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."
169 (defgroup convenience nil
170 "Convenience features for faster editing."
174 "Support for editing files."
178 "Support for editing text files."
183 "Support for editing binary data files."
187 "Abbreviation handling, typing shortcuts, macros."
191 (defgroup matching nil
192 "Various sorts of searching and matching."
195 (defgroup emulations nil
196 "Emulations of other editors."
197 :link
'(custom-manual "(emacs)Emulation")
204 (defgroup outlines nil
205 "Support for hierarchical outlining."
208 (defgroup external nil
209 "Interfacing to external utilities."
213 "Communications, networking, and remote access to files."
217 (defgroup processes nil
218 "Process, subshell, compilation, and job control support."
221 (defgroup programming nil
222 "Support for programming in other languages."
225 (defgroup languages nil
226 "Specialized modes for editing programming languages."
230 "Lisp support, including Emacs Lisp."
231 :link
'(custom-group-link :tag
"Font Lock Faces group" font-lock-faces
)
236 "Support for the C language and related languages."
237 :link
'(custom-group-link :tag
"Font Lock Faces group" font-lock-faces
)
238 :link
'(custom-manual "(ccmode)")
245 (defgroup applications nil
246 "Applications written in Emacs."
249 (defgroup calendar nil
250 "Calendar and time management support."
251 :group
'applications
)
254 "Modes for electronic-mail handling."
255 :group
'applications
)
258 "Support for netnews reading and posting."
259 :link
'(custom-manual "(gnus)")
260 :group
'applications
)
263 "Games, jokes and amusements."
264 :group
'applications
)
266 (defgroup development nil
267 "Support for further development of Emacs."
271 "Support for Emacs documentation."
274 (defgroup extensions nil
275 "Emacs Lisp language extensions."
278 (defgroup internal nil
279 "Code for Emacs internals, build process, defaults."
283 "Maintenance aids for the Emacs development group."
287 (defgroup environment nil
288 "Fitting Emacs with its environment."
291 (defgroup hardware nil
292 "Support for interfacing with miscellaneous hardware."
295 (defgroup terminals nil
296 "Support for terminal types."
300 "Front-ends/assistants for, or emulators of, UNIX features."
304 "Internationalization and alternate character-set support."
305 :link
'(custom-manual "(emacs)International")
310 "The X Window system."
314 "Support for Emacs frames and window systems."
318 "Code related to the TeX formatter."
319 :link
'(custom-group-link :tag
"Font Lock Faces group" font-lock-faces
)
323 "Support for multiple fonts."
327 "Support for on-line help systems."
330 (defgroup multimedia nil
331 "Non-textual support, specifically images and sound."
335 "Code local to your site."
338 (defgroup customize
'((widgets custom-group
))
339 "Customization of the Customization support."
343 (defgroup custom-faces nil
344 "Faces used by customize."
348 (defgroup custom-browse nil
349 "Control customize browser."
353 (defgroup custom-buffer nil
354 "Control customize buffers."
358 (defgroup custom-menu nil
359 "Control customize menus."
364 "Storage allocation and gc for GNU Emacs Lisp interpreter."
365 :tag
"Storage Allocation"
369 "Undoing changes in buffers."
370 :link
'(custom-manual "(emacs)Undo")
373 (defgroup mode-line nil
374 "Content of the modeline."
377 (defgroup editing-basics nil
378 "Most basic editing facilities."
381 (defgroup display nil
382 "How characters are displayed in buffers."
385 (defgroup execute nil
386 "Executing external commands."
389 (defgroup installation nil
390 "The Emacs installation."
398 "Internal Emacs limits."
402 "Debugging Emacs itself."
405 (defgroup keyboard nil
406 "Input from the keyboard."
410 "Input from the mouse."
414 "Input from the menus."
418 "Handling data from drag and drop."
421 (defgroup auto-save nil
422 "Preventing accidental loss of data."
425 (defgroup processes-basics nil
426 "Basic stuff dealing with processes."
430 "MULE Emacs internationalization."
433 (defgroup windows nil
434 "Windows within a frame."
435 :link
'(custom-manual "(emacs)Windows")
438 ;;; Custom mode keymaps
440 (defvar custom-mode-map
441 ;; This keymap should be dense, but a dense keymap would prevent inheriting
442 ;; "\r" bindings from the parent map.
443 ;; Actually, this misfeature of dense keymaps was fixed on 2001-11-26.
444 (let ((map (make-keymap)))
445 (set-keymap-parent map widget-keymap
)
446 (define-key map
[remap self-insert-command
] 'Custom-no-edit
)
447 (define-key map
"\^m" 'Custom-newline
)
448 (define-key map
" " 'scroll-up
)
449 (define-key map
"\177" 'scroll-down
)
450 (define-key map
"\C-c\C-c" 'Custom-set
)
451 (define-key map
"\C-x\C-s" 'Custom-save
)
452 (define-key map
"q" 'Custom-buffer-done
)
453 (define-key map
"u" 'Custom-goto-parent
)
454 (define-key map
"n" 'widget-forward
)
455 (define-key map
"p" 'widget-backward
)
457 "Keymap for `Custom-mode'.")
459 (defvar custom-mode-link-map
460 (let ((map (make-keymap)))
461 (set-keymap-parent map custom-mode-map
)
462 (define-key map
[down-mouse-2
] nil
)
463 (define-key map
[down-mouse-1
] 'mouse-drag-region
)
464 (define-key map
[mouse-2
] 'widget-move-and-invoke
)
466 "Local keymap for links in `Custom-mode'.")
468 (defvar custom-field-keymap
469 (let ((map (copy-keymap widget-field-keymap
)))
470 (define-key map
"\C-c\C-c" 'Custom-set
)
471 (define-key map
"\C-x\C-s" 'Custom-save
)
473 "Keymap used inside editable fields in customization buffers.")
475 (widget-put (get 'editable-field
'widget-type
) :keymap custom-field-keymap
)
479 (defun custom-split-regexp-maybe (regexp)
480 "If REGEXP is a string, split it to a list at `\\|'.
481 You can get the original back from the result with:
482 (mapconcat 'identity result \"\\|\")
484 IF REGEXP is not a string, return it unchanged."
486 (split-string regexp
"\\\\|")
489 (defun custom-variable-prompt ()
490 "Prompt for a custom variable, defaulting to the variable at point.
491 Return a list suitable for use in `interactive'."
492 (let* ((v (variable-at-point))
493 (default (and (symbolp v
) (custom-variable-p v
) (symbol-name v
)))
494 (enable-recursive-minibuffers t
)
496 (setq val
(completing-read
497 (if default
(format "Customize variable (default %s): " default
)
498 "Customize variable: ")
499 obarray
'custom-variable-p t nil nil default
))
500 (list (if (equal val
"")
501 (if (symbolp v
) v nil
)
504 (defun custom-menu-filter (menu widget
)
505 "Convert MENU to the form used by `widget-choose'.
506 MENU should be in the same format as `custom-variable-menu'.
507 WIDGET is the widget to apply the filter entries of MENU on."
509 current name action filter
)
511 (setq current
(car menu
)
513 action
(nth 1 current
)
514 filter
(nth 2 current
)
516 (if (or (null filter
) (funcall filter widget
))
517 (push (cons name action
) result
)
523 (defvar custom-prefix-list nil
524 "List of prefixes that should be ignored by `custom-unlispify'.")
526 (defcustom custom-unlispify-menu-entries t
527 "Display menu entries as words instead of symbols if non-nil."
531 (defcustom custom-unlispify-remove-prefixes nil
532 "Non-nil means remove group prefixes from option names in buffer."
534 :group
'custom-buffer
537 (defun custom-unlispify-menu-entry (symbol &optional no-suffix
)
538 "Convert SYMBOL into a menu entry."
539 (cond ((not custom-unlispify-menu-entries
)
540 (symbol-name symbol
))
541 ((get symbol
'custom-tag
)
543 (get symbol
'custom-tag
)
544 (concat (get symbol
'custom-tag
) "...")))
546 (with-current-buffer (get-buffer-create " *Custom-Work*")
548 (princ symbol
(current-buffer))
549 (goto-char (point-min))
550 ;; FIXME: Boolean variables are not predicates, so they shouldn't
551 ;; end with `-p'. -stef
552 ;; (when (and (eq (get symbol 'custom-type) 'boolean)
553 ;; (re-search-forward "-p\\'" nil t))
554 ;; (replace-match "" t t)
555 ;; (goto-char (point-min)))
556 (if custom-unlispify-remove-prefixes
557 (let ((prefixes custom-prefix-list
)
560 (setq prefix
(car prefixes
))
561 (if (search-forward prefix
(+ (point) (length prefix
)) t
)
564 (delete-region (point-min) (point)))
565 (setq prefixes
(cdr prefixes
))))))
566 (subst-char-in-region (point-min) (point-max) ?- ?\ t
)
567 (capitalize-region (point-min) (point-max))
569 (goto-char (point-max))
573 (defcustom custom-unlispify-tag-names t
574 "Display tag names as words instead of symbols if non-nil."
575 :group
'custom-buffer
578 (defun custom-unlispify-tag-name (symbol)
579 "Convert SYMBOL into a menu entry."
580 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names
))
581 (custom-unlispify-menu-entry symbol t
)))
583 (defun custom-prefix-add (symbol prefixes
)
584 "Add SYMBOL to list of ignored PREFIXES."
585 (cons (or (get symbol
'custom-prefix
)
586 (concat (symbol-name symbol
) "-"))
591 (defcustom custom-guess-name-alist
597 ("-function\\'" function
)
598 ("-functions\\'" (repeat function
))
599 ("-list\\'" (repeat sexp
))
600 ("-alist\\'" (repeat (cons sexp sexp
))))
601 "Alist of (MATCH TYPE).
603 MATCH should be a regexp matching the name of a symbol, and TYPE should
604 be a widget suitable for editing the value of that symbol. The TYPE
605 of the first entry where MATCH matches the name of the symbol will be
608 This is used for guessing the type of variables not declared with
610 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
611 :group
'custom-buffer
)
613 (defcustom custom-guess-doc-alist
614 '(("\\`\\*?Non-nil " boolean
))
615 "Alist of (MATCH TYPE).
617 MATCH should be a regexp matching a documentation string, and TYPE
618 should be a widget suitable for editing the value of a variable with
619 that documentation string. The TYPE of the first entry where MATCH
620 matches the name of the symbol will be used.
622 This is used for guessing the type of variables not declared with
624 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
625 :group
'custom-buffer
)
627 (defun custom-guess-type (symbol)
628 "Guess a widget suitable for editing the value of SYMBOL.
629 This is done by matching SYMBOL with `custom-guess-name-alist' and
630 if that fails, the doc string with `custom-guess-doc-alist'."
631 (let ((name (symbol-name symbol
))
632 (names custom-guess-name-alist
)
635 (setq current
(car names
)
637 (when (string-match (nth 0 current
) name
)
638 (setq found
(nth 1 current
)
641 (let ((doc (documentation-property symbol
'variable-documentation
))
642 (docs custom-guess-doc-alist
))
645 (setq current
(car docs
)
647 (when (string-match (nth 0 current
) doc
)
648 (setq found
(nth 1 current
)
655 (defcustom custom-browse-sort-alphabetically nil
656 "If non-nil, sort customization group alphabetically in `custom-browse'."
658 :group
'custom-browse
)
660 (defcustom custom-browse-order-groups nil
661 "If non-nil, order group members within each customization group.
662 If `first', order groups before non-groups.
663 If `last', order groups after non-groups."
664 :type
'(choice (const first
)
666 (const :tag
"none" nil
))
667 :group
'custom-browse
)
669 (defcustom custom-browse-only-groups nil
670 "If non-nil, show group members only within each customization group."
672 :group
'custom-browse
)
675 (defcustom custom-buffer-sort-alphabetically t
676 "Whether to sort customization groups alphabetically in Custom buffer."
678 :group
'custom-buffer
)
680 (defcustom custom-buffer-order-groups
'last
681 "If non-nil, order group members within each customization group.
682 If `first', order groups before non-groups.
683 If `last', order groups after non-groups."
684 :type
'(choice (const first
)
686 (const :tag
"none" nil
))
687 :group
'custom-buffer
)
690 (defcustom custom-menu-sort-alphabetically nil
691 "If non-nil, sort each customization group alphabetically in menus."
695 (defcustom custom-menu-order-groups
'first
696 "If non-nil, order group members within each customization group.
697 If `first', order groups before non-groups.
698 If `last', order groups after non-groups."
699 :type
'(choice (const first
)
701 (const :tag
"none" nil
))
704 ;;;###autoload (add-hook 'same-window-regexps (purecopy "\\`\\*Customiz.*\\*\\'"))
706 (defun custom-sort-items (items sort-alphabetically order-groups
)
707 "Return a sorted copy of ITEMS.
708 ITEMS should be a `custom-group' property.
709 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
710 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
711 groups after non-groups, if nil do not order groups at all."
712 (sort (copy-sequence items
)
714 (let ((typea (nth 1 a
)) (typeb (nth 1 b
))
715 (namea (nth 0 a
)) (nameb (nth 0 b
)))
716 (cond ((not order-groups
)
717 ;; Since we don't care about A and B order, maybe sort.
718 (when sort-alphabetically
719 (string-lessp namea nameb
)))
720 ((eq typea
'custom-group
)
721 ;; If B is also a group, maybe sort. Otherwise, order A and B.
722 (if (eq typeb
'custom-group
)
723 (when sort-alphabetically
724 (string-lessp namea nameb
))
725 (eq order-groups
'first
)))
726 ((eq typeb
'custom-group
)
727 ;; Since A cannot be a group, order A and B.
728 (eq order-groups
'last
))
730 ;; Since A and B cannot be groups, sort.
731 (string-lessp namea nameb
)))))))
733 ;;; Custom Mode Commands.
735 ;; This variable is used by `custom-tool-bar-map', or directly by
736 ;; `custom-buffer-create-internal' if `custom-buffer-verbose-help' is non-nil.
738 (defvar custom-commands
739 '(("Set for current session" Custom-set t
740 "Apply all settings in this buffer to the current session"
742 ("Save for future sessions" Custom-save
743 (or custom-file user-init-file
)
744 "Apply all settings in this buffer and save them for future Emacs sessions."
746 ("Undo edits" Custom-reset-current t
747 "Restore all settings in this buffer to reflect their current values."
749 ("Reset to saved" Custom-reset-saved t
750 "Restore all settings in this buffer to their saved values (if any)."
752 ("Erase customizations" Custom-reset-standard
753 (or custom-file user-init-file
)
754 "Un-customize all settings in this buffer and save them with standard values."
756 ("Help for Customize" Custom-help t
757 "Get help for using Customize."
759 ("Exit" Custom-buffer-done t
"Exit Customize." "exit")))
761 (defun Custom-help ()
762 "Read the node on Easy Customization in the Emacs manual."
764 (info "(emacs)Easy Customization"))
766 (defvar custom-reset-menu
767 '(("Undo Edits" . Custom-reset-current
)
768 ("Reset to Saved" . Custom-reset-saved
)
769 ("Erase Customizations (use standard values)" . Custom-reset-standard
))
770 "Alist of actions for the `Reset' button.
771 The key is a string containing the name of the action, the value is a
772 Lisp function taking the widget as an element which will be called
773 when the action is chosen.")
775 (defvar custom-options nil
776 "Customization widgets in the current buffer.")
778 (defun custom-command-apply (fun query
&optional strong-query
)
779 "Call function FUN on all widgets in `custom-options'.
780 If there is more than one widget, ask user for confirmation using
781 the query string QUERY, using `y-or-n-p' if STRONG-QUERY is nil,
782 and `yes-or-no-p' otherwise."
783 (if (or (and (= 1 (length custom-options
))
784 (memq (widget-type (car custom-options
))
785 '(custom-variable custom-face
)))
786 (funcall (if strong-query
'yes-or-no-p
'y-or-n-p
) query
))
787 (progn (mapc fun custom-options
) t
)
791 (defun Custom-set (&rest ignore
)
792 "Set the current value of all edited settings in the buffer."
794 (custom-command-apply
796 (when (eq (widget-get child
:custom-state
) 'modified
)
797 (widget-apply child
:custom-set
)))
798 "Set all values according to this buffer? "))
800 (defun Custom-save (&rest ignore
)
801 "Set all edited settings, then save all settings that have been set.
802 If a setting was edited and set before, this saves it. If a
803 setting was merely edited before, this sets it then saves it."
805 (when (custom-command-apply
807 (when (memq (widget-get child
:custom-state
)
808 '(modified set changed rogue
))
809 (widget-apply child
:custom-mark-to-save
)))
810 "Save all settings in this buffer? " t
)
811 ;; Save changes to buffer and redraw.
813 (dolist (child custom-options
)
814 (widget-apply child
:custom-state-set-and-redraw
))))
816 (defun custom-reset (widget &optional event
)
817 "Select item from reset menu."
818 (let* ((completion-ignore-case t
)
819 (answer (widget-choose "Reset settings"
825 (defun Custom-reset-current (&rest ignore
)
826 "Reset all edited settings in the buffer to show their current values."
828 (custom-command-apply
830 (if (memq (widget-get widget
:custom-state
) '(modified changed
))
831 (widget-apply widget
:custom-reset-current
)))
832 "Reset all settings' buffer text to show current values? "))
834 (defun Custom-reset-saved (&rest ignore
)
835 "Reset all edited or set settings in the buffer to their saved value.
836 This also shows the saved values in the buffer."
838 (custom-command-apply
840 (if (memq (widget-get widget
:custom-state
) '(modified set changed rogue
))
841 (widget-apply widget
:custom-reset-saved
)))
842 "Reset all settings (current values and buffer text) to saved values? "))
844 ;; The next two variables are bound to '(t) by `Custom-reset-standard'
845 ;; and `custom-group-reset-standard'. If these variables are nil, both
846 ;; `custom-variable-reset-standard' and `custom-face-reset-standard'
847 ;; save, reset and redraw the handled widget immediately. Otherwise,
848 ;; they add the widget to the corresponding list and leave it to
849 ;; `custom-reset-standard-save-and-update' to save, reset and redraw it.
850 (defvar custom-reset-standard-variables-list nil
)
851 (defvar custom-reset-standard-faces-list nil
)
853 ;; The next function was excerpted from `custom-variable-reset-standard'
854 ;; and `custom-face-reset-standard' and is used to avoid calling
855 ;; `custom-save-all' repeatedly (and thus saving settings to file one by
856 ;; one) when erasing all customizations.
857 (defun custom-reset-standard-save-and-update ()
858 "Save settings and redraw after erasing customizations."
859 (when (or (and custom-reset-standard-variables-list
860 (not (eq custom-reset-standard-variables-list
'(t))))
861 (and custom-reset-standard-faces-list
862 (not (eq custom-reset-standard-faces-list
'(t)))))
863 ;; Save settings to file.
865 ;; Set state of and redraw variables.
866 (dolist (widget custom-reset-standard-variables-list
)
867 (unless (eq widget t
)
868 (widget-put widget
:custom-state
'unknown
)
869 (custom-redraw widget
)))
870 ;; Set state of and redraw faces.
871 (dolist (widget custom-reset-standard-faces-list
)
872 (unless (eq widget t
)
873 (let* ((symbol (widget-value widget
))
874 (child (car (widget-get widget
:children
)))
875 (value (get symbol
'face-defface-spec
))
876 (comment-widget (widget-get widget
:comment-widget
)))
877 (put symbol
'face-comment nil
)
878 (widget-value-set child
879 (custom-pre-filter-face-spec
880 (list (list t
(custom-face-attributes-get
882 ;; This call manages the comment visibility
883 (widget-value-set comment-widget
"")
884 (custom-face-state-set widget
)
885 (custom-redraw-magic widget
))))))
887 (defun Custom-reset-standard (&rest ignore
)
888 "Erase all customizations (either current or saved) in current buffer.
889 The immediate result is to restore them to their standard values.
890 This operation eliminates any saved values for the group members,
891 making them as if they had never been customized at all."
893 ;; Bind these temporarily.
894 (let ((custom-reset-standard-variables-list '(t))
895 (custom-reset-standard-faces-list '(t)))
896 (custom-command-apply
898 (and (or (null (widget-get widget
:custom-standard-value
))
899 (widget-apply widget
:custom-standard-value
))
900 (memq (widget-get widget
:custom-state
)
901 '(modified set changed saved rogue
))
902 (widget-apply widget
:custom-mark-to-reset-standard
)))
903 "Erase all customizations for settings in this buffer? " t
)
904 (custom-reset-standard-save-and-update)))
906 ;;; The Customize Commands
908 (defun custom-prompt-variable (prompt-var prompt-val
&optional comment
)
909 "Prompt for a variable and a value and return them as a list.
910 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
911 prompt for the value. The %s escape in PROMPT-VAL is replaced with
912 the name of the variable.
914 If the variable has a `variable-interactive' property, that is used as if
915 it were the arg to `interactive' (which see) to interactively read the value.
917 If the variable has a `custom-type' property, it must be a widget and the
918 `:prompt-value' property of that widget will be used for reading the value.
920 If optional COMMENT argument is non-nil, also prompt for a comment and return
921 it as the third element in the list."
922 (let* ((var (read-variable prompt-var
))
923 (minibuffer-help-form '(describe-variable var
))
925 (let ((prop (get var
'variable-interactive
))
926 (type (get var
'custom-type
))
927 (prompt (format prompt-val var
)))
929 (setq type
(list type
)))
931 ;; Use VAR's `variable-interactive' property
932 ;; as an interactive spec for prompting.
933 (call-interactively `(lambda (arg)
937 (widget-prompt-value type
943 (eval-minibuffer prompt
))))))
946 (read-string "Comment: " (get var
'variable-comment
)))
950 (defun customize-set-value (variable value
&optional comment
)
951 "Set VARIABLE to VALUE, and return VALUE. VALUE is a Lisp object.
953 If VARIABLE has a `variable-interactive' property, that is used as if
954 it were the arg to `interactive' (which see) to interactively read the value.
956 If VARIABLE has a `custom-type' property, it must be a widget and the
957 `:prompt-value' property of that widget will be used for reading the value.
959 If given a prefix (or a COMMENT argument), also prompt for a comment."
960 (interactive (custom-prompt-variable "Set variable: "
964 (cond ((string= comment
"")
965 (put variable
'variable-comment nil
))
967 (put variable
'variable-comment comment
)))
968 (set variable value
))
971 (defun customize-set-variable (variable value
&optional comment
)
972 "Set the default for VARIABLE to VALUE, and return VALUE.
973 VALUE is a Lisp object.
975 If VARIABLE has a `custom-set' property, that is used for setting
976 VARIABLE, otherwise `set-default' is used.
978 If VARIABLE has a `variable-interactive' property, that is used as if
979 it were the arg to `interactive' (which see) to interactively read the value.
981 If VARIABLE has a `custom-type' property, it must be a widget and the
982 `:prompt-value' property of that widget will be used for reading the value.
984 If given a prefix (or a COMMENT argument), also prompt for a comment."
985 (interactive (custom-prompt-variable "Set variable: "
986 "Set customized value for %s to: "
988 (custom-load-symbol variable
)
989 (custom-push-theme 'theme-value variable
'user
'set
(custom-quote value
))
990 (funcall (or (get variable
'custom-set
) 'set-default
) variable value
)
991 (put variable
'customized-value
(list (custom-quote value
)))
992 (cond ((string= comment
"")
993 (put variable
'variable-comment nil
)
994 (put variable
'customized-variable-comment nil
))
996 (put variable
'variable-comment comment
)
997 (put variable
'customized-variable-comment comment
)))
1001 (defun customize-save-variable (variable value
&optional comment
)
1002 "Set the default for VARIABLE to VALUE, and save it for future sessions.
1005 If VARIABLE has a `custom-set' property, that is used for setting
1006 VARIABLE, otherwise `set-default' is used.
1008 If VARIABLE has a `variable-interactive' property, that is used as if
1009 it were the arg to `interactive' (which see) to interactively read the value.
1011 If VARIABLE has a `custom-type' property, it must be a widget and the
1012 `:prompt-value' property of that widget will be used for reading the value.
1014 If given a prefix (or a COMMENT argument), also prompt for a comment."
1015 (interactive (custom-prompt-variable "Set and save variable: "
1016 "Set and save value for %s as: "
1017 current-prefix-arg
))
1018 (funcall (or (get variable
'custom-set
) 'set-default
) variable value
)
1019 (put variable
'saved-value
(list (custom-quote value
)))
1020 (custom-push-theme 'theme-value variable
'user
'set
(custom-quote value
))
1021 (cond ((string= comment
"")
1022 (put variable
'variable-comment nil
)
1023 (put variable
'saved-variable-comment nil
))
1025 (put variable
'variable-comment comment
)
1026 (put variable
'saved-variable-comment comment
)))
1027 (put variable
'customized-value nil
)
1028 (put variable
'customized-variable-comment nil
)
1034 "Select a customization buffer which you can use to set user options.
1035 User options are structured into \"groups\".
1036 Initially the top-level group `Emacs' and its immediate subgroups
1037 are shown; the contents of those subgroups are initially hidden."
1039 (customize-group 'emacs
))
1042 (defun customize-mode (mode)
1043 "Customize options related to the current major mode.
1044 If a prefix \\[universal-argument] was given (or if the current major mode has no known group),
1045 then prompt for the MODE to customize."
1048 (let ((completion-regexp-list '("-mode\\'"))
1049 (group (custom-group-of-mode major-mode
)))
1050 (if (and group
(not current-prefix-arg
))
1053 (completing-read (if group
1054 (format "Major mode (default %s): " major-mode
)
1057 'custom-group-of-mode
1058 t nil nil
(if group
(symbol-name major-mode
))))))))
1059 (customize-group (custom-group-of-mode mode
)))
1061 (defun customize-read-group ()
1062 (let ((completion-ignore-case t
))
1063 (completing-read "Customize group (default emacs): "
1066 (or (and (get symbol
'custom-loads
)
1067 (not (get symbol
'custom-autoload
)))
1068 (get symbol
'custom-group
)))
1072 (defun customize-group (&optional group
)
1073 "Customize GROUP, which must be a customization group."
1074 (interactive (list (customize-read-group)))
1075 (when (stringp group
)
1076 (if (string-equal "" group
)
1078 (setq group
(intern group
))))
1079 (let ((name (format "*Customize Group: %s*"
1080 (custom-unlispify-tag-name group
))))
1081 (if (get-buffer name
)
1082 (pop-to-buffer name
)
1083 (custom-buffer-create
1084 (list (list group
'custom-group
))
1086 (concat " for group "
1087 (custom-unlispify-tag-name group
))))))
1090 (defun customize-group-other-window (&optional group
)
1091 "Customize GROUP, which must be a customization group, in another window."
1092 (interactive (list (customize-read-group)))
1093 (let ((pop-up-windows t
)
1094 (same-window-buffer-names nil
)
1095 (same-window-regexps nil
))
1096 (customize-group group
)))
1099 (defalias 'customize-variable
'customize-option
)
1102 (defun customize-option (symbol)
1103 "Customize SYMBOL, which must be a user option variable."
1104 (interactive (custom-variable-prompt))
1106 (error "No variable specified"))
1107 (let ((basevar (indirect-variable symbol
)))
1108 (custom-buffer-create (list (list basevar
'custom-variable
))
1109 (format "*Customize Option: %s*"
1110 (custom-unlispify-tag-name basevar
)))
1111 (unless (eq symbol basevar
)
1112 (message "`%s' is an alias for `%s'" symbol basevar
))))
1115 (defalias 'customize-variable-other-window
'customize-option-other-window
)
1118 (defun customize-option-other-window (symbol)
1119 "Customize SYMBOL, which must be a user option variable.
1120 Show the buffer in another window, but don't select it."
1121 (interactive (custom-variable-prompt))
1123 (error "No variable specified"))
1124 (let ((basevar (indirect-variable symbol
)))
1125 (custom-buffer-create-other-window
1126 (list (list basevar
'custom-variable
))
1127 (format "*Customize Option: %s*" (custom-unlispify-tag-name basevar
)))
1128 (unless (eq symbol basevar
)
1129 (message "`%s' is an alias for `%s'" symbol basevar
))))
1131 (defvar customize-changed-options-previous-release
"23.1"
1132 "Version for `customize-changed-options' to refer back to by default.")
1134 ;; Packages will update this variable, so make it available.
1136 (defvar customize-package-emacs-version-alist nil
1137 "Alist mapping versions of a package to Emacs versions.
1138 We use this for packages that have their own names, but are released
1139 as part of Emacs itself.
1141 Each elements looks like this:
1143 (PACKAGE (PVERSION . EVERSION)...)
1145 Here PACKAGE is the name of a package, as a symbol. After
1146 PACKAGE come one or more elements, each associating a
1147 package version PVERSION with the first Emacs version
1148 EVERSION in which it (or a subsequent version of PACKAGE)
1149 was first released. Both PVERSION and EVERSION are strings.
1150 PVERSION should be a string that this package used in
1151 the :package-version keyword for `defcustom', `defgroup',
1154 For example, the MH-E package updates this alist as follows:
1156 (add-to-list 'customize-package-emacs-version-alist
1157 '(MH-E (\"6.0\" . \"22.1\") (\"6.1\" . \"22.1\")
1158 (\"7.0\" . \"22.1\") (\"7.1\" . \"22.1\")
1159 (\"7.2\" . \"22.1\") (\"7.3\" . \"22.1\")
1160 (\"7.4\" . \"22.1\") (\"8.0\" . \"22.1\")))
1162 The value of PACKAGE needs to be unique and it needs to match the
1163 PACKAGE value appearing in the :package-version keyword. Since
1164 the user might see the value in a error message, a good choice is
1165 the official name of the package, such as MH-E or Gnus.")
1168 (defalias 'customize-changed
'customize-changed-options
)
1171 (defun customize-changed-options (&optional since-version
)
1172 "Customize all settings whose meanings have changed in Emacs itself.
1173 This includes new user option variables and faces, and new
1174 customization groups, as well as older options and faces whose meanings
1175 or default values have changed since the previous major Emacs release.
1177 With argument SINCE-VERSION (a string), customize all settings
1178 that were added or redefined since that version."
1182 (read-from-minibuffer
1183 (format "Customize options changed, since version (default %s): "
1184 customize-changed-options-previous-release
))))
1185 (if (equal since-version
"")
1186 (setq since-version nil
)
1187 (unless (condition-case nil
1188 (numberp (read since-version
))
1190 (signal 'wrong-type-argument
(list 'numberp since-version
))))
1191 (unless since-version
1192 (setq since-version customize-changed-options-previous-release
))
1194 ;; Load the information for versions since since-version. We use
1195 ;; custom-load-symbol for this.
1196 (put 'custom-versions-load-alist
'custom-loads nil
)
1197 (dolist (elt custom-versions-load-alist
)
1198 (if (customize-version-lessp since-version
(car elt
))
1199 (dolist (load (cdr elt
))
1200 (custom-add-load 'custom-versions-load-alist load
))))
1201 (custom-load-symbol 'custom-versions-load-alist
)
1202 (put 'custom-versions-load-alist
'custom-loads nil
)
1207 (let* ((package-version (get symbol
'custom-package-version
))
1209 (or (and package-version
1210 (customize-package-emacs-version symbol
1212 (get symbol
'custom-version
))))
1214 (when (customize-version-lessp since-version version
)
1215 (if (or (get symbol
'custom-group
)
1216 (get symbol
'group-documentation
))
1217 (push (list symbol
'custom-group
) found
))
1218 (if (custom-variable-p symbol
)
1219 (push (list symbol
'custom-variable
) found
))
1220 (if (custom-facep symbol
)
1221 (push (list symbol
'custom-face
) found
)))))))
1223 (custom-buffer-create (custom-sort-items found t
'first
)
1224 "*Customize Changed Options*")
1225 (error "No user option defaults have been changed since Emacs %s"
1228 (defun customize-package-emacs-version (symbol package-version
)
1229 "Return the Emacs version in which SYMBOL's meaning last changed.
1230 PACKAGE-VERSION has the form (PACKAGE . VERSION). We use
1231 `customize-package-emacs-version-alist' to find the version of
1232 Emacs that is associated with version VERSION of PACKAGE."
1233 (let (package-versions emacs-version
)
1234 ;; Use message instead of error since we want user to be able to
1235 ;; see the rest of the symbols even if a package author has
1236 ;; botched things up.
1237 (cond ((not (listp package-version
))
1238 (message "Invalid package-version value for %s" symbol
))
1239 ((setq package-versions
(assq (car package-version
)
1240 customize-package-emacs-version-alist
))
1242 (cdr (assoc (cdr package-version
) package-versions
)))
1243 (unless emacs-version
1244 (message "%s version %s not found in %s" symbol
1245 (cdr package-version
)
1246 "customize-package-emacs-version-alist")))
1248 (message "Package %s version %s lists no corresponding Emacs version"
1249 (car package-version
)
1250 (cdr package-version
))))
1253 (defun customize-version-lessp (version1 version2
)
1254 ;; Why are the versions strings, and given that they are, why aren't
1255 ;; they converted to numbers and compared as such here? -- fx
1257 ;; In case someone made a mistake and left out the quotes
1258 ;; in the :version value.
1259 (if (numberp version2
)
1260 (setq version2
(prin1-to-string version2
)))
1261 (let (major1 major2 minor1 minor2
)
1262 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version1
)
1263 (setq major1
(read (or (match-string 1 version1
)
1265 (setq minor1
(read (or (match-string 3 version1
)
1267 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version2
)
1268 (setq major2
(read (or (match-string 1 version2
)
1270 (setq minor2
(read (or (match-string 3 version2
)
1272 (or (< major1 major2
)
1273 (and (= major1 major2
)
1274 (< minor1 minor2
)))))
1277 (defun customize-face (&optional face
)
1278 "Customize FACE, which should be a face name or nil.
1279 If FACE is nil, customize all faces. If FACE is actually a
1280 face-alias, customize the face it is aliased to.
1282 Interactively, when point is on text which has a face specified,
1283 suggest to customize that face, if it's customizable."
1284 (interactive (list (read-face-name "Customize face" "all faces" t
)))
1285 (if (member face
'(nil ""))
1286 (setq face
(face-list)))
1287 (if (and (listp face
) (null (cdr face
)))
1288 (setq face
(car face
)))
1290 (custom-buffer-create
1292 (mapcar (lambda (s) (list s
'custom-face
)) face
)
1294 "*Customize Faces*")
1295 ;; If FACE is actually an alias, customize the face it is aliased to.
1296 (if (get face
'face-alias
)
1297 (setq face
(get face
'face-alias
)))
1298 (unless (facep face
)
1299 (error "Invalid face %S" face
))
1300 (custom-buffer-create
1301 (list (list face
'custom-face
))
1302 (format "*Customize Face: %s*"
1303 (custom-unlispify-tag-name face
)))))
1306 (defun customize-face-other-window (&optional face
)
1307 "Show customization buffer for face FACE in other window.
1308 If FACE is actually a face-alias, customize the face it is aliased to.
1310 Interactively, when point is on text which has a face specified,
1311 suggest to customize that face, if it's customizable."
1312 (interactive (list (read-face-name "Customize face" "all faces" t
)))
1313 (let ((pop-up-windows t
)
1314 (same-window-buffer-names nil
)
1315 (same-window-regexps nil
))
1316 (customize-face face
)))
1318 (defalias 'customize-customized
'customize-unsaved
)
1321 (defun customize-unsaved ()
1322 "Customize all user options set in this session but not saved."
1325 (mapatoms (lambda (symbol)
1326 (and (or (get symbol
'customized-face
)
1327 (get symbol
'customized-face-comment
))
1328 (custom-facep symbol
)
1329 (push (list symbol
'custom-face
) found
))
1330 (and (or (get symbol
'customized-value
)
1331 (get symbol
'customized-variable-comment
))
1333 (push (list symbol
'custom-variable
) found
))))
1335 (error "No user options are set but unsaved")
1336 (custom-buffer-create (custom-sort-items found t nil
)
1337 "*Customize Unsaved*"))))
1340 (defun customize-rogue ()
1341 "Customize all user variables modified outside customize."
1344 (mapatoms (lambda (symbol)
1345 (let ((cval (or (get symbol
'customized-value
)
1346 (get symbol
'saved-value
)
1347 (get symbol
'standard-value
))))
1348 (when (and cval
;Declared with defcustom.
1349 (default-boundp symbol
) ;Has a value.
1350 (not (equal (eval (car cval
))
1351 ;; Which does not match customize.
1352 (default-value symbol
))))
1353 (push (list symbol
'custom-variable
) found
)))))
1355 (error "No rogue user options")
1356 (custom-buffer-create (custom-sort-items found t nil
)
1357 "*Customize Rogue*"))))
1359 (defun customize-saved ()
1360 "Customize all already saved user options."
1363 (mapatoms (lambda (symbol)
1364 (and (or (get symbol
'saved-face
)
1365 (get symbol
'saved-face-comment
))
1366 (custom-facep symbol
)
1367 (push (list symbol
'custom-face
) found
))
1368 (and (or (get symbol
'saved-value
)
1369 (get symbol
'saved-variable-comment
))
1371 (push (list symbol
'custom-variable
) found
))))
1373 (error "No saved user options")
1374 (custom-buffer-create (custom-sort-items found t nil
)
1375 "*Customize Saved*"))))
1377 (declare-function apropos-parse-pattern
"apropos" (pattern))
1380 (defun customize-apropos (pattern &optional type
)
1381 "Customize all loaded options, faces and groups matching PATTERN.
1382 PATTERN can be a word, a list of words (separated by spaces),
1383 or a regexp (using some regexp special characters). If it is a word,
1384 search for matches for that word as a substring. If it is a list of words,
1385 search for matches for any two (or more) of those words.
1387 If TYPE is `options', include only options.
1388 If TYPE is `faces', include only faces.
1389 If TYPE is `groups', include only groups.
1390 If TYPE is t (interactively, with prefix arg), include variables
1391 that are not customizable options, as well as faces and groups
1392 \(but we recommend using `apropos-variable' instead)."
1393 (interactive (list (apropos-read-pattern "symbol") current-prefix-arg
))
1395 (apropos-parse-pattern pattern
)
1399 (when (string-match apropos-regexp
(symbol-name symbol
))
1400 ,(if (not (memq type
'(faces options
)))
1401 '(if (get symbol
'custom-group
)
1402 (push (list symbol
'custom-group
) found
)))
1403 ,(if (not (memq type
'(options groups
)))
1404 '(if (custom-facep symbol
)
1405 (push (list symbol
'custom-face
) found
)))
1406 ,(if (not (memq type
'(groups faces
)))
1407 `(if (and (boundp symbol
)
1408 (eq (indirect-variable symbol
) symbol
)
1409 (or (get symbol
'saved-value
)
1410 (custom-variable-p symbol
)
1411 ,(if (not (memq type
'(nil options
)))
1412 '(get symbol
'variable-documentation
))))
1413 (push (list symbol
'custom-variable
) found
))))))
1415 (error "No %s matching %s"
1418 (format "customizable %s"
1419 (if (memq type
'(options faces groups
))
1423 (custom-buffer-create
1424 (custom-sort-items found t custom-buffer-order-groups
)
1425 "*Customize Apropos*"))))
1428 (defun customize-apropos-options (regexp &optional arg
)
1429 "Customize all loaded customizable options matching REGEXP.
1430 With prefix ARG, include variables that are not customizable options
1431 \(but it is better to use `apropos-variable' if you want to find those)."
1432 (interactive "sCustomize options (regexp): \nP")
1433 (customize-apropos regexp
(or arg
'options
)))
1436 (defun customize-apropos-faces (regexp)
1437 "Customize all loaded faces matching REGEXP."
1438 (interactive "sCustomize faces (regexp): \n")
1439 (customize-apropos regexp
'faces
))
1442 (defun customize-apropos-groups (regexp)
1443 "Customize all loaded groups matching REGEXP."
1444 (interactive "sCustomize groups (regexp): \n")
1445 (customize-apropos regexp
'groups
))
1449 (defcustom custom-buffer-style
'links
1450 "Control the presentation style for customization buffers.
1451 The value should be a symbol, one of:
1453 brackets: groups nest within each other with big horizontal brackets.
1454 links: groups have links to subgroups."
1455 :type
'(radio (const brackets
)
1457 :group
'custom-buffer
)
1459 (defcustom custom-buffer-done-kill nil
1460 "Non-nil means exiting a Custom buffer should kill it."
1463 :group
'custom-buffer
)
1465 (defcustom custom-buffer-indent
3
1466 "Number of spaces to indent nested groups."
1468 :group
'custom-buffer
)
1470 (defun custom-get-fresh-buffer (name)
1471 "Get a fresh new buffer with name NAME.
1472 If the buffer already exist, clean it up to be like new.
1473 Beware: it's not quite like new. Good enough for custom, but maybe
1475 ;; To be more complete, we should also kill all permanent-local variables,
1476 ;; but it's not needed for custom.
1477 (let ((buf (get-buffer name
)))
1478 (when (and buf
(buffer-local-value 'buffer-file-name buf
))
1479 ;; This will check if the file is not saved.
1483 (get-buffer-create name
)
1484 (with-current-buffer buf
1485 (kill-all-local-variables)
1486 (run-hooks 'kill-buffer-hook
)
1487 ;; Delete overlays before erasing the buffer so the overlay hooks
1488 ;; don't get run spuriously when we erase the buffer.
1489 (let ((ols (overlay-lists)))
1490 (dolist (ol (nconc (car ols
) (cdr ols
)))
1491 (delete-overlay ol
)))
1496 (defun custom-buffer-create (options &optional name description
)
1497 "Create a buffer containing OPTIONS.
1498 Optional NAME is the name of the buffer.
1499 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1500 SYMBOL is a customization option, and WIDGET is a widget for editing
1502 (pop-to-buffer (custom-get-fresh-buffer (or name
"*Customization*")))
1503 (custom-buffer-create-internal options description
))
1506 (defun custom-buffer-create-other-window (options &optional name description
)
1507 "Create a buffer containing OPTIONS, and display it in another window.
1508 The result includes selecting that window.
1509 Optional NAME is the name of the buffer.
1510 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1511 SYMBOL is a customization option, and WIDGET is a widget for editing
1513 (unless name
(setq name
"*Customization*"))
1514 (let ((pop-up-windows t
)
1515 (same-window-buffer-names nil
)
1516 (same-window-regexps nil
))
1517 (pop-to-buffer (custom-get-fresh-buffer name
))
1518 (custom-buffer-create-internal options description
)))
1520 (defcustom custom-reset-button-menu nil
1521 "If non-nil, only show a single reset button in customize buffers.
1522 This button will have a menu with all three reset operations."
1524 :group
'custom-buffer
)
1526 (defcustom custom-buffer-verbose-help t
1527 "If non-nil, include explanatory text in the customization buffer."
1529 :group
'custom-buffer
)
1531 (defun Custom-buffer-done (&rest ignore
)
1532 "Exit current Custom buffer according to `custom-buffer-done-kill'."
1534 (quit-window custom-buffer-done-kill
))
1536 (defvar custom-button nil
1537 "Face used for buttons in customization buffers.")
1539 (defvar custom-button-mouse nil
1540 "Mouse face used for buttons in customization buffers.")
1542 (defvar custom-button-pressed nil
1543 "Face used for pressed buttons in customization buffers.")
1545 (defcustom custom-search-field t
1546 "If non-nil, show a search field in Custom buffers."
1549 :group
'custom-buffer
)
1551 (defcustom custom-raised-buttons
(not (equal (face-valid-attribute-values :box
)
1552 '(("unspecified" . unspecified
))))
1553 "If non-nil, indicate active buttons in a `raised-button' style.
1554 Otherwise use brackets."
1557 :group
'custom-buffer
1558 :set
(lambda (variable value
)
1559 (custom-set-default variable value
)
1561 (if value
'custom-button
'custom-button-unraised
))
1562 (setq custom-button-mouse
1563 (if value
'custom-button-mouse
'highlight
))
1564 (setq custom-button-pressed
1566 'custom-button-pressed
1567 'custom-button-pressed-unraised
))))
1569 (defun custom-buffer-create-internal (options &optional description
)
1571 (let ((init-file (or custom-file user-init-file
)))
1572 ;; Insert verbose help at the top of the custom buffer.
1573 (when custom-buffer-verbose-help
1574 (widget-insert (if init-file
1575 "To apply changes, use the Save or Set buttons."
1576 "Custom settings cannot be saved; maybe you started Emacs with `-q'.")
1577 "\nFor details, see ")
1578 (widget-create 'custom-manual
1579 :tag
"Saving Customizations"
1580 "(emacs)Saving Customizations")
1581 (widget-insert " in the ")
1582 (widget-create 'custom-manual
1584 :help-echo
"Read the Emacs manual."
1586 (widget-insert "."))
1587 (widget-insert "\n")
1589 ;; Insert the search field.
1590 (when custom-search-field
1591 (widget-insert "\n")
1592 (let* ((echo "Search for custom items")
1596 :size
40 :help-echo echo
1597 :action
`(lambda (widget &optional event
)
1598 (customize-apropos (widget-value widget
))))))
1600 (widget-create-child-and-convert
1601 search-widget
'push-button
1603 :help-echo echo
:action
1604 (lambda (widget &optional event
)
1605 (customize-apropos (widget-value (widget-get widget
:parent
)))))
1606 (widget-insert "\n")))
1608 ;; The custom command buttons are also in the toolbar, so for a
1609 ;; time they were not inserted in the buffer if the toolbar was in use.
1610 ;; But it can be a little confusing for the buffer layout to
1611 ;; change according to whether or nor the toolbar is on, not to
1612 ;; mention that a custom buffer can in theory be created in a
1613 ;; frame with a toolbar, then later viewed in one without.
1614 ;; So now the buttons are always inserted in the buffer. (Bug#1326)
1615 (if custom-buffer-verbose-help
1617 Operate on all settings in this buffer:\n"))
1618 (let ((button (lambda (tag action active help icon
)
1621 (widget-create 'push-button
:tag tag
1622 :help-echo help
:action action
))))
1623 (commands custom-commands
))
1624 (apply button
(pop commands
)) ; Set for current session
1625 (apply button
(pop commands
)) ; Save for future sessions
1626 (if custom-reset-button-menu
1629 (widget-create 'push-button
1631 :help-echo
"Show a menu with reset operations."
1632 :mouse-down-action
'ignore
1633 :action
'custom-reset
))
1634 (widget-insert "\n")
1635 (apply button
(pop commands
)) ; Undo edits
1636 (apply button
(pop commands
)) ; Reset to saved
1637 (apply button
(pop commands
)) ; Erase customization
1639 (pop commands
) ; Help (omitted)
1640 (apply button
(pop commands
)))) ; Exit
1641 (widget-insert "\n\n"))
1643 ;; Now populate the custom buffer.
1644 (message "Creating customization items...")
1645 (buffer-disable-undo)
1646 (setq custom-options
1647 (if (= (length options
) 1)
1648 (mapcar (lambda (entry)
1649 (widget-create (nth 1 entry
)
1650 :documentation-shown t
1651 :custom-state
'unknown
1652 :tag
(custom-unlispify-tag-name
1654 :value
(nth 0 entry
)))
1657 (length (length options
)))
1658 (mapcar (lambda (entry)
1660 (message "Creating customization items ...%2d%%"
1661 (/ (* 100.0 count
) length
))
1662 (widget-create (nth 1 entry
)
1663 :tag
(custom-unlispify-tag-name
1665 :value
(nth 0 entry
))
1666 (setq count
(1+ count
))
1667 (unless (eq (preceding-char) ?
\n)
1668 (widget-insert "\n"))
1669 (widget-insert "\n")))
1671 (unless (eq (preceding-char) ?
\n)
1672 (widget-insert "\n"))
1673 (message "Creating customization items ...done")
1674 (message "Resetting customization items...")
1675 (unless (eq custom-buffer-style
'tree
)
1676 (mapc 'custom-magic-reset custom-options
))
1677 (message "Resetting customization items...done")
1678 (message "Creating customization setup...")
1680 (buffer-enable-undo)
1681 (goto-char (point-min))
1682 (message "Creating customization setup...done"))
1684 ;;; The Tree Browser.
1687 (defun customize-browse (&optional group
)
1688 "Create a tree browser for the customize hierarchy."
1691 (setq group
'emacs
))
1692 (let ((name "*Customize Browser*"))
1693 (pop-to-buffer (custom-get-fresh-buffer name
)))
1695 (widget-insert (format "\
1696 %s buttons; type RET or click mouse-1
1697 on a button to invoke its action.
1698 Invoke [+] to expand a group, and [-] to collapse an expanded group.\n"
1699 (if custom-raised-buttons
1700 "`Raised' text indicates"
1701 "Square brackets indicate")))
1704 (if custom-browse-only-groups
1706 Invoke the [Group] button below to edit that item in another window.\n\n")
1707 (widget-insert "Invoke the ")
1708 (widget-create 'item
1711 :tag-glyph
"folder")
1712 (widget-insert ", ")
1713 (widget-create 'item
1717 (widget-insert ", and ")
1718 (widget-create 'item
1721 :tag-glyph
"option")
1722 (widget-insert " buttons below to edit that
1723 item in another window.\n\n"))
1724 (let ((custom-buffer-style 'tree
))
1725 (widget-create 'custom-group
1727 :custom-state
'unknown
1728 :tag
(custom-unlispify-tag-name group
)
1731 (goto-char (point-min)))
1733 (define-widget 'custom-browse-visibility
'item
1734 "Control visibility of items in the customize tree browser."
1736 :action
'custom-browse-visibility-action
)
1738 (defun custom-browse-visibility-action (widget &rest ignore
)
1739 (let ((custom-buffer-style 'tree
))
1740 (custom-toggle-parent widget
)))
1742 (define-widget 'custom-browse-group-tag
'custom-group-link
1743 "Show parent in other window when activated."
1746 :action
'custom-browse-group-tag-action
)
1748 (defun custom-browse-group-tag-action (widget &rest ignore
)
1749 (let ((parent (widget-get widget
:parent
)))
1750 (customize-group-other-window (widget-value parent
))))
1752 (define-widget 'custom-browse-variable-tag
'custom-group-link
1753 "Show parent in other window when activated."
1756 :action
'custom-browse-variable-tag-action
)
1758 (defun custom-browse-variable-tag-action (widget &rest ignore
)
1759 (let ((parent (widget-get widget
:parent
)))
1760 (customize-variable-other-window (widget-value parent
))))
1762 (define-widget 'custom-browse-face-tag
'custom-group-link
1763 "Show parent in other window when activated."
1766 :action
'custom-browse-face-tag-action
)
1768 (defun custom-browse-face-tag-action (widget &rest ignore
)
1769 (let ((parent (widget-get widget
:parent
)))
1770 (customize-face-other-window (widget-value parent
))))
1772 (defconst custom-browse-alist
'((" " "space")
1778 (defun custom-browse-insert-prefix (prefix)
1779 "Insert PREFIX. On XEmacs convert it to line graphics."
1780 ;; Fixme: do graphics.
1781 (if nil
; (featurep 'xemacs)
1784 (while (not (string-equal prefix
""))
1785 (let ((entry (substring prefix
0 3)))
1786 (setq prefix
(substring prefix
3))
1787 (let ((overlay (make-overlay (1- (point)) (point) nil t nil
))
1788 (name (nth 1 (assoc entry custom-browse-alist
))))
1789 (overlay-put overlay
'end-glyph
(widget-glyph-find name entry
))
1790 (overlay-put overlay
'start-open t
)
1791 (overlay-put overlay
'end-open t
)))))
1794 ;;; Modification of Basic Widgets.
1796 ;; We add extra properties to the basic widgets needed here. This is
1797 ;; fine, as long as we are careful to stay within our own namespace.
1799 ;; We want simple widgets to be displayed by default, but complex
1800 ;; widgets to be hidden.
1802 (widget-put (get 'item
'widget-type
) :custom-show t
)
1803 (widget-put (get 'editable-field
'widget-type
)
1804 :custom-show
(lambda (widget value
)
1805 (let ((pp (pp-to-string value
)))
1806 (cond ((string-match "\n" pp
)
1811 (widget-put (get 'menu-choice
'widget-type
) :custom-show t
)
1813 ;;; The `custom-manual' Widget.
1815 (define-widget 'custom-manual
'info-link
1816 "Link to the manual entry for this customization option."
1817 :help-echo
"Read the manual entry for this option."
1818 :keymap custom-mode-link-map
1819 :follow-link
'mouse-face
1820 :button-face
'custom-link
1821 :mouse-face
'highlight
1822 :pressed-face
'highlight
1825 ;;; The `custom-magic' Widget.
1827 (defgroup custom-magic-faces nil
1828 "Faces used by the magic button."
1829 :group
'custom-faces
1830 :group
'custom-buffer
)
1832 (defface custom-invalid
'((((class color
))
1833 (:foreground
"yellow1" :background
"red1"))
1835 (:weight bold
:slant italic
:underline t
)))
1836 "Face used when the customize item is invalid."
1837 :group
'custom-magic-faces
)
1838 (define-obsolete-face-alias 'custom-invalid-face
'custom-invalid
"22.1")
1840 (defface custom-rogue
'((((class color
))
1841 (:foreground
"pink" :background
"black"))
1844 "Face used when the customize item is not defined for customization."
1845 :group
'custom-magic-faces
)
1846 (define-obsolete-face-alias 'custom-rogue-face
'custom-rogue
"22.1")
1848 (defface custom-modified
'((((min-colors 88) (class color
))
1849 (:foreground
"white" :background
"blue1"))
1851 (:foreground
"white" :background
"blue"))
1853 (:slant italic
:bold
)))
1854 "Face used when the customize item has been modified."
1855 :group
'custom-magic-faces
)
1856 (define-obsolete-face-alias 'custom-modified-face
'custom-modified
"22.1")
1858 (defface custom-set
'((((min-colors 88) (class color
))
1859 (:foreground
"blue1" :background
"white"))
1861 (:foreground
"blue" :background
"white"))
1864 "Face used when the customize item has been set."
1865 :group
'custom-magic-faces
)
1866 (define-obsolete-face-alias 'custom-set-face
'custom-set
"22.1")
1868 (defface custom-changed
'((((min-colors 88) (class color
))
1869 (:foreground
"white" :background
"blue1"))
1871 (:foreground
"white" :background
"blue"))
1874 "Face used when the customize item has been changed."
1875 :group
'custom-magic-faces
)
1876 (define-obsolete-face-alias 'custom-changed-face
'custom-changed
"22.1")
1878 (defface custom-themed
'((((min-colors 88) (class color
))
1879 (:foreground
"white" :background
"blue1"))
1881 (:foreground
"white" :background
"blue"))
1884 "Face used when the customize item has been set by a theme."
1885 :group
'custom-magic-faces
)
1887 (defface custom-saved
'((t (:underline t
)))
1888 "Face used when the customize item has been saved."
1889 :group
'custom-magic-faces
)
1890 (define-obsolete-face-alias 'custom-saved-face
'custom-saved
"22.1")
1892 (defconst custom-magic-alist
1893 '((nil "#" underline
"\
1894 UNINITIALIZED, you should not see this.")
1895 (unknown "?" italic
"\
1896 UNKNOWN, you should not see this.")
1897 (hidden "-" default
"\
1898 HIDDEN, invoke \"Show\" in the previous line to show." "\
1899 group now hidden, invoke \"Show\", above, to show contents.")
1900 (invalid "x" custom-invalid
"\
1901 INVALID, the displayed value cannot be set.")
1902 (modified "*" custom-modified
"\
1903 EDITED, shown value does not take effect until you set or save it." "\
1904 something in this group has been edited but not set.")
1905 (set "+" custom-set
"\
1906 SET for current session only." "\
1907 something in this group has been set but not saved.")
1908 (changed ":" custom-changed
"\
1909 CHANGED outside Customize; operating on it here may be unreliable." "\
1910 something in this group has been changed outside customize.")
1911 (saved "!" custom-saved
"\
1913 something in this group has been set and saved.")
1914 (themed "o" custom-themed
"\
1916 visible group members are all at standard values.")
1917 (rogue "@" custom-rogue
"\
1918 NO CUSTOMIZATION DATA; not intended to be customized." "\
1919 something in this group is not prepared for customization.")
1920 (standard " " nil
"\
1922 visible group members are all at standard values."))
1923 "Alist of customize option states.
1924 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1926 STATE is one of the following symbols:
1929 For internal use, should never occur.
1931 For internal use, should never occur.
1933 This item is not being displayed.
1935 This item is modified, but has an invalid form.
1937 This item is modified, and has a valid form.
1939 This item has been set but not saved.
1941 The current value of this item has been changed outside Customize.
1943 This item is marked for saving.
1945 This item has no customization information.
1947 This item is unchanged from the standard setting.
1949 MAGIC is a string used to present that state.
1951 FACE is a face used to present the state.
1953 ITEM-DESC is a string describing the state for options.
1955 GROUP-DESC is a string describing the state for groups. If this is
1956 left out, ITEM-DESC will be used.
1958 The string %c in either description will be replaced with the
1959 category of the item. These are `group'. `option', and `face'.
1961 The list should be sorted most significant first.")
1963 (defcustom custom-magic-show
'long
1964 "If non-nil, show textual description of the state.
1965 If `long', show a full-line description, not just one word."
1966 :type
'(choice (const :tag
"no" nil
)
1968 (other :tag
"short" short
))
1969 :group
'custom-buffer
)
1971 (defcustom custom-magic-show-hidden
'(option face
)
1972 "Control whether the State button is shown for hidden items.
1973 The value should be a list with the custom categories where the State
1974 button should be visible. Possible categories are `group', `option',
1976 :type
'(set (const group
) (const option
) (const face
))
1977 :group
'custom-buffer
)
1979 (defcustom custom-magic-show-button nil
1980 "Show a \"magic\" button indicating the state of each customization option."
1982 :group
'custom-buffer
)
1984 (define-widget 'custom-magic
'default
1985 "Show and manipulate state for a customization option."
1987 :action
'widget-parent-action
1990 :value-create
'custom-magic-value-create
1991 :value-delete
'widget-children-value-delete
)
1993 (defun widget-magic-mouse-down-action (widget &optional event
)
1994 ;; Non-nil unless hidden.
1995 (not (eq (widget-get (widget-get (widget-get widget
:parent
) :parent
)
1999 (defun custom-magic-value-create (widget)
2000 "Create compact status report for WIDGET."
2001 (let* ((parent (widget-get widget
:parent
))
2002 (state (widget-get parent
:custom-state
))
2003 (hidden (eq state
'hidden
))
2004 (entry (assq state custom-magic-alist
))
2005 (magic (nth 1 entry
))
2006 (face (nth 2 entry
))
2007 (category (widget-get parent
:custom-category
))
2008 (text (or (and (eq category
'group
)
2011 (form (widget-get parent
:custom-form
))
2013 (unless (eq state
'hidden
)
2014 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text
)
2015 (setq text
(concat (match-string 1 text
)
2016 (symbol-name category
)
2017 (match-string 2 text
))))
2018 (when (and custom-magic-show
2020 (memq category custom-magic-show-hidden
)))
2022 (when (and (eq category
'group
)
2023 (not (and (eq custom-buffer-style
'links
)
2024 (> (widget-get parent
:custom-level
) 1))))
2025 (insert-char ?\
(* custom-buffer-indent
2026 (widget-get parent
:custom-level
))))
2027 (push (widget-create-child-and-convert
2029 :help-echo
"Change the state of this item."
2030 :format
(if hidden
"%t" "%[%t%]")
2031 :button-prefix
'widget-push-button-prefix
2032 :button-suffix
'widget-push-button-suffix
2033 :mouse-down-action
'widget-magic-mouse-down-action
2037 (let ((start (point)))
2038 (if (eq custom-magic-show
'long
)
2040 (insert (symbol-name state
)))
2041 (cond ((eq form
'lisp
)
2043 ((eq form
'mismatch
)
2044 (insert " (mismatch)")))
2045 (put-text-property start
(point) 'face
'custom-state
))
2047 (when (and (eq category
'group
)
2048 (not (and (eq custom-buffer-style
'links
)
2049 (> (widget-get parent
:custom-level
) 1))))
2050 (insert-char ?\
(* custom-buffer-indent
2051 (widget-get parent
:custom-level
))))
2052 (when custom-magic-show-button
2053 (when custom-magic-show
2054 (let ((indent (widget-get parent
:indent
)))
2056 (insert-char ? indent
))))
2057 (push (widget-create-child-and-convert
2059 :mouse-down-action
'widget-magic-mouse-down-action
2063 :help-echo
"Change the state."
2064 :format
(if hidden
"%t" "%[%t%]")
2065 :tag
(if (memq form
'(lisp mismatch
))
2066 (concat "(" magic
")")
2067 (concat "[" magic
"]")))
2070 (widget-put widget
:children children
))))
2072 (defun custom-magic-reset (widget)
2073 "Redraw the :custom-magic property of WIDGET."
2074 (let ((magic (widget-get widget
:custom-magic
)))
2075 (widget-value-set magic
(widget-value magic
))))
2077 ;;; The `custom' Widget.
2079 (defface custom-button
2080 '((((type x w32 ns
) (class color
)) ; Like default modeline
2081 (:box
(:line-width
2 :style released-button
)
2082 :background
"lightgrey" :foreground
"black"))
2085 "Face for custom buffer buttons if `custom-raised-buttons' is non-nil."
2087 :group
'custom-faces
)
2088 (define-obsolete-face-alias 'custom-button-face
'custom-button
"22.1")
2090 (defface custom-button-mouse
2091 '((((type x w32 ns
) (class color
))
2092 (:box
(:line-width
2 :style released-button
)
2093 :background
"grey90" :foreground
"black"))
2095 ;; This is for text terminals that support mouse, like GPM mouse
2096 ;; or the MS-DOS terminal: inverse-video makes the button stand
2097 ;; out on mouse-over.
2098 (:inverse-video t
)))
2099 "Mouse face for custom buffer buttons if `custom-raised-buttons' is non-nil."
2101 :group
'custom-faces
)
2103 (defface custom-button-unraised
2104 '((t :inherit underline
))
2105 "Face for custom buffer buttons if `custom-raised-buttons' is nil."
2107 :group
'custom-faces
)
2110 (if custom-raised-buttons
'custom-button
'custom-button-unraised
))
2112 (setq custom-button-mouse
2113 (if custom-raised-buttons
'custom-button-mouse
'highlight
))
2115 (defface custom-button-pressed
2116 '((((type x w32 ns
) (class color
))
2117 (:box
(:line-width
2 :style pressed-button
)
2118 :background
"lightgrey" :foreground
"black"))
2120 (:inverse-video t
)))
2121 "Face for pressed custom buttons if `custom-raised-buttons' is non-nil."
2123 :group
'custom-faces
)
2124 (define-obsolete-face-alias 'custom-button-pressed-face
2125 'custom-button-pressed
"22.1")
2127 (defface custom-button-pressed-unraised
2128 '((default :inherit custom-button-unraised
)
2129 (((class color
) (background light
)) :foreground
"magenta4")
2130 (((class color
) (background dark
)) :foreground
"violet"))
2131 "Face for pressed custom buttons if `custom-raised-buttons' is nil."
2133 :group
'custom-faces
)
2135 (setq custom-button-pressed
2136 (if custom-raised-buttons
2137 'custom-button-pressed
2138 'custom-button-pressed-unraised
))
2140 (defface custom-documentation
'((t nil
))
2141 "Face used for documentation strings in customization buffers."
2142 :group
'custom-faces
)
2143 (define-obsolete-face-alias 'custom-documentation-face
2144 'custom-documentation
"22.1")
2146 (defface custom-state
'((((class color
)
2148 (:foreground
"lime green"))
2151 (:foreground
"dark green"))
2153 "Face used for State descriptions in the customize buffer."
2154 :group
'custom-faces
)
2155 (define-obsolete-face-alias 'custom-state-face
'custom-state
"22.1")
2157 (defface custom-link
2158 '((t :inherit link
))
2159 "Face for links in customization buffers."
2161 :group
'custom-faces
)
2163 (define-widget 'custom
'default
2164 "Customize a user option."
2166 :convert-widget
'custom-convert-widget
2167 :notify
'custom-notify
2170 :custom-state
'hidden
2171 :documentation-property
'widget-subclass-responsibility
2172 :value-create
'widget-subclass-responsibility
2173 :value-delete
'widget-children-value-delete
2174 :value-get
'widget-value-value-get
2175 :validate
'widget-children-validate
2176 :match
(lambda (widget value
) (symbolp value
)))
2178 (defun custom-convert-widget (widget)
2179 "Initialize :value and :tag from :args in WIDGET."
2180 (let ((args (widget-get widget
:args
)))
2182 (widget-put widget
:value
(widget-apply widget
2183 :value-to-internal
(car args
)))
2184 (widget-put widget
:tag
(custom-unlispify-tag-name (car args
)))
2185 (widget-put widget
:args nil
)))
2188 (defun custom-notify (widget &rest args
)
2189 "Keep track of changes."
2190 (let ((state (widget-get widget
:custom-state
)))
2191 (unless (eq state
'modified
)
2192 (unless (memq state
'(nil unknown hidden
))
2193 (widget-put widget
:custom-state
'modified
))
2194 (custom-magic-reset widget
)
2195 (apply 'widget-default-notify widget args
))))
2197 (defun custom-redraw (widget)
2198 "Redraw WIDGET with current settings."
2199 (let ((line (count-lines (point-min) (point)))
2200 (column (current-column))
2202 (from (marker-position (widget-get widget
:from
)))
2203 (to (marker-position (widget-get widget
:to
))))
2205 (widget-value-set widget
(widget-value widget
))
2206 (custom-redraw-magic widget
))
2207 (when (and (>= pos from
) (<= pos to
))
2210 (goto-char (point-min))
2211 (forward-line (if (> column
0)
2214 (move-to-column column
))
2217 (defun custom-redraw-magic (widget)
2218 "Redraw WIDGET state with current settings."
2220 (let ((magic (widget-get widget
:custom-magic
)))
2222 (widget-value-set magic
(widget-value magic
))
2223 (when (setq widget
(widget-get widget
:group
))
2224 (custom-group-state-update widget
)))
2226 (setq widget nil
)))))
2229 (defun custom-show (widget value
)
2230 "Non-nil if WIDGET should be shown with VALUE by default."
2231 (let ((show (widget-get widget
:custom-show
)))
2232 (if (functionp show
)
2233 (funcall show widget value
)
2236 (defun custom-load-widget (widget)
2237 "Load all dependencies for WIDGET."
2238 (custom-load-symbol (widget-value widget
)))
2240 (defun custom-unloaded-symbol-p (symbol)
2241 "Return non-nil if the dependencies of SYMBOL have not yet been loaded."
2243 (loads (get symbol
'custom-loads
))
2246 (setq load
(car loads
)
2248 (cond ((symbolp load
)
2249 (unless (featurep load
)
2251 ((assoc load load-history
))
2252 ((assoc (locate-library load
) load-history
)
2258 (defun custom-unloaded-widget-p (widget)
2259 "Return non-nil if the dependencies of WIDGET have not yet been loaded."
2260 (custom-unloaded-symbol-p (widget-value widget
)))
2262 (defun custom-toggle-hide (widget)
2263 "Toggle visibility of WIDGET."
2264 (custom-load-widget widget
)
2265 (let ((state (widget-get widget
:custom-state
)))
2266 (cond ((memq state
'(invalid modified set
))
2267 (error "There are unsaved changes"))
2269 (widget-put widget
:custom-state
'unknown
))
2271 (widget-put widget
:documentation-shown nil
)
2272 (widget-put widget
:custom-state
'hidden
)))
2273 (custom-redraw widget
)
2276 (defun custom-toggle-parent (widget &rest ignore
)
2277 "Toggle visibility of parent of WIDGET."
2278 (custom-toggle-hide (widget-get widget
:parent
)))
2280 (defun custom-add-see-also (widget &optional prefix
)
2281 "Add `See also ...' to WIDGET if there are any links.
2282 Insert PREFIX first if non-nil."
2283 (let* ((symbol (widget-get widget
:value
))
2284 (links (get symbol
'custom-links
))
2285 (many (> (length links
) 2))
2286 (buttons (widget-get widget
:buttons
))
2287 (indent (widget-get widget
:indent
)))
2290 (insert-char ?\ indent
))
2293 (insert "See also ")
2295 (push (widget-create-child-and-convert
2297 :button-face
'custom-link
2298 :mouse-face
'highlight
2299 :pressed-face
'highlight
)
2301 (setq links
(cdr links
))
2310 (widget-put widget
:buttons buttons
))))
2312 (defun custom-add-parent-links (widget &optional initial-string doc-initial-string
)
2313 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
2314 The value is non-nil if any parents were found.
2315 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
2316 (let ((name (widget-value widget
))
2317 (type (widget-type widget
))
2318 (buttons (widget-get widget
:buttons
))
2321 (insert (or initial-string
"Groups:"))
2322 (mapatoms (lambda (symbol)
2323 (when (member (list name type
) (get symbol
'custom-group
))
2325 (push (widget-create-child-and-convert
2326 widget
'custom-group-link
2327 :tag
(custom-unlispify-tag-name symbol
)
2330 (setq parents
(cons symbol parents
)))))
2333 (delete-region start
(point)))
2334 (widget-put widget
:buttons buttons
)
2337 ;;; The `custom-comment' Widget.
2339 ;; like the editable field
2340 (defface custom-comment
'((((type tty
))
2341 :background
"yellow3"
2342 :foreground
"black")
2343 (((class grayscale color
)
2345 :background
"gray85")
2346 (((class grayscale color
)
2348 :background
"dim gray")
2351 "Face used for comments on variables or faces."
2353 :group
'custom-faces
)
2354 (define-obsolete-face-alias 'custom-comment-face
'custom-comment
"22.1")
2356 ;; like font-lock-comment-face
2357 (defface custom-comment-tag
2358 '((((class color
) (background dark
)) (:foreground
"gray80"))
2359 (((class color
) (background light
)) (:foreground
"blue4"))
2360 (((class grayscale
) (background light
))
2361 (:foreground
"DimGray" :weight bold
:slant italic
))
2362 (((class grayscale
) (background dark
))
2363 (:foreground
"LightGray" :weight bold
:slant italic
))
2365 "Face used for the comment tag on variables or faces."
2366 :group
'custom-faces
)
2367 (define-obsolete-face-alias 'custom-comment-tag-face
'custom-comment-tag
"22.1")
2369 (define-widget 'custom-comment
'string
2372 :help-echo
"Edit a comment here."
2373 :sample-face
'custom-comment-tag
2374 :value-face
'custom-comment
2376 :create
'custom-comment-create
)
2378 (defun custom-comment-create (widget)
2379 (let* ((null-comment (equal "" (widget-value widget
))))
2380 (if (or (widget-get (widget-get widget
:parent
) :comment-shown
)
2382 (widget-default-create widget
)
2383 ;; `widget-default-delete' expects markers in these slots --
2384 ;; maybe it shouldn't.
2385 (widget-put widget
:from
(point-marker))
2386 (widget-put widget
:to
(point-marker)))))
2388 (defun custom-comment-hide (widget)
2389 (widget-put (widget-get widget
:parent
) :comment-shown nil
))
2391 ;; Those functions are for the menu. WIDGET is NOT the comment widget. It's
2392 ;; the global custom one
2393 (defun custom-comment-show (widget)
2394 (widget-put widget
:comment-shown t
)
2395 (custom-redraw widget
)
2398 (defun custom-comment-invisible-p (widget)
2399 (let ((val (widget-value (widget-get widget
:comment-widget
))))
2401 (not (widget-get widget
:comment-shown
)))))
2403 ;;; The `custom-variable' Widget.
2405 (defface custom-variable-tag
2408 (:foreground
"light blue" :weight bold
))
2409 (((min-colors 88) (class color
)
2411 (:foreground
"blue1" :weight bold
))
2414 (:foreground
"blue" :weight bold
))
2416 "Face used for unpushable variable tags."
2417 :group
'custom-faces
)
2418 (define-obsolete-face-alias 'custom-variable-tag-face
2419 'custom-variable-tag
"22.1")
2421 (defface custom-variable-button
'((t (:underline t
:weight bold
)))
2422 "Face used for pushable variable tags."
2423 :group
'custom-faces
)
2424 (define-obsolete-face-alias 'custom-variable-button-face
2425 'custom-variable-button
"22.1")
2427 (defcustom custom-variable-default-form
'edit
2428 "Default form of displaying variable values."
2429 :type
'(choice (const edit
)
2431 :group
'custom-buffer
2434 (defun custom-variable-documentation (variable)
2435 "Return documentation of VARIABLE for use in Custom buffer.
2436 Normally just return the docstring. But if VARIABLE automatically
2437 becomes buffer local when set, append a message to that effect."
2438 (if (and (local-variable-if-set-p variable
)
2439 (or (not (local-variable-p variable
))
2441 (local-variable-if-set-p variable
))))
2442 (concat (documentation-property variable
'variable-documentation
)
2444 This variable automatically becomes buffer-local when set outside Custom.
2445 However, setting it through Custom sets the default value.")
2446 (documentation-property variable
'variable-documentation
)))
2448 (define-widget 'custom-variable
'custom
2449 "A widget for displaying a Custom variable.
2451 The following property has a special meaning for this widget:
2452 :hidden-states - A list of widget states for which the widget's initial
2453 contents should be hidden."
2455 :help-echo
"Set or reset this variable."
2456 :documentation-property
#'custom-variable-documentation
2457 :custom-category
'option
2459 :custom-menu
'custom-variable-menu-create
2460 :custom-form nil
; defaults to value of `custom-variable-default-form'
2461 :value-create
'custom-variable-value-create
2462 :action
'custom-variable-action
2463 :hidden-states
'(standard)
2464 :custom-set
'custom-variable-set
2465 :custom-mark-to-save
'custom-variable-mark-to-save
2466 :custom-reset-current
'custom-redraw
2467 :custom-reset-saved
'custom-variable-reset-saved
2468 :custom-reset-standard
'custom-variable-reset-standard
2469 :custom-mark-to-reset-standard
'custom-variable-mark-to-reset-standard
2470 :custom-standard-value
'custom-variable-standard-value
2471 :custom-state-set-and-redraw
'custom-variable-state-set-and-redraw
)
2473 (defun custom-variable-type (symbol)
2474 "Return a widget suitable for editing the value of SYMBOL.
2475 If SYMBOL has a `custom-type' property, use that.
2476 Otherwise, try matching SYMBOL against `custom-guess-name-alist' and
2477 try matching its doc string against `custom-guess-doc-alist'."
2478 (let* ((type (or (get symbol
'custom-type
)
2479 (and (not (get symbol
'standard-value
))
2480 (custom-guess-type symbol
))
2482 (options (get symbol
'custom-options
))
2483 (tmp (if (listp type
)
2484 (copy-sequence type
)
2487 (widget-put tmp
:options options
))
2490 (defun custom-variable-value-create (widget)
2491 "Here is where you edit the variable's value."
2492 (custom-load-widget widget
)
2493 (unless (widget-get widget
:custom-form
)
2494 (widget-put widget
:custom-form custom-variable-default-form
))
2495 (let* ((buttons (widget-get widget
:buttons
))
2496 (children (widget-get widget
:children
))
2497 (form (widget-get widget
:custom-form
))
2498 (symbol (widget-get widget
:value
))
2499 (tag (widget-get widget
:tag
))
2500 (type (custom-variable-type symbol
))
2501 (conv (widget-convert type
))
2502 (get (or (get symbol
'custom-get
) 'default-value
))
2503 (prefix (widget-get widget
:custom-prefix
))
2504 (last (widget-get widget
:custom-last
))
2505 (value (if (default-boundp symbol
)
2506 (funcall get symbol
)
2507 (widget-get conv
:value
)))
2508 (state (or (widget-get widget
:custom-state
)
2509 (if (memq (custom-variable-state symbol value
)
2510 (widget-get widget
:hidden-states
))
2513 ;; If we don't know the state, see if we need to edit it in lisp form.
2515 (setq state
(if (custom-show type value
) 'unknown
'hidden
)))
2516 (when (eq state
'unknown
)
2517 (unless (widget-apply conv
:match value
)
2518 (setq form
'mismatch
)))
2519 ;; Now we can create the child widget.
2520 (cond ((eq custom-buffer-style
'tree
)
2521 (insert prefix
(if last
" `--- " " |--- "))
2522 (push (widget-create-child-and-convert
2523 widget
'custom-browse-variable-tag
)
2525 (insert " " tag
"\n")
2526 (widget-put widget
:buttons buttons
))
2528 ;; Indicate hidden value.
2529 (push (widget-create-child-and-convert
2530 widget
'custom-visibility
2531 :help-echo
"Show the value of this option."
2536 :action
'custom-toggle-parent
2540 (push (widget-create-child-and-convert
2543 :sample-face
'custom-variable-tag
2547 ((memq form
'(lisp mismatch
))
2548 ;; In lisp mode edit the saved value when possible.
2549 (push (widget-create-child-and-convert
2550 widget
'custom-visibility
2551 :help-echo
"Hide the value of this option."
2556 :action
'custom-toggle-parent
2560 (let* ((value (cond ((get symbol
'saved-value
)
2561 (car (get symbol
'saved-value
)))
2562 ((get symbol
'standard-value
)
2563 (car (get symbol
'standard-value
)))
2564 ((default-boundp symbol
)
2565 (custom-quote (funcall get symbol
)))
2567 (custom-quote (widget-get conv
:value
))))))
2568 (insert (symbol-name symbol
) ": ")
2569 (push (widget-create-child-and-convert
2571 :button-face
'custom-variable-button-face
2573 :tag
(symbol-name symbol
)
2579 (push (widget-create-child-and-convert
2580 widget
'custom-visibility
2581 :help-echo
"Hide or show this option."
2586 :action
'custom-toggle-parent
2590 (let* ((format (widget-get type
:format
))
2591 tag-format value-format
)
2592 (unless (string-match ":" format
)
2593 (error "Bad format"))
2594 (setq tag-format
(substring format
0 (match-end 0)))
2595 (setq value-format
(substring format
(match-end 0)))
2596 (push (widget-create-child-and-convert
2599 :action
'custom-tag-action
2600 :help-echo
"Change value of this option."
2601 :mouse-down-action
'custom-tag-mouse-down-action
2602 :button-face
'custom-variable-button
2603 :sample-face
'custom-variable-tag
2606 (push (widget-create-child-and-convert
2608 :format value-format
2611 (unless (eq custom-buffer-style
'tree
)
2612 (unless (eq (preceding-char) ?
\n)
2613 (widget-insert "\n"))
2614 ;; Create the magic button.
2615 (let ((magic (widget-create-child-and-convert
2616 widget
'custom-magic nil
)))
2617 (widget-put widget
:custom-magic magic
)
2618 (push magic buttons
))
2619 (widget-put widget
:buttons buttons
)
2620 ;; Insert documentation.
2621 (widget-put widget
:documentation-indent
3)
2622 (widget-add-documentation-string-button
2623 widget
:visibility-widget
'custom-visibility
)
2625 ;; The comment field
2626 (unless (eq state
'hidden
)
2627 (let* ((comment (get symbol
'variable-comment
))
2629 (widget-create-child-and-convert
2630 widget
'custom-comment
2632 :value
(or comment
""))))
2633 (widget-put widget
:comment-widget comment-widget
)
2634 ;; Don't push it !!! Custom assumes that the first child is the
2636 (setq children
(append children
(list comment-widget
)))))
2637 ;; Update the rest of the properties.
2638 (widget-put widget
:custom-form form
)
2639 (widget-put widget
:children children
)
2640 ;; Now update the state.
2641 (if (eq state
'hidden
)
2642 (widget-put widget
:custom-state state
)
2643 (custom-variable-state-set widget
))
2645 (unless (eq state
'hidden
)
2646 (when (eq (widget-get widget
:custom-level
) 1)
2647 (custom-add-parent-links widget
))
2648 (custom-add-see-also widget
)))))
2650 (defun custom-tag-action (widget &rest args
)
2651 "Pass :action to first child of WIDGET's parent."
2652 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2655 (defun custom-tag-mouse-down-action (widget &rest args
)
2656 "Pass :mouse-down-action to first child of WIDGET's parent."
2657 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2658 :mouse-down-action args
))
2660 (defun custom-variable-state (symbol val
)
2661 "Return the state of SYMBOL if its value is VAL.
2662 If SYMBOL has a non-nil `custom-get' property, it overrides VAL.
2663 Possible return values are `standard', `saved', `set', `themed',
2664 `changed', and `rogue'."
2665 (let* ((get (or (get symbol
'custom-get
) 'default-value
))
2666 (value (if (default-boundp symbol
)
2667 (funcall get symbol
)
2669 (comment (get symbol
'variable-comment
))
2672 (cond ((progn (setq tmp
(get symbol
'customized-value
))
2674 (get symbol
'customized-variable-comment
))
2676 (if (condition-case nil
2677 (and (equal value
(eval (car tmp
)))
2678 (equal comment temp
))
2682 ((progn (setq tmp
(get symbol
'theme-value
))
2683 (setq temp
(get symbol
'saved-variable-comment
))
2685 (if (condition-case nil
2686 (and (equal comment temp
)
2689 (car (custom-variable-theme-value
2693 ((eq (caar tmp
) 'user
) 'saved
)
2694 ((eq (caar tmp
) 'changed
)
2695 (if (condition-case nil
2699 (car (get symbol
'standard-value
)))))
2701 ;; The value was originally set outside
2702 ;; custom, but it was set to the standard
2703 ;; value (probably an autoloaded defcustom).
2708 ((setq tmp
(get symbol
'standard-value
))
2709 (if (condition-case nil
2710 (and (equal value
(eval (car tmp
)))
2711 (equal comment nil
))
2717 (defun custom-variable-state-set (widget &optional state
)
2718 "Set the state of WIDGET to STATE.
2719 If STATE is nil, the value is computed by `custom-variable-state'."
2720 (widget-put widget
:custom-state
2721 (or state
(custom-variable-state (widget-value widget
)
2722 (widget-get widget
:value
)))))
2724 (defun custom-variable-standard-value (widget)
2725 (get (widget-value widget
) 'standard-value
))
2727 (defvar custom-variable-menu
2728 `(("Set for Current Session" custom-variable-set
2730 (eq (widget-get widget
:custom-state
) 'modified
)))
2731 ;; Note that in all the backquoted code in this file, we test
2732 ;; init-file-user rather than user-init-file. This is in case
2733 ;; cus-edit is loaded by something in site-start.el, because
2734 ;; user-init-file is not set at that stage.
2735 ;; http://lists.gnu.org/archive/html/emacs-devel/2007-10/msg00310.html
2736 ,@(when (or custom-file init-file-user
)
2737 '(("Save for Future Sessions" custom-variable-save
2739 (memq (widget-get widget
:custom-state
)
2740 '(modified set changed rogue
))))))
2741 ("Undo Edits" custom-redraw
2743 (and (default-boundp (widget-value widget
))
2744 (memq (widget-get widget
:custom-state
) '(modified changed
)))))
2745 ("Reset to Saved" custom-variable-reset-saved
2747 (and (or (get (widget-value widget
) 'saved-value
)
2748 (get (widget-value widget
) 'saved-variable-comment
))
2749 (memq (widget-get widget
:custom-state
)
2750 '(modified set changed rogue
)))))
2751 ,@(when (or custom-file init-file-user
)
2752 '(("Erase Customization" custom-variable-reset-standard
2754 (and (get (widget-value widget
) 'standard-value
)
2755 (memq (widget-get widget
:custom-state
)
2756 '(modified set changed saved rogue
)))))))
2757 ("Set to Backup Value" custom-variable-reset-backup
2759 (get (widget-value widget
) 'backup-value
)))
2760 ("---" ignore ignore
)
2761 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
2762 ("---" ignore ignore
)
2763 ("Show Current Value" custom-variable-edit
2765 (eq (widget-get widget
:custom-form
) 'lisp
)))
2766 ("Show Saved Lisp Expression" custom-variable-edit-lisp
2768 (eq (widget-get widget
:custom-form
) 'edit
))))
2769 "Alist of actions for the `custom-variable' widget.
2770 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2771 the menu entry, ACTION is the function to call on the widget when the
2772 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2773 widget as an argument, and returns non-nil if ACTION is valid on that
2774 widget. If FILTER is nil, ACTION is always valid.")
2776 (defun custom-variable-action (widget &optional event
)
2777 "Show the menu for `custom-variable' WIDGET.
2778 Optional EVENT is the location for the menu."
2779 (if (eq (widget-get widget
:custom-state
) 'hidden
)
2780 (custom-toggle-hide widget
)
2781 (unless (eq (widget-get widget
:custom-state
) 'modified
)
2782 (custom-variable-state-set widget
))
2783 (custom-redraw-magic widget
)
2784 (let* ((completion-ignore-case t
)
2785 (answer (widget-choose (concat "Operation on "
2786 (custom-unlispify-tag-name
2787 (widget-get widget
:value
)))
2788 (custom-menu-filter custom-variable-menu
2792 (funcall answer widget
)))))
2794 (defun custom-variable-edit (widget)
2795 "Edit value of WIDGET."
2796 (widget-put widget
:custom-state
'unknown
)
2797 (widget-put widget
:custom-form
'edit
)
2798 (custom-redraw widget
))
2800 (defun custom-variable-edit-lisp (widget)
2801 "Edit the Lisp representation of the value of WIDGET."
2802 (widget-put widget
:custom-state
'unknown
)
2803 (widget-put widget
:custom-form
'lisp
)
2804 (custom-redraw widget
))
2806 (defun custom-variable-set (widget)
2807 "Set the current value for the variable being edited by WIDGET."
2808 (let* ((form (widget-get widget
:custom-form
))
2809 (state (widget-get widget
:custom-state
))
2810 (child (car (widget-get widget
:children
)))
2811 (symbol (widget-value widget
))
2812 (set (or (get symbol
'custom-set
) 'set-default
))
2813 (comment-widget (widget-get widget
:comment-widget
))
2814 (comment (widget-value comment-widget
))
2816 (cond ((eq state
'hidden
)
2817 (error "Cannot set hidden variable"))
2818 ((setq val
(widget-apply child
:validate
))
2819 (goto-char (widget-get val
:from
))
2820 (error "%s" (widget-get val
:error
)))
2821 ((memq form
'(lisp mismatch
))
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
(eval (setq val
(widget-value child
))))
2830 (put symbol
'customized-value
(list val
))
2831 (put symbol
'variable-comment comment
)
2832 (put symbol
'customized-variable-comment comment
))
2834 (when (equal comment
"")
2836 ;; Make the comment invisible by hand if it's empty
2837 (custom-comment-hide comment-widget
))
2838 (custom-variable-backup-value widget
)
2839 (custom-push-theme 'theme-value symbol
'user
2840 'set
(custom-quote (widget-value child
)))
2841 (funcall set symbol
(setq val
(widget-value child
)))
2842 (put symbol
'customized-value
(list (custom-quote val
)))
2843 (put symbol
'variable-comment comment
)
2844 (put symbol
'customized-variable-comment comment
)))
2845 (custom-variable-state-set widget
)
2846 (custom-redraw-magic widget
)))
2848 (defun custom-variable-mark-to-save (widget)
2849 "Set value and mark for saving the variable edited by WIDGET."
2850 (let* ((form (widget-get widget
:custom-form
))
2851 (state (widget-get widget
:custom-state
))
2852 (child (car (widget-get widget
:children
)))
2853 (symbol (widget-value widget
))
2854 (set (or (get symbol
'custom-set
) 'set-default
))
2855 (comment-widget (widget-get widget
:comment-widget
))
2856 (comment (widget-value comment-widget
))
2858 (cond ((eq state
'hidden
)
2859 (error "Cannot set hidden variable"))
2860 ((setq val
(widget-apply child
:validate
))
2861 (goto-char (widget-get val
:from
))
2862 (error "Saving %s: %s" symbol
(widget-get val
:error
)))
2863 ((memq form
'(lisp mismatch
))
2864 (when (equal comment
"")
2866 ;; Make the comment invisible by hand if it's empty
2867 (custom-comment-hide comment-widget
))
2868 (put symbol
'saved-value
(list (widget-value child
)))
2869 (custom-push-theme 'theme-value symbol
'user
2870 'set
(custom-quote (widget-value child
)))
2871 (funcall set symbol
(eval (widget-value child
)))
2872 (put symbol
'variable-comment comment
)
2873 (put symbol
'saved-variable-comment comment
))
2875 (when (equal comment
"")
2877 ;; Make the comment invisible by hand if it's empty
2878 (custom-comment-hide comment-widget
))
2879 (put symbol
'saved-value
2880 (list (custom-quote (widget-value child
))))
2881 (custom-push-theme 'theme-value symbol
'user
2882 'set
(custom-quote (widget-value child
)))
2883 (funcall set symbol
(widget-value child
))
2884 (put symbol
'variable-comment comment
)
2885 (put symbol
'saved-variable-comment comment
)))
2886 (put symbol
'customized-value nil
)
2887 (put symbol
'customized-variable-comment nil
)))
2889 (defsubst custom-variable-state-set-and-redraw
(widget)
2890 "Set state of variable widget WIDGET and redraw with current settings."
2891 (custom-variable-state-set widget
)
2892 (custom-redraw-magic widget
))
2894 (defun custom-variable-save (widget)
2895 "Save value of variable edited by widget WIDGET."
2896 (custom-variable-mark-to-save widget
)
2898 (custom-variable-state-set-and-redraw widget
))
2900 (defun custom-variable-reset-saved (widget)
2901 "Restore the saved value for the variable being edited by WIDGET.
2902 This also updates the buffer to show that value.
2903 The value that was current before this operation
2904 becomes the backup value, so you can get it again."
2905 (let* ((symbol (widget-value widget
))
2906 (set (or (get symbol
'custom-set
) 'set-default
))
2907 (value (get symbol
'saved-value
))
2908 (comment (get symbol
'saved-variable-comment
)))
2909 (cond ((or value comment
)
2910 (put symbol
'variable-comment comment
)
2911 (custom-variable-backup-value widget
)
2912 (custom-push-theme 'theme-value symbol
'user
'set
(car-safe value
))
2914 (funcall set symbol
(eval (car value
)))
2917 (error "No saved value for %s" symbol
)))
2918 (put symbol
'customized-value nil
)
2919 (put symbol
'customized-variable-comment nil
)
2920 (widget-put widget
:custom-state
'unknown
)
2921 ;; This call will possibly make the comment invisible
2922 (custom-redraw widget
)))
2924 (defun custom-variable-mark-to-reset-standard (widget)
2925 "Mark to restore standard setting for the variable edited by widget WIDGET.
2926 If `custom-reset-standard-variables-list' is nil, save, reset and
2927 redraw the widget immediately."
2928 (let* ((symbol (widget-value widget
)))
2929 (if (get symbol
'standard-value
)
2930 (custom-variable-backup-value widget
)
2931 (error "No standard setting known for %S" symbol
))
2932 (put symbol
'variable-comment nil
)
2933 (put symbol
'customized-value nil
)
2934 (put symbol
'customized-variable-comment nil
)
2935 (custom-push-theme 'theme-value symbol
'user
'reset
)
2936 (custom-theme-recalc-variable symbol
)
2937 (if (and custom-reset-standard-variables-list
2938 (or (get symbol
'saved-value
) (get symbol
'saved-variable-comment
)))
2940 (put symbol
'saved-value nil
)
2941 (put symbol
'saved-variable-comment nil
)
2942 ;; Append this to `custom-reset-standard-variables-list' to
2943 ;; have `custom-reset-standard-save-and-update' save setting
2944 ;; to the file, update the widget's state, and redraw it.
2945 (setq custom-reset-standard-variables-list
2946 (cons widget custom-reset-standard-variables-list
)))
2947 (when (or (get symbol
'saved-value
) (get symbol
'saved-variable-comment
))
2948 (put symbol
'saved-value nil
)
2949 (put symbol
'saved-variable-comment nil
)
2951 (widget-put widget
:custom-state
'unknown
)
2952 ;; This call will possibly make the comment invisible
2953 (custom-redraw widget
))))
2955 (defun custom-variable-reset-standard (widget)
2956 "Restore standard setting for the variable edited by WIDGET.
2957 This operation eliminates any saved setting for the variable,
2958 restoring it to the state of a variable that has never been customized.
2959 The value that was current before this operation
2960 becomes the backup value, so you can get it again."
2961 (let (custom-reset-standard-variables-list)
2962 (custom-variable-mark-to-reset-standard widget
)))
2964 (defun custom-variable-backup-value (widget)
2965 "Back up the current value for WIDGET's variable.
2966 The backup value is kept in the car of the `backup-value' property."
2967 (let* ((symbol (widget-value widget
))
2968 (get (or (get symbol
'custom-get
) 'default-value
))
2969 (type (custom-variable-type symbol
))
2970 (conv (widget-convert type
))
2971 (value (if (default-boundp symbol
)
2972 (funcall get symbol
)
2973 (widget-get conv
:value
))))
2974 (put symbol
'backup-value
(list value
))))
2976 (defun custom-variable-reset-backup (widget)
2977 "Restore the backup value for the variable being edited by WIDGET.
2978 The value that was current before this operation
2979 becomes the backup value, so you can use this operation repeatedly
2980 to switch between two values."
2981 (let* ((symbol (widget-value widget
))
2982 (set (or (get symbol
'custom-set
) 'set-default
))
2983 (value (get symbol
'backup-value
))
2984 (comment-widget (widget-get widget
:comment-widget
))
2985 (comment (widget-value comment-widget
)))
2988 (custom-variable-backup-value widget
)
2989 (custom-push-theme 'theme-value symbol
'user
'set value
)
2991 (funcall set symbol
(car value
))
2993 (error "No backup value for %s" symbol
))
2994 (put symbol
'customized-value
(list (car value
)))
2995 (put symbol
'variable-comment comment
)
2996 (put symbol
'customized-variable-comment comment
)
2997 (custom-variable-state-set widget
)
2998 ;; This call will possibly make the comment invisible
2999 (custom-redraw widget
)))
3001 ;;; The `custom-visibility' Widget
3003 (define-widget 'custom-visibility
'visibility
3004 "Show or hide a documentation string."
3005 :button-face
'custom-visibility
3006 :pressed-face
'custom-visibility
3007 :mouse-face
'highlight
3008 :pressed-face
'highlight
3012 (defface custom-visibility
3013 '((t :height
0.8 :inherit link
))
3014 "Face for the `custom-visibility' widget."
3016 :group
'custom-faces
)
3018 ;;; The `custom-face-edit' Widget.
3020 (define-widget 'custom-face-edit
'checklist
3021 "Edit face attributes."
3025 :button-args
'(:help-echo
"Control whether this attribute has any effect.")
3026 :value-to-internal
'custom-face-edit-fix-value
3027 :match
(lambda (widget value
)
3028 (widget-checklist-match widget
3029 (custom-face-edit-fix-value widget value
)))
3030 :convert-widget
'custom-face-edit-convert-widget
3031 :args
(mapcar (lambda (att)
3034 :sibling-args
(widget-get (nth 1 att
) :sibling-args
)
3035 (list 'const
:format
"" :value
(nth 0 att
))
3037 custom-face-attributes
))
3039 (defun custom-face-edit-fix-value (widget value
)
3040 "Ignoring WIDGET, convert :bold and :italic in VALUE to new form.
3041 Also change :reverse-video to :inverse-video."
3045 (let ((key (car value
))
3046 (val (car (cdr value
))))
3047 (cond ((eq key
:italic
)
3048 (push :slant result
)
3049 (push (if val
'italic
'normal
) result
))
3051 (push :weight result
)
3052 (push (if val
'bold
'normal
) result
))
3053 ((eq key
:reverse-video
)
3054 (push :inverse-video result
)
3058 (push val result
))))
3059 (setq value
(cdr (cdr value
))))
3060 (setq result
(nreverse result
))
3064 (defun custom-face-edit-convert-widget (widget)
3065 "Convert :args as widget types in WIDGET."
3068 :args
(mapcar (lambda (arg)
3070 :deactivate
'custom-face-edit-deactivate
3071 :activate
'custom-face-edit-activate
3072 :delete
'custom-face-edit-delete
))
3073 (widget-get widget
:args
)))
3076 (defun custom-face-edit-deactivate (widget)
3077 "Make face widget WIDGET inactive for user modifications."
3078 (unless (widget-get widget
:inactive
)
3079 (let ((tag (custom-face-edit-attribute-tag widget
))
3080 (from (copy-marker (widget-get widget
:from
)))
3081 (value (widget-value widget
))
3082 (inhibit-read-only t
)
3083 (inhibit-modification-hooks t
))
3086 (widget-default-delete widget
)
3087 (insert tag
": *\n")
3088 (widget-put widget
:inactive
3089 (cons value
(cons from
(- (point) from
))))))))
3091 (defun custom-face-edit-activate (widget)
3092 "Make face widget WIDGET active for user modifications."
3093 (let ((inactive (widget-get widget
:inactive
))
3094 (inhibit-read-only t
)
3095 (inhibit-modification-hooks t
))
3096 (when (consp inactive
)
3098 (goto-char (car (cdr inactive
)))
3099 (delete-region (point) (+ (point) (cdr (cdr inactive
))))
3100 (widget-put widget
:inactive nil
)
3101 (widget-apply widget
:create
)
3102 (widget-value-set widget
(car inactive
))
3105 (defun custom-face-edit-delete (widget)
3106 "Remove WIDGET from the buffer."
3107 (let ((inactive (widget-get widget
:inactive
))
3108 (inhibit-read-only t
)
3109 (inhibit-modification-hooks t
))
3111 ;; Widget is alive, we don't have to do anything special
3112 (widget-default-delete widget
)
3113 ;; WIDGET is already deleted because we did so to inactivate it;
3114 ;; now just get rid of the label we put in its place.
3115 (delete-region (car (cdr inactive
))
3116 (+ (car (cdr inactive
)) (cdr (cdr inactive
))))
3117 (widget-put widget
:inactive nil
))))
3120 (defun custom-face-edit-attribute-tag (widget)
3121 "Return the first :tag property in WIDGET or one of its children."
3122 (let ((tag (widget-get widget
:tag
)))
3123 (or (and (not (equal tag
"")) tag
)
3124 (let ((children (widget-get widget
:children
)))
3125 (while (and (null tag
) children
)
3126 (setq tag
(custom-face-edit-attribute-tag (pop children
))))
3129 ;;; The `custom-display' Widget.
3131 (define-widget 'custom-display
'menu-choice
3132 "Select a display type."
3135 :help-echo
"Specify frames where the face attributes should be used."
3136 :args
'((const :tag
"all" t
)
3137 (const :tag
"defaults" default
)
3141 :args
((group :sibling-args
(:help-echo
"\
3142 Only match the specified window systems.")
3143 (const :format
"Type: "
3145 (checklist :inline t
3148 :sibling-args
(:help-echo
"\
3149 The X11 Window System.")
3151 (const :format
"PM "
3152 :sibling-args
(:help-echo
"\
3153 OS/2 Presentation Manager.")
3155 (const :format
"W32 "
3156 :sibling-args
(:help-echo
"\
3159 (const :format
"NS "
3160 :sibling-args
(:help-echo
"\
3161 GNUstep or Macintosh OS Cocoa interface.")
3163 (const :format
"DOS "
3164 :sibling-args
(:help-echo
"\
3167 (const :format
"TTY%n"
3168 :sibling-args
(:help-echo
"\
3169 Plain text terminals.")
3171 (group :sibling-args
(:help-echo
"\
3172 Only match the frames with the specified color support.")
3173 (const :format
"Class: "
3175 (checklist :inline t
3177 (const :format
"Color "
3178 :sibling-args
(:help-echo
"\
3179 Match color frames.")
3181 (const :format
"Grayscale "
3182 :sibling-args
(:help-echo
"\
3183 Match grayscale frames.")
3185 (const :format
"Monochrome%n"
3186 :sibling-args
(:help-echo
"\
3187 Match frames with no color support.")
3189 (group :sibling-args
(:help-echo
"\
3190 The minimum number of colors the frame should support.")
3191 (const :format
"" min-colors
)
3192 (integer :tag
"Minimum number of colors" ))
3193 (group :sibling-args
(:help-echo
"\
3194 Only match frames with the specified intensity.")
3196 Background brightness: "
3198 (checklist :inline t
3200 (const :format
"Light "
3201 :sibling-args
(:help-echo
"\
3202 Match frames with light backgrounds.")
3204 (const :format
"Dark\n"
3205 :sibling-args
(:help-echo
"\
3206 Match frames with dark backgrounds.")
3208 (group :sibling-args
(:help-echo
"\
3209 Only match frames that support the specified face attributes.")
3210 (const :format
"Supports attributes:" supports
)
3211 (custom-face-edit :inline t
:format
"%n%v"))))))
3213 ;;; The `custom-face' Widget.
3215 (defface custom-face-tag
3216 `((t :inherit custom-variable-tag
))
3217 "Face used for face tags."
3218 :group
'custom-faces
)
3219 (define-obsolete-face-alias 'custom-face-tag-face
'custom-face-tag
"22.1")
3221 (defcustom custom-face-default-form
'selected
3222 "Default form of displaying face definition."
3223 :type
'(choice (const all
)
3226 :group
'custom-buffer
3229 (define-widget 'custom-face
'custom
3231 :sample-face
'custom-face-tag
3232 :help-echo
"Set or reset this face."
3233 :documentation-property
#'face-doc-string
3234 :value-create
'custom-face-value-create
3235 :action
'custom-face-action
3236 :custom-category
'face
3237 :custom-form nil
; defaults to value of `custom-face-default-form'
3238 :custom-set
'custom-face-set
3239 :custom-mark-to-save
'custom-face-mark-to-save
3240 :custom-reset-current
'custom-redraw
3241 :custom-reset-saved
'custom-face-reset-saved
3242 :custom-reset-standard
'custom-face-reset-standard
3243 :custom-mark-to-reset-standard
'custom-face-mark-to-reset-standard
3244 :custom-standard-value
'custom-face-standard-value
3245 :custom-state-set-and-redraw
'custom-face-state-set-and-redraw
3246 :custom-menu
'custom-face-menu-create
)
3248 (define-widget 'custom-face-all
'editable-list
3249 "An editable list of display specifications and attributes."
3250 :entry-format
"%i %d %v"
3251 :insert-button-args
'(:help-echo
"Insert new display specification here.")
3252 :append-button-args
'(:help-echo
"Append new display specification here.")
3253 :delete-button-args
'(:help-echo
"Delete this display specification.")
3254 :args
'((group :format
"%v" custom-display custom-face-edit
)))
3256 (defconst custom-face-all
(widget-convert 'custom-face-all
)
3257 "Converted version of the `custom-face-all' widget.")
3259 (define-widget 'custom-display-unselected
'item
3260 "A display specification that doesn't match the selected display."
3261 :match
'custom-display-unselected-match
)
3263 (defun custom-display-unselected-match (widget value
)
3264 "Non-nil if VALUE is an unselected display specification."
3265 (not (face-spec-set-match-display value
(selected-frame))))
3267 (define-widget 'custom-face-selected
'group
3268 "Edit the attributes of the selected display in a face specification."
3269 :args
'((choice :inline t
3270 (group :tag
"With Defaults" :inline t
3271 (group (const :tag
"" default
)
3272 (custom-face-edit :tag
" Default\n Attributes"))
3275 (group custom-display-unselected sexp
))
3276 (group (sexp :format
"")
3277 (custom-face-edit :tag
" Overriding\n Attributes"))
3281 (group :tag
"No Defaults" :inline t
3284 (group custom-display-unselected sexp
))
3285 (group (sexp :format
"")
3286 (custom-face-edit :tag
"\n Attributes"))
3293 (defconst custom-face-selected
(widget-convert 'custom-face-selected
)
3294 "Converted version of the `custom-face-selected' widget.")
3296 (defun custom-filter-face-spec (spec filter-index
&optional default-filter
)
3297 "Return a canonicalized version of SPEC using.
3298 FILTER-INDEX is the index in the entry for each attribute in
3299 `custom-face-attributes' at which the appropriate filter function can be
3300 found, and DEFAULT-FILTER is the filter to apply for attributes that
3302 (mapcar (lambda (entry)
3303 ;; Filter a single face-spec entry
3304 (let ((tests (car entry
))
3306 ;; Handle both old- and new-style attribute syntax
3307 (if (listp (car (cdr entry
)))
3310 (filtered-attrs nil
))
3311 ;; Filter each face attribute
3312 (while unfiltered-attrs
3313 (let* ((attr (pop unfiltered-attrs
))
3314 (pre-filtered-value (pop unfiltered-attrs
))
3316 (or (nth filter-index
(assq attr custom-face-attributes
))
3320 (funcall filter pre-filtered-value
)
3321 pre-filtered-value
)))
3322 (push filtered-value filtered-attrs
)
3323 (push attr filtered-attrs
)))
3325 (list tests filtered-attrs
)))
3328 (defun custom-pre-filter-face-spec (spec)
3329 "Return SPEC changed as necessary for editing by the face customization widget.
3330 SPEC must be a full face spec."
3331 (custom-filter-face-spec spec
2))
3333 (defun custom-post-filter-face-spec (spec)
3334 "Return the customized SPEC in a form suitable for setting the face."
3335 (custom-filter-face-spec spec
3))
3337 (defun custom-face-value-create (widget)
3338 "Create a list of the display specifications for WIDGET."
3339 (let ((buttons (widget-get widget
:buttons
))
3341 (symbol (widget-get widget
:value
))
3342 (tag (widget-get widget
:tag
))
3343 (state (widget-get widget
:custom-state
))
3345 (is-last (widget-get widget
:custom-last
))
3346 (prefix (widget-get widget
:custom-prefix
)))
3348 (setq tag
(prin1-to-string symbol
)))
3349 (cond ((eq custom-buffer-style
'tree
)
3350 (insert prefix
(if is-last
" `--- " " |--- "))
3351 (push (widget-create-child-and-convert
3352 widget
'custom-browse-face-tag
)
3354 (insert " " tag
"\n")
3355 (widget-put widget
:buttons buttons
))
3358 (push (widget-create-child-and-convert
3359 widget
'custom-visibility
3360 :help-echo
"Hide or show this face."
3365 :action
'custom-toggle-parent
3366 (not (eq state
'hidden
)))
3371 (widget-specify-sample widget begin
(point))
3372 (if (eq custom-buffer-style
'face
)
3374 (if (string-match "face\\'" tag
)
3376 (insert " face: ")))
3378 (push (widget-create-child-and-convert widget
'item
3385 (let ((magic (widget-create-child-and-convert
3386 widget
'custom-magic nil
)))
3387 (widget-put widget
:custom-magic magic
)
3388 (push magic buttons
))
3390 (widget-put widget
:buttons buttons
)
3391 ;; Insert documentation.
3392 (widget-put widget
:documentation-indent
3)
3393 (widget-add-documentation-string-button
3394 widget
:visibility-widget
'custom-visibility
)
3396 ;; The comment field
3397 (unless (eq state
'hidden
)
3398 (let* ((comment (get symbol
'face-comment
))
3400 (widget-create-child-and-convert
3401 widget
'custom-comment
3403 :value
(or comment
""))))
3404 (widget-put widget
:comment-widget comment-widget
)
3405 (push comment-widget children
)))
3407 (unless (eq state
'hidden
)
3408 (when (eq (widget-get widget
:custom-level
) 1)
3409 (custom-add-parent-links widget
))
3410 (custom-add-see-also widget
))
3412 (unless (eq (preceding-char) ?
\n)
3414 (unless (eq state
'hidden
)
3415 (message "Creating face editor...")
3416 (custom-load-widget widget
)
3417 (unless (widget-get widget
:custom-form
)
3418 (widget-put widget
:custom-form custom-face-default-form
))
3419 (let* ((symbol (widget-value widget
))
3420 (spec (or (get symbol
'customized-face
)
3421 (get symbol
'saved-face
)
3422 (get symbol
'face-defface-spec
)
3423 ;; Attempt to construct it.
3424 (list (list t
(custom-face-attributes-get
3425 symbol
(selected-frame))))))
3426 (form (widget-get widget
:custom-form
))
3427 (indent (widget-get widget
:indent
))
3429 ;; If the user has changed this face in some other way,
3430 ;; edit it as the user has specified it.
3431 (if (not (face-spec-match-p symbol spec
(selected-frame)))
3432 (setq spec
(list (list t
(face-attr-construct symbol
(selected-frame))))))
3433 (setq spec
(custom-pre-filter-face-spec spec
))
3434 (setq edit
(widget-create-child-and-convert
3436 (cond ((and (eq form
'selected
)
3437 (widget-apply custom-face-selected
3439 (when indent
(insert-char ?\ indent
))
3440 'custom-face-selected
)
3441 ((and (not (eq form
'lisp
))
3442 (widget-apply custom-face-all
3446 (when indent
(insert-char ?\ indent
))
3449 (custom-face-state-set widget
)
3450 (push edit children
)
3451 (widget-put widget
:children children
))
3452 (message "Creating face editor...done"))))))
3454 (defvar custom-face-menu
3455 `(("Set for Current Session" custom-face-set
)
3456 ,@(when (or custom-file init-file-user
)
3457 '(("Save for Future Sessions" custom-face-save
)))
3458 ("Undo Edits" custom-redraw
3460 (memq (widget-get widget
:custom-state
) '(modified changed
))))
3461 ("Reset to Saved" custom-face-reset-saved
3463 (or (get (widget-value widget
) 'saved-face
)
3464 (get (widget-value widget
) 'saved-face-comment
))))
3465 ,@(when (or custom-file init-file-user
)
3466 '(("Erase Customization" custom-face-reset-standard
3468 (get (widget-value widget
) 'face-defface-spec
)))))
3469 ("---" ignore ignore
)
3470 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
3471 ("---" ignore ignore
)
3472 ("For Current Display" custom-face-edit-selected
3474 (not (eq (widget-get widget
:custom-form
) 'selected
))))
3475 ("For All Kinds of Displays" custom-face-edit-all
3477 (not (eq (widget-get widget
:custom-form
) 'all
))))
3478 ("Show Lisp Expression" custom-face-edit-lisp
3480 (not (eq (widget-get widget
:custom-form
) 'lisp
)))))
3481 "Alist of actions for the `custom-face' widget.
3482 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3483 the menu entry, ACTION is the function to call on the widget when the
3484 menu is selected, and FILTER is a predicate which takes a `custom-face'
3485 widget as an argument, and returns non-nil if ACTION is valid on that
3486 widget. If FILTER is nil, ACTION is always valid.")
3488 (defun custom-face-edit-selected (widget)
3489 "Edit selected attributes of the value of WIDGET."
3490 (widget-put widget
:custom-state
'unknown
)
3491 (widget-put widget
:custom-form
'selected
)
3492 (custom-redraw widget
))
3494 (defun custom-face-edit-all (widget)
3495 "Edit all attributes of the value of WIDGET."
3496 (widget-put widget
:custom-state
'unknown
)
3497 (widget-put widget
:custom-form
'all
)
3498 (custom-redraw widget
))
3500 (defun custom-face-edit-lisp (widget)
3501 "Edit the Lisp representation of the value of WIDGET."
3502 (widget-put widget
:custom-state
'unknown
)
3503 (widget-put widget
:custom-form
'lisp
)
3504 (custom-redraw widget
))
3506 (defun custom-face-state-set (widget)
3507 "Set the state of WIDGET."
3508 (let* ((symbol (widget-value widget
))
3509 (comment (get symbol
'face-comment
))
3513 (setq tmp
(get symbol
'customized-face
))
3514 (setq temp
(get symbol
'customized-face-comment
))
3516 (if (equal temp comment
)
3520 (setq tmp
(get symbol
'saved-face
))
3521 (setq temp
(get symbol
'saved-face-comment
))
3523 (if (equal temp comment
)
3525 ((eq 'user
(caar (get symbol
'theme-face
)))
3527 ((eq 'changed
(caar (get symbol
'theme-face
)))
3531 ((get symbol
'face-defface-spec
)
3532 (if (equal comment nil
)
3537 ;; If the user called set-face-attribute to change the default
3538 ;; for new frames, this face is "set outside of Customize".
3539 (if (and (not (eq state
'rogue
))
3540 (get symbol
'face-modified
))
3541 (setq state
'changed
))
3542 (widget-put widget
:custom-state state
)))
3544 (defun custom-face-action (widget &optional event
)
3545 "Show the menu for `custom-face' WIDGET.
3546 Optional EVENT is the location for the menu."
3547 (if (eq (widget-get widget
:custom-state
) 'hidden
)
3548 (custom-toggle-hide widget
)
3549 (let* ((completion-ignore-case t
)
3550 (symbol (widget-get widget
:value
))
3551 (answer (widget-choose (concat "Operation on "
3552 (custom-unlispify-tag-name symbol
))
3553 (custom-menu-filter custom-face-menu
3557 (funcall answer widget
)))))
3559 (defun custom-face-set (widget)
3560 "Make the face attributes in WIDGET take effect."
3561 (let* ((symbol (widget-value widget
))
3562 (child (car (widget-get widget
:children
)))
3563 (value (custom-post-filter-face-spec (widget-value child
)))
3564 (comment-widget (widget-get widget
:comment-widget
))
3565 (comment (widget-value comment-widget
)))
3566 (when (equal comment
"")
3568 ;; Make the comment invisible by hand if it's empty
3569 (custom-comment-hide comment-widget
))
3570 (put symbol
'customized-face value
)
3571 (custom-push-theme 'theme-face symbol
'user
'set value
)
3572 (if (face-spec-choose value
)
3573 (face-spec-set symbol value t
)
3574 ;; face-set-spec ignores empty attribute lists, so just give it
3575 ;; something harmless instead.
3576 (face-spec-set symbol
'((t :foreground unspecified
)) t
))
3577 (put symbol
'customized-face-comment comment
)
3578 (put symbol
'face-comment comment
)
3579 (custom-face-state-set widget
)
3580 (custom-redraw-magic widget
)))
3582 (defun custom-face-mark-to-save (widget)
3583 "Mark for saving the face edited by WIDGET."
3584 (let* ((symbol (widget-value widget
))
3585 (child (car (widget-get widget
:children
)))
3586 (value (custom-post-filter-face-spec (widget-value child
)))
3587 (comment-widget (widget-get widget
:comment-widget
))
3588 (comment (widget-value comment-widget
)))
3589 (when (equal comment
"")
3591 ;; Make the comment invisible by hand if it's empty
3592 (custom-comment-hide comment-widget
))
3593 (custom-push-theme 'theme-face symbol
'user
'set value
)
3594 (if (face-spec-choose value
)
3595 (face-spec-set symbol value t
)
3596 ;; face-set-spec ignores empty attribute lists, so just give it
3597 ;; something harmless instead.
3598 (face-spec-set symbol
'((t :foreground unspecified
)) t
))
3599 (unless (eq (widget-get widget
:custom-state
) 'standard
)
3600 (put symbol
'saved-face value
))
3601 (put symbol
'customized-face nil
)
3602 (put symbol
'face-comment comment
)
3603 (put symbol
'customized-face-comment nil
)
3604 (put symbol
'saved-face-comment comment
)))
3606 (defsubst custom-face-state-set-and-redraw
(widget)
3607 "Set state of face widget WIDGET and redraw with current settings."
3608 (custom-face-state-set widget
)
3609 (custom-redraw-magic widget
))
3611 (defun custom-face-save (widget)
3612 "Save the face edited by WIDGET."
3613 (custom-face-mark-to-save widget
)
3615 (custom-face-state-set-and-redraw widget
))
3617 ;; For backward compatibility.
3618 (define-obsolete-function-alias 'custom-face-save-command
'custom-face-save
3621 (defun custom-face-reset-saved (widget)
3622 "Restore WIDGET to the face's default attributes."
3623 (let* ((symbol (widget-value widget
))
3624 (child (car (widget-get widget
:children
)))
3625 (value (get symbol
'saved-face
))
3626 (comment (get symbol
'saved-face-comment
))
3627 (comment-widget (widget-get widget
:comment-widget
)))
3628 (unless (or value comment
)
3629 (error "No saved value for this face"))
3630 (put symbol
'customized-face nil
)
3631 (put symbol
'customized-face-comment nil
)
3632 (custom-push-theme 'theme-face symbol
'user
'set value
)
3633 (face-spec-set symbol value t
)
3634 (put symbol
'face-comment comment
)
3635 (widget-value-set child value
)
3636 ;; This call manages the comment visibility
3637 (widget-value-set comment-widget
(or comment
""))
3638 (custom-face-state-set widget
)
3639 (custom-redraw-magic widget
)))
3641 (defun custom-face-standard-value (widget)
3642 (get (widget-value widget
) 'face-defface-spec
))
3644 (defun custom-face-mark-to-reset-standard (widget)
3645 "Restore widget WIDGET to the face's standard attribute values.
3646 If `custom-reset-standard-faces-list' is nil, save, reset and
3647 redraw the widget immediately."
3648 (let* ((symbol (widget-value widget
))
3649 (child (car (widget-get widget
:children
)))
3650 (value (get symbol
'face-defface-spec
))
3651 (comment-widget (widget-get widget
:comment-widget
)))
3653 (error "No standard setting for this face"))
3654 (put symbol
'customized-face nil
)
3655 (put symbol
'customized-face-comment nil
)
3656 (custom-push-theme 'theme-face symbol
'user
'reset
)
3657 (face-spec-set symbol value t
)
3658 (custom-theme-recalc-face symbol
)
3659 (if (and custom-reset-standard-faces-list
3660 (or (get symbol
'saved-face
) (get symbol
'saved-face-comment
)))
3663 (put symbol
'saved-face nil
)
3664 (put symbol
'saved-face-comment nil
)
3665 ;; Append this to `custom-reset-standard-faces-list' and have
3666 ;; `custom-reset-standard-save-and-update' save setting to the
3667 ;; file, update the widget's state, and redraw it.
3668 (setq custom-reset-standard-faces-list
3669 (cons widget custom-reset-standard-faces-list
)))
3670 (when (or (get symbol
'saved-face
) (get symbol
'saved-face-comment
))
3671 (put symbol
'saved-face nil
)
3672 (put symbol
'saved-face-comment nil
)
3674 (put symbol
'face-comment nil
)
3675 (widget-value-set child
3676 (custom-pre-filter-face-spec
3677 (list (list t
(custom-face-attributes-get
3679 ;; This call manages the comment visibility
3680 (widget-value-set comment-widget
"")
3681 (custom-face-state-set widget
)
3682 (custom-redraw-magic widget
))))
3684 (defun custom-face-reset-standard (widget)
3685 "Restore WIDGET to the face's standard attribute values.
3686 This operation eliminates any saved attributes for the face,
3687 restoring it to the state of a face that has never been customized."
3688 (let (custom-reset-standard-faces-list)
3689 (custom-face-mark-to-reset-standard widget
)))
3691 ;;; The `face' Widget.
3693 (defvar widget-face-prompt-value-history nil
3694 "History of input to `widget-face-prompt-value'.")
3696 (define-widget 'face
'symbol
3697 "A Lisp face name (with sample)."
3698 :format
"%{%t%}: (%{sample%}) %v"
3701 :sample-face-get
'widget-face-sample-face-get
3702 :notify
'widget-face-notify
3703 :match
(lambda (widget value
) (facep value
))
3704 :complete-function
(lambda ()
3706 (lisp-complete-symbol 'facep
))
3707 :prompt-match
'facep
3708 :prompt-history
'widget-face-prompt-value-history
3709 :validate
(lambda (widget)
3710 (unless (facep (widget-value widget
))
3712 :error
(format "Invalid face: %S"
3713 (widget-value widget
)))
3716 (defun widget-face-sample-face-get (widget)
3717 (let ((value (widget-value widget
)))
3722 (defun widget-face-notify (widget child
&optional event
)
3723 "Update the sample, and notify the parent."
3724 (overlay-put (widget-get widget
:sample-overlay
)
3725 'face
(widget-apply widget
:sample-face-get
))
3726 (widget-default-notify widget child event
))
3729 ;;; The `hook' Widget.
3731 (define-widget 'hook
'list
3732 "An Emacs Lisp hook."
3733 :value-to-internal
(lambda (widget value
)
3734 (if (and value
(symbolp value
))
3737 :match
(lambda (widget value
)
3739 (widget-group-match widget value
)))
3740 ;; Avoid adding undefined functions to the hook, especially for
3741 ;; things like `find-file-hook' or even more basic ones, to avoid
3743 :set
(lambda (symbol value
)
3746 (add-hook symbol elt
))))
3747 :convert-widget
'custom-hook-convert-widget
3750 (defun custom-hook-convert-widget (widget)
3751 ;; Handle `:options'.
3752 (let* ((options (widget-get widget
:options
))
3753 (other `(editable-list :inline t
3754 :entry-format
"%i %d%v"
3755 (function :format
" %v")))
3757 (list `(checklist :inline t
3758 ,@(mapcar (lambda (entry)
3759 `(function-item ,entry
))
3763 (widget-put widget
:args args
)
3766 ;;; The `custom-group-link' Widget.
3768 (define-widget 'custom-group-link
'link
3769 "Show parent in other window when activated."
3770 :button-face
'custom-link
3771 :mouse-face
'highlight
3772 :pressed-face
'highlight
3773 :help-echo
"Create customization buffer for this group."
3774 :keymap custom-mode-link-map
3775 :follow-link
'mouse-face
3776 :action
'custom-group-link-action
)
3778 (defun custom-group-link-action (widget &rest ignore
)
3779 (customize-group (widget-value widget
)))
3781 ;;; The `custom-group' Widget.
3783 (defcustom custom-group-tag-faces nil
3784 ;; In XEmacs, this ought to play games with font size.
3785 ;; Fixme: make it do so in Emacs.
3786 "Face used for group tags.
3787 The first member is used for level 1 groups, the second for level 2,
3788 and so forth. The remaining group tags are shown with `custom-group-tag'."
3789 :type
'(repeat face
)
3790 :group
'custom-faces
)
3792 (defface custom-group-tag-1
3795 (:foreground
"pink" :weight bold
:height
1.2 :inherit variable-pitch
))
3796 (((min-colors 88) (class color
)
3798 (:foreground
"red1" :weight bold
:height
1.2 :inherit variable-pitch
))
3801 (:foreground
"red" :weight bold
:height
1.2 :inherit variable-pitch
))
3803 "Face used for group tags."
3804 :group
'custom-faces
)
3805 (define-obsolete-face-alias 'custom-group-tag-face-1
'custom-group-tag-1
"22.1")
3807 (defface custom-group-tag
3810 (:foreground
"light blue" :weight bold
:height
1.2 :inherit variable-pitch
))
3811 (((min-colors 88) (class color
)
3813 (:foreground
"blue1" :weight bold
:height
1.2 :inherit variable-pitch
))
3816 (:foreground
"blue" :weight bold
:height
1.2 :inherit variable-pitch
))
3818 "Face used for low level group tags."
3819 :group
'custom-faces
)
3820 (define-obsolete-face-alias 'custom-group-tag-face
'custom-group-tag
"22.1")
3822 (define-widget 'custom-group
'custom
3825 :sample-face-get
'custom-group-sample-face-get
3826 :documentation-property
'group-documentation
3827 :help-echo
"Set or reset all members of this group."
3828 :value-create
'custom-group-value-create
3829 :action
'custom-group-action
3830 :custom-category
'group
3831 :custom-set
'custom-group-set
3832 :custom-mark-to-save
'custom-group-mark-to-save
3833 :custom-reset-current
'custom-group-reset-current
3834 :custom-reset-saved
'custom-group-reset-saved
3835 :custom-reset-standard
'custom-group-reset-standard
3836 :custom-mark-to-reset-standard
'custom-group-mark-to-reset-standard
3837 :custom-state-set-and-redraw
'custom-group-state-set-and-redraw
3838 :custom-menu
'custom-group-menu-create
)
3840 (defun custom-group-sample-face-get (widget)
3841 ;; Use :sample-face.
3842 (or (nth (1- (widget-get widget
:custom-level
)) custom-group-tag-faces
)
3845 (define-widget 'custom-group-visibility
'visibility
3846 "An indicator and manipulator for hidden group contents."
3847 :create
'custom-group-visibility-create
)
3849 (defun custom-group-visibility-create (widget)
3850 (let ((visible (widget-value widget
)))
3852 (insert "--------")))
3853 (widget-default-create widget
))
3855 (defun custom-group-members (symbol groups-only
)
3856 "Return SYMBOL's custom group members.
3857 If GROUPS-ONLY non-nil, return only those members that are groups."
3858 (if (not groups-only
)
3859 (get symbol
'custom-group
)
3861 (dolist (entry (get symbol
'custom-group
))
3862 (when (eq (nth 1 entry
) 'custom-group
)
3863 (push entry members
)))
3864 (nreverse members
))))
3866 (defun custom-group-value-create (widget)
3867 "Insert a customize group for WIDGET in the current buffer."
3868 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
3869 (custom-load-widget widget
))
3870 (let* ((state (widget-get widget
:custom-state
))
3871 (level (widget-get widget
:custom-level
))
3872 ;; (indent (widget-get widget :indent))
3873 (prefix (widget-get widget
:custom-prefix
))
3874 (buttons (widget-get widget
:buttons
))
3875 (tag (widget-get widget
:tag
))
3876 (symbol (widget-value widget
))
3877 (members (custom-group-members symbol
3878 (and (eq custom-buffer-style
'tree
)
3879 custom-browse-only-groups
)))
3880 (doc (widget-docstring widget
)))
3881 (cond ((and (eq custom-buffer-style
'tree
)
3883 (or members
(custom-unloaded-widget-p widget
)))
3884 (custom-browse-insert-prefix prefix
)
3885 (push (widget-create-child-and-convert
3886 widget
'custom-browse-visibility
3887 ;; :tag-glyph "plus"
3891 ;; (widget-glyph-insert nil "-- " "horizontal")
3892 (push (widget-create-child-and-convert
3893 widget
'custom-browse-group-tag
)
3895 (insert " " tag
"\n")
3896 (widget-put widget
:buttons buttons
))
3897 ((and (eq custom-buffer-style
'tree
)
3898 (zerop (length members
)))
3899 (custom-browse-insert-prefix prefix
)
3901 ;; (widget-glyph-insert nil "[ ]" "empty")
3902 ;; (widget-glyph-insert nil "-- " "horizontal")
3903 (push (widget-create-child-and-convert
3904 widget
'custom-browse-group-tag
)
3906 (insert " " tag
"\n")
3907 (widget-put widget
:buttons buttons
))
3908 ((eq custom-buffer-style
'tree
)
3909 (custom-browse-insert-prefix prefix
)
3910 (if (zerop (length members
))
3912 (custom-browse-insert-prefix prefix
)
3914 ;; (widget-glyph-insert nil "[ ]" "empty")
3915 ;; (widget-glyph-insert nil "-- " "horizontal")
3916 (push (widget-create-child-and-convert
3917 widget
'custom-browse-group-tag
)
3919 (insert " " tag
"\n")
3920 (widget-put widget
:buttons buttons
))
3921 (push (widget-create-child-and-convert
3922 widget
'custom-browse-visibility
3923 ;; :tag-glyph "minus"
3927 ;; (widget-glyph-insert nil "-\\ " "top")
3928 (push (widget-create-child-and-convert
3929 widget
'custom-browse-group-tag
)
3931 (insert " " tag
"\n")
3932 (widget-put widget
:buttons buttons
)
3933 (message "Creating group...")
3934 (let* ((members (custom-sort-items
3936 ;; Never sort the top-level custom group.
3937 (unless (eq symbol
'emacs
)
3938 custom-browse-sort-alphabetically
)
3939 custom-browse-order-groups
))
3940 (prefixes (widget-get widget
:custom-prefixes
))
3941 (custom-prefix-list (custom-prefix-add symbol prefixes
))
3942 (extra-prefix (if (widget-get widget
:custom-last
)
3945 (prefix (concat prefix extra-prefix
))
3948 (setq entry
(car members
)
3949 members
(cdr members
))
3950 (push (widget-create-child-and-convert
3951 widget
(nth 1 entry
)
3953 :tag
(custom-unlispify-tag-name (nth 0 entry
))
3954 :custom-prefixes custom-prefix-list
3955 :custom-level
(1+ level
)
3956 :custom-last
(null members
)
3957 :value
(nth 0 entry
)
3958 :custom-prefix prefix
)
3960 (widget-put widget
:children
(reverse children
)))
3961 (message "Creating group...done")))
3964 ;; Create level indicator.
3966 (if (eq custom-buffer-style
'links
)
3967 (push (widget-create-child-and-convert
3968 widget
'custom-group-link
3972 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3974 (push (widget-create-child-and-convert
3975 widget
'custom-group-visibility
3976 :help-echo
"Show members of this group."
3977 :action
'custom-toggle-parent
3978 (not (eq state
'hidden
)))
3981 ;; Create magic button.
3982 (let ((magic (widget-create-child-and-convert
3983 widget
'custom-magic nil
)))
3984 (widget-put widget
:custom-magic magic
)
3985 (push magic buttons
))
3987 (widget-put widget
:buttons buttons
)
3988 ;; Insert documentation.
3989 (if (and (eq custom-buffer-style
'links
) (> level
1))
3990 (widget-put widget
:documentation-indent
0))
3991 (widget-add-documentation-string-button
3992 widget
:visibility-widget
'custom-visibility
))
3996 ;; Draw a horizontal line (this works for both graphical
3997 ;; and text displays):
4000 (put-text-property p
(1+ p
) 'face
'(:underline t
))
4001 (overlay-put (make-overlay p
(1+ p
))
4003 (propertize "\n" 'face
'(:underline t
)
4004 'display
'(space :align-to
999))))
4006 ;; Add parent groups references above the group.
4008 (if (custom-add-parent-links widget
"Parent groups:")
4010 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
4012 (let ((start (point)))
4013 (insert tag
" group: ")
4014 (widget-specify-sample widget start
(point)))
4017 (insert " Group definition missing. "))
4018 ((< (length doc
) 50)
4020 ;; Create visibility indicator.
4021 (unless (eq custom-buffer-style
'links
)
4023 (push (widget-create-child-and-convert
4025 :help-echo
"Hide members of this group."
4026 :action
'custom-toggle-parent
4027 (not (eq state
'hidden
)))
4031 ;; Create magic button.
4032 (let ((magic (widget-create-child-and-convert
4033 widget
'custom-magic
4036 (widget-put widget
:custom-magic magic
)
4037 (push magic buttons
))
4039 (widget-put widget
:buttons buttons
)
4040 ;; Insert documentation.
4041 (when (and doc
(>= (length doc
) 50))
4042 (widget-add-documentation-string-button
4043 widget
:visibility-widget
'custom-visibility
))
4046 (if nil
;;; This should test that the buffer
4047 ;;; was not made to display a group.
4049 (insert-char ?\ custom-buffer-indent
)
4050 (custom-add-parent-links widget
)))
4051 (custom-add-see-also widget
4052 (make-string (* custom-buffer-indent level
)
4055 (message "Creating group...")
4056 (let* ((members (custom-sort-items
4058 ;; Never sort the top-level custom group.
4059 (unless (eq symbol
'emacs
)
4060 custom-buffer-sort-alphabetically
)
4061 custom-buffer-order-groups
))
4062 (prefixes (widget-get widget
:custom-prefixes
))
4063 (custom-prefix-list (custom-prefix-add symbol prefixes
))
4064 (len (length members
))
4066 (reporter (make-progress-reporter
4067 "Creating group entries..." 0 len
))
4072 (widget-insert "\n")
4073 (progress-reporter-update reporter
(setq count
(1+ count
)))
4074 (let ((sym (nth 0 entry
))
4075 (type (nth 1 entry
))
4078 (widget-create-child-and-convert
4081 :tag
(custom-unlispify-tag-name sym
)
4082 :custom-prefixes custom-prefix-list
4083 :custom-level
(1+ level
)
4085 (unless (eq (preceding-char) ?
\n)
4086 (widget-insert "\n")))))
4088 (mapc 'custom-magic-reset children
)
4089 (widget-put widget
:children children
)
4090 (custom-group-state-update widget
)
4091 (progress-reporter-done reporter
))
4095 (put-text-property p
(1+ p
) 'face
'(:underline t
))
4096 (overlay-put (make-overlay p
(1+ p
))
4098 (propertize "\n" 'face
'(:underline t
)
4099 'display
'(space :align-to
999))))))))
4101 (defvar custom-group-menu
4102 `(("Set for Current Session" custom-group-set
4104 (eq (widget-get widget
:custom-state
) 'modified
)))
4105 ,@(when (or custom-file init-file-user
)
4106 '(("Save for Future Sessions" custom-group-save
4108 (memq (widget-get widget
:custom-state
) '(modified set
))))))
4109 ("Undo Edits" custom-group-reset-current
4111 (memq (widget-get widget
:custom-state
) '(modified))))
4112 ("Reset to Saved" custom-group-reset-saved
4114 (memq (widget-get widget
:custom-state
) '(modified set
))))
4115 ,@(when (or custom-file init-file-user
)
4116 '(("Erase Customization" custom-group-reset-standard
4118 (memq (widget-get widget
:custom-state
) '(modified set saved
)))))))
4119 "Alist of actions for the `custom-group' widget.
4120 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
4121 the menu entry, ACTION is the function to call on the widget when the
4122 menu is selected, and FILTER is a predicate which takes a `custom-group'
4123 widget as an argument, and returns non-nil if ACTION is valid on that
4124 widget. If FILTER is nil, ACTION is always valid.")
4126 (defun custom-group-action (widget &optional event
)
4127 "Show the menu for `custom-group' WIDGET.
4128 Optional EVENT is the location for the menu."
4129 (if (eq (widget-get widget
:custom-state
) 'hidden
)
4130 (custom-toggle-hide widget
)
4131 (let* ((completion-ignore-case t
)
4132 (answer (widget-choose (concat "Operation on "
4133 (custom-unlispify-tag-name
4134 (widget-get widget
:value
)))
4135 (custom-menu-filter custom-group-menu
4139 (funcall answer widget
)))))
4141 (defun custom-group-set (widget)
4142 "Set changes in all modified group members."
4143 (dolist (child (widget-get widget
:children
))
4144 (when (eq (widget-get child
:custom-state
) 'modified
)
4145 (widget-apply child
:custom-set
))))
4147 (defun custom-group-mark-to-save (widget)
4148 "Mark all modified group members for saving."
4149 (dolist (child (widget-get widget
:children
))
4150 (when (memq (widget-get child
:custom-state
) '(modified set
))
4151 (widget-apply child
:custom-mark-to-save
))))
4153 (defsubst custom-group-state-set-and-redraw
(widget)
4154 "Set state of group widget WIDGET and redraw with current settings."
4155 (dolist (child (widget-get widget
:children
))
4156 (when (memq (widget-get child
:custom-state
) '(modified set
))
4157 (widget-apply child
:custom-state-set-and-redraw
))))
4159 (defun custom-group-save (widget)
4160 "Save all modified group members."
4161 (custom-group-mark-to-save widget
)
4163 (custom-group-state-set-and-redraw widget
))
4165 (defun custom-group-reset-current (widget)
4166 "Reset all modified group members."
4167 (dolist (child (widget-get widget
:children
))
4168 (when (eq (widget-get child
:custom-state
) 'modified
)
4169 (widget-apply child
:custom-reset-current
))))
4171 (defun custom-group-reset-saved (widget)
4172 "Reset all modified or set group members."
4173 (dolist (child (widget-get widget
:children
))
4174 (when (memq (widget-get child
:custom-state
) '(modified set
))
4175 (widget-apply child
:custom-reset-saved
))))
4177 (defun custom-group-reset-standard (widget)
4178 "Reset all modified, set, or saved group members."
4179 (let ((custom-reset-standard-variables-list '(t))
4180 (custom-reset-standard-faces-list '(t)))
4181 (custom-group-mark-to-reset-standard widget
)
4182 (custom-reset-standard-save-and-update)))
4184 (defun custom-group-mark-to-reset-standard (widget)
4185 "Mark to reset all modified, set, or saved group members."
4186 (dolist (child (widget-get widget
:children
))
4187 (when (memq (widget-get child
:custom-state
)
4188 '(modified set saved
))
4189 (widget-apply child
:custom-mark-to-reset-standard
))))
4191 (defun custom-group-state-update (widget)
4193 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
4194 (let* ((children (widget-get widget
:children
))
4195 (states (mapcar (lambda (child)
4196 (widget-get child
:custom-state
))
4198 (magics custom-magic-alist
)
4201 (let ((magic (car (car magics
))))
4202 (if (and (not (eq magic
'hidden
))
4203 (memq magic states
))
4206 (setq magics
(cdr magics
)))))
4207 (widget-put widget
:custom-state found
)))
4208 (custom-magic-reset widget
))
4210 ;;; Reading and writing the custom file.
4213 (defcustom custom-file nil
4214 "File used for storing customization information.
4215 The default is nil, which means to use your init file
4216 as specified by `user-init-file'. If the value is not nil,
4217 it should be an absolute file name.
4219 You can set this option through Custom, if you carefully read the
4220 last paragraph below. However, usually it is simpler to write
4221 something like the following in your init file:
4223 \(setq custom-file \"~/.emacs-custom.el\")
4226 Note that both lines are necessary: the first line tells Custom to
4227 save all customizations in this file, but does not load it.
4229 When you change this variable outside Custom, look in the
4230 previous custom file \(usually your init file) for the
4231 forms `(custom-set-variables ...)' and `(custom-set-faces ...)',
4232 and copy them (whichever ones you find) to the new custom file.
4233 This will preserve your existing customizations.
4235 If you save this option using Custom, Custom will write all
4236 currently saved customizations, including the new one for this
4237 option itself, into the file you specify, overwriting any
4238 `custom-set-variables' and `custom-set-faces' forms already
4239 present in that file. It will not delete any customizations from
4240 the old custom file. You should do that manually if that is what you
4241 want. You also have to put something like `\(load \"CUSTOM-FILE\")
4242 in your init file, where CUSTOM-FILE is the actual name of the
4243 file. Otherwise, Emacs will not load the file when it starts up,
4244 and hence will not set `custom-file' to that file either."
4245 :type
'(choice (const :tag
"Your Emacs init file" nil
)
4246 (file :format
"%t:%v%d"
4248 "Please read entire docstring below before setting \
4249 this through Custom.
4250 Click on \"More\" \(or position point there and press RETURN)
4251 if only the first line of the docstring is shown."))
4254 (defun custom-file ()
4255 "Return the file name for saving customizations."
4258 (let ((user-init-file user-init-file
)
4260 (if (eq system-type
'ms-dos
) "~/_emacs" "~/.emacs")))
4261 (when (null user-init-file
)
4262 (if (or (file-exists-p default-init-file
)
4263 (and (eq system-type
'windows-nt
)
4264 (file-exists-p "~/_emacs")))
4265 ;; Started with -q, i.e. the file containing
4266 ;; Custom settings hasn't been read. Saving
4267 ;; settings there would overwrite other settings.
4268 (error "Saving settings from \"emacs -q\" would overwrite existing customizations"))
4269 (setq user-init-file default-init-file
))
4272 ;; If recentf-mode is non-nil, this is defined.
4273 (declare-function recentf-expand-file-name
"recentf" (name))
4276 (defun custom-save-all ()
4277 "Save all customizations in `custom-file'."
4278 (when (and (null custom-file
) init-file-had-error
)
4279 (error "Cannot save customizations; init file was not fully loaded"))
4280 (let* ((filename (custom-file))
4285 (recentf-expand-file-name (custom-file)))
4288 (old-buffer (find-buffer-visiting filename
))
4291 (with-current-buffer (let ((find-file-visit-truename t
))
4292 (or old-buffer
(find-file-noselect filename
)))
4293 ;; We'll save using file-precious-flag, so avoid destroying
4294 ;; symlinks. (If we're not already visiting the buffer, this is
4295 ;; handled by find-file-visit-truename, above.)
4297 (setq old-buffer-name
(buffer-file-name))
4298 (set-visited-file-name (file-chase-links filename
)))
4300 (unless (eq major-mode
'emacs-lisp-mode
)
4302 (let ((inhibit-read-only t
))
4303 (custom-save-variables)
4304 (custom-save-faces))
4305 (let ((file-precious-flag t
))
4309 (set-visited-file-name old-buffer-name
)
4310 (set-buffer-modified-p nil
))
4311 (kill-buffer (current-buffer))))))
4314 (defun customize-save-customized ()
4315 "Save all user options which have been set in this session."
4317 (mapatoms (lambda (symbol)
4318 (let ((face (get symbol
'customized-face
))
4319 (value (get symbol
'customized-value
))
4320 (face-comment (get symbol
'customized-face-comment
))
4322 (get symbol
'customized-variable-comment
)))
4324 (put symbol
'saved-face face
)
4325 (custom-push-theme 'theme-face symbol
'user
'set value
)
4326 (put symbol
'customized-face nil
))
4328 (put symbol
'saved-value value
)
4329 (custom-push-theme 'theme-value symbol
'user
'set value
)
4330 (put symbol
'customized-value nil
))
4331 (when variable-comment
4332 (put symbol
'saved-variable-comment variable-comment
)
4333 (put symbol
'customized-variable-comment nil
))
4335 (put symbol
'saved-face-comment face-comment
)
4336 (put symbol
'customized-face-comment nil
)))))
4337 ;; We really should update all custom buffers here.
4340 ;; Editing the custom file contents in a buffer.
4342 (defun custom-save-delete (symbol)
4343 "Delete all calls to SYMBOL from the contents of the current buffer.
4344 Leave point at the old location of the first such call,
4345 or (if there were none) at the end of the buffer.
4347 This function does not save the buffer."
4348 (goto-char (point-min))
4349 ;; Skip all whitespace and comments.
4350 (while (forward-comment 1))
4352 (save-excursion (forward-sexp (buffer-size)))) ; Test for scan errors.
4355 (while t
;; We exit this loop only via throw.
4356 ;; Skip all whitespace and comments.
4357 (while (forward-comment 1))
4358 (let ((start (point))
4359 (sexp (condition-case nil
4360 (read (current-buffer))
4361 (end-of-file (throw 'found nil
)))))
4362 (when (and (listp sexp
)
4363 (eq (car sexp
) symbol
))
4364 (delete-region start
(point))
4366 (setq first
(point)))))))
4369 ;; Move in front of local variables, otherwise long Custom
4370 ;; entries would make them ineffective.
4371 (let ((pos (point-max))
4372 (case-fold-search t
))
4374 (goto-char (point-max))
4375 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
4377 (when (search-forward "Local Variables:" nil t
)
4378 (setq pos
(line-beginning-position))))
4381 (defun custom-save-variables ()
4382 "Save all customized variables in `custom-file'."
4384 (custom-save-delete 'custom-set-variables
)
4385 (let ((standard-output (current-buffer))
4386 (saved-list (make-list 1 0))
4388 ;; First create a sorted list of saved variables.
4391 (if (and (get symbol
'saved-value
)
4392 ;; ignore theme values
4393 (or (null (get symbol
'theme-value
))
4394 (eq 'user
(caar (get symbol
'theme-value
)))))
4395 (nconc saved-list
(list symbol
)))))
4396 (setq saved-list
(sort (cdr saved-list
) 'string
<))
4399 (princ "(custom-set-variables
4400 ;; custom-set-variables was added by Custom.
4401 ;; If you edit it by hand, you could mess it up, so be careful.
4402 ;; Your init file should contain only one such instance.
4403 ;; If there is more than one, they won't work right.\n")
4404 (dolist (symbol saved-list
)
4405 (let ((spec (car-safe (get symbol
'theme-value
)))
4406 (value (get symbol
'saved-value
))
4407 (requests (get symbol
'custom-requests
))
4408 (now (and (not (custom-variable-p symbol
))
4410 (eq (get symbol
'force-value
)
4412 (comment (get symbol
'saved-variable-comment
)))
4413 ;; Check REQUESTS for validity.
4414 (dolist (request requests
)
4415 (when (and (symbolp request
) (not (featurep request
)))
4416 (message "Unknown requested feature: %s" request
)
4417 (setq requests
(delq request requests
))))
4418 ;; Is there anything customized about this variable?
4419 (when (or (and spec
(eq (car spec
) 'user
))
4421 (and (null spec
) (get symbol
'saved-value
)))
4422 ;; Output an element for this variable.
4423 ;; It has the form (SYMBOL VALUE-FORM NOW REQUESTS COMMENT).
4424 ;; SYMBOL is the variable name.
4425 ;; VALUE-FORM is an expression to return the customized value.
4426 ;; NOW if non-nil means always set the variable immediately
4427 ;; when the customizations are reloaded. This is used
4428 ;; for rogue variables
4429 ;; REQUESTS is a list of packages to load before setting the
4430 ;; variable. Each element of it will be passed to `require'.
4431 ;; COMMENT is whatever comment the user has specified
4432 ;; with the customize facility.
4439 (when (or now requests comment
)
4442 (when (or requests comment
)
4452 (unless (looking-at "\n")
4455 (defun custom-save-faces ()
4456 "Save all customized faces in `custom-file'."
4458 (custom-save-delete 'custom-reset-faces
)
4459 (custom-save-delete 'custom-set-faces
)
4460 (let ((standard-output (current-buffer))
4461 (saved-list (make-list 1 0))
4463 ;; First create a sorted list of saved faces.
4466 (if (and (get symbol
'saved-face
)
4467 (eq 'user
(car (car-safe (get symbol
'theme-face
)))))
4468 (nconc saved-list
(list symbol
)))))
4469 (setq saved-list
(sort (cdr saved-list
) 'string
<))
4470 ;; The default face must be first, since it affects the others.
4471 (if (memq 'default saved-list
)
4472 (setq saved-list
(cons 'default
(delq 'default saved-list
))))
4475 (princ "(custom-set-faces
4476 ;; custom-set-faces was added by Custom.
4477 ;; If you edit it by hand, you could mess it up, so be careful.
4478 ;; Your init file should contain only one such instance.
4479 ;; If there is more than one, they won't work right.\n")
4480 (dolist (symbol saved-list
)
4481 (let ((spec (car-safe (get symbol
'theme-face
)))
4482 (value (get symbol
'saved-face
))
4483 (now (not (or (get symbol
'face-defface-spec
)
4484 (and (not (custom-facep symbol
))
4485 (not (get symbol
'force-face
))))))
4486 (comment (get symbol
'saved-face-comment
)))
4487 (when (or (and spec
(eq (nth 0 spec
) 'user
))
4489 (and (null spec
) (get symbol
'saved-face
)))
4490 ;; Don't print default face here.
4497 (when (or now comment
)
4507 (unless (looking-at "\n")
4510 ;;; The Customize Menu.
4514 (defcustom custom-menu-nesting
2
4515 "Maximum nesting in custom menus."
4517 :group
'custom-menu
)
4519 (defun custom-face-menu-create (widget symbol
)
4520 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
4521 (vector (custom-unlispify-menu-entry symbol
)
4522 `(customize-face ',symbol
)
4525 (defun custom-variable-menu-create (widget symbol
)
4526 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
4527 (let ((type (get symbol
'custom-type
)))
4528 (unless (listp type
)
4529 (setq type
(list type
)))
4530 (if (and type
(widget-get type
:custom-menu
))
4531 (widget-apply type
:custom-menu symbol
)
4532 (vector (custom-unlispify-menu-entry symbol
)
4533 `(customize-variable ',symbol
)
4536 ;; Add checkboxes to boolean variable entries.
4537 (widget-put (get 'boolean
'widget-type
)
4538 :custom-menu
(lambda (widget symbol
)
4539 (vector (custom-unlispify-menu-entry symbol
)
4540 `(customize-variable ',symbol
)
4542 ':selected symbol
)))
4544 (defun custom-group-menu-create (widget symbol
)
4545 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
4546 `( ,(custom-unlispify-menu-entry symbol t
)
4547 :filter
(lambda (&rest junk
)
4548 (let* ((menu (custom-menu-create ',symbol
)))
4549 (if (consp menu
) (cdr menu
) menu
)))))
4552 (defun custom-menu-create (symbol)
4553 "Create menu for customization group SYMBOL.
4554 The menu is in a format applicable to `easy-menu-define'."
4555 (let* ((deactivate-mark nil
)
4556 (item (vector (custom-unlispify-menu-entry symbol
)
4557 `(customize-group ',symbol
)
4559 (if (and (or (not (boundp 'custom-menu-nesting
))
4560 (>= custom-menu-nesting
0))
4562 (custom-load-symbol symbol
)
4563 (< (length (get symbol
'custom-group
)) widget-menu-max-size
)))
4564 (let ((custom-prefix-list (custom-prefix-add symbol
4565 custom-prefix-list
))
4566 (members (custom-sort-items (get symbol
'custom-group
)
4567 custom-menu-sort-alphabetically
4568 custom-menu-order-groups
)))
4569 `(,(custom-unlispify-menu-entry symbol t
)
4572 ,@(mapcar (lambda (entry)
4573 (widget-apply (if (listp (nth 1 entry
))
4575 (list (nth 1 entry
)))
4576 :custom-menu
(nth 0 entry
)))
4581 (defun customize-menu-create (symbol &optional name
)
4582 "Return a customize menu for customization group SYMBOL.
4583 If optional NAME is given, use that as the name of the menu.
4584 Otherwise the menu will be named `Customize'.
4585 The format is suitable for use with `easy-menu-define'."
4587 (setq name
"Customize"))
4589 :filter
(lambda (&rest junk
)
4590 (let ((menu (custom-menu-create ',symbol
)))
4591 (if (consp menu
) (cdr menu
) menu
)))))
4593 ;;; Toolbar and menubar support
4596 Custom-mode-menu
(list custom-mode-map custom-field-keymap
)
4597 "Menu used in customization buffers."
4598 (nconc (list "Custom"
4599 (customize-menu-create 'customize
))
4600 (mapcar (lambda (arg)
4601 (let ((tag (nth 0 arg
))
4602 (command (nth 1 arg
))
4603 (active (nth 2 arg
))
4605 (vector tag command
:active
(eval active
) :help help
)))
4608 (defvar tool-bar-map
)
4610 ;;; `custom-tool-bar-map' used to be set up here. This will fail to
4611 ;;; DTRT when `display-graphic-p' returns nil during compilation. Hence
4612 ;;; we set this up lazily in `Custom-mode'.
4613 (defvar custom-tool-bar-map nil
4614 "Keymap for toolbar in Custom mode.")
4616 ;;; The Custom Mode.
4618 (defun Custom-no-edit (pos &optional event
)
4619 "Invoke button at POS, or refuse to allow editing of Custom buffer."
4621 (error "You can't edit this part of the Custom buffer"))
4623 (defun Custom-newline (pos &optional event
)
4624 "Invoke button at POS, or refuse to allow editing of Custom buffer."
4626 (let ((button (get-char-property pos
'button
)))
4628 (widget-apply-action button event
)
4629 (error "You can't edit this part of the Custom buffer"))))
4631 (defun Custom-goto-parent ()
4632 "Go to the parent group listed at the top of this buffer.
4633 If several parents are listed, go to the first of them."
4636 (goto-char (point-min))
4637 (if (search-forward "\nParent groups: " nil t
)
4638 (let* ((button (get-char-property (point) 'button
))
4639 (parent (downcase (widget-get button
:tag
))))
4640 (customize-group parent
)))))
4642 (defcustom Custom-mode-hook nil
4643 "Hook called when entering Custom mode."
4645 :group
'custom-buffer
)
4647 (defun custom-state-buffer-message (widget)
4648 (if (eq (widget-get (widget-get widget
:parent
) :custom-state
) 'modified
)
4649 (message "To install your edits, invoke [State] and choose the Set operation")))
4651 (define-derived-mode Custom-mode nil
"Custom"
4652 "Major mode for editing customization buffers.
4654 The following commands are available:
4657 Move to next button, link or editable field. \\[widget-forward]
4658 Move to previous button, link or editable field. \\[widget-backward]
4659 \\<custom-field-keymap>\
4660 Complete content of editable text field. \\[widget-complete]
4661 \\<custom-mode-map>\
4662 Invoke button under the mouse pointer. \\[widget-button-click]
4663 Invoke button under point. \\[widget-button-press]
4664 Set all options from current text. \\[Custom-set]
4665 Make values in current text permanent. \\[Custom-save]
4666 Make text match actual option values. \\[Custom-reset-current]
4667 Reset options to permanent settings. \\[Custom-reset-saved]
4668 Erase customizations; set options
4669 and buffer text to the standard values. \\[Custom-reset-standard]
4671 Entry to this mode calls the value of `Custom-mode-hook'
4672 if that value is non-nil."
4673 (use-local-map custom-mode-map
)
4674 (easy-menu-add Custom-mode-menu
)
4675 (set (make-local-variable 'tool-bar-map
)
4676 (or custom-tool-bar-map
4677 ;; Set up `custom-tool-bar-map'.
4678 (let ((map (make-sparse-keymap)))
4681 (tool-bar-local-item-from-menu
4682 (nth 1 arg
) (nth 4 arg
) map custom-mode-map
))
4684 (setq custom-tool-bar-map map
))))
4685 (make-local-variable 'custom-options
)
4686 (make-local-variable 'custom-local-buffer
)
4687 (make-local-variable 'widget-documentation-face
)
4688 (setq widget-documentation-face
'custom-documentation
)
4689 (make-local-variable 'widget-button-face
)
4690 (setq widget-button-face custom-button
)
4691 (setq show-trailing-whitespace nil
)
4693 ;; We need this because of the "More" button on docstrings.
4694 ;; Otherwise clicking on "More" can push point offscreen, which
4695 ;; causes the window to recenter on point, which pushes the
4696 ;; newly-revealed docstring offscreen; which is annoying. -- cyd.
4697 (set (make-local-variable 'widget-button-click-moves-point
) t
)
4699 (set (make-local-variable 'widget-button-pressed-face
) custom-button-pressed
)
4700 (set (make-local-variable 'widget-mouse-face
) custom-button-mouse
)
4702 ;; When possible, use relief for buttons, not bracketing. This test
4703 ;; may not be optimal.
4704 (when custom-raised-buttons
4705 (set (make-local-variable 'widget-push-button-prefix
) "")
4706 (set (make-local-variable 'widget-push-button-suffix
) "")
4707 (set (make-local-variable 'widget-link-prefix
) "")
4708 (set (make-local-variable 'widget-link-suffix
) ""))
4709 (add-hook 'widget-edit-functions
'custom-state-buffer-message nil t
))
4711 (put 'Custom-mode
'mode-class
'special
)
4713 ;; backward-compatibility
4714 (defun custom-mode ()
4715 "Non-interactive variant of `Custom-mode'."
4717 (make-obsolete 'custom-mode
'Custom-mode
"23.1")
4718 (put 'custom-mode
'mode-class
'special
)
4719 (define-obsolete-variable-alias 'custom-mode-hook
'Custom-mode-hook
"23.1")
4722 '("^No user option defaults have been changed since Emacs "
4724 "^No \\(?:customized\\|rogue\\|saved\\) user options"
4725 "^No customizable items matching "
4726 "^There are unset changes"
4727 "^Cannot set hidden variable"
4728 "^No \\(?:saved\\|backup\\) value for "
4729 "^No standard setting known for "
4730 "^No standard setting for this face"
4731 "^Saving settings from \"emacs -q\" would overwrite existing customizations"))
4732 (add-to-list 'debug-ignored-errors regexp
))
4738 ;; arch-tag: 64533aa4-1b1a-48c3-8812-f9dc718e8a6f
4739 ;;; cus-edit.el ends here