1 ;;; cus-edit.el --- tools for customizing Emacs and Lisp packages
3 ;; Copyright (C) 1996, 1997, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
6 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
8 ;; Keywords: help, faces
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 3, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
29 ;; This file implements the code to create and edit customize buffers.
33 ;; No commands should have names starting with `custom-' because
34 ;; that interferes with completion. Use `customize-' for commands
35 ;; that the user will run with M-x, and `Custom-' for interactive commands.
37 ;; The identity of a customize option is represented by a Lisp symbol.
38 ;; The following values are associated with an option.
40 ;; 0. The current value.
42 ;; This is the value of the option as seen by "the rest of Emacs".
44 ;; Usually extracted by 'default-value', but can be extracted with
45 ;; different means if the option symbol has the 'custom-get'
46 ;; property. Similarly, set-default (or the 'custom-set' property)
49 ;; 1. The widget value.
51 ;; This is the value shown in the widget in a customize buffer.
53 ;; 2. The customized value.
55 ;; This is the last value given to the option through customize.
57 ;; It is stored in the 'customized-value' property of the option, in a
58 ;; cons-cell whose car evaluates to the customized value.
60 ;; 3. The saved value.
62 ;; This is last value saved from customize.
64 ;; It is stored in the 'saved-value' property of the option, in a
65 ;; cons-cell whose car evaluates to the saved value.
67 ;; 4. The standard value.
69 ;; This is the value given in the 'defcustom' declaration.
71 ;; It is stored in the 'standard-value' property of the option, in a
72 ;; cons-cell whose car evaluates to the standard value.
74 ;; 5. The "think" value.
76 ;; This is what customize thinks the current value should be.
78 ;; This is the customized value, if any such value exists, otherwise
79 ;; the saved value, if that exists, and as a last resort the standard
82 ;; The reason for storing values unevaluated: This is so you can have
83 ;; values that depend on the environment. For example, you can have a
84 ;; variable that has one value when Emacs is running under a window
85 ;; system, and another value on a tty. Since the evaluation is only done
86 ;; when the variable is first initialized, this is only relevant for the
87 ;; saved (and standard) values, but affect others values for
90 ;; You can see (and modify and save) this unevaluated value by selecting
91 ;; "Show Saved Lisp Expression" from the Lisp interface. This will
92 ;; give you the unevaluated saved value, if any, otherwise the
93 ;; unevaluated standard value.
95 ;; The possible states for a customize widget are:
99 ;; The state has not been determined yet.
103 ;; The widget value is different from the current value.
107 ;; The current value is different from the "think" value.
111 ;; The "think" value is the customized value.
115 ;; The "think" value is the saved value.
119 ;; The "think" value is the standard value.
123 ;; There is no standard value. This means that the variable was
124 ;; not defined with defcustom, nor handled in cus-start.el. Most
125 ;; standard interactive Custom commands do not let you create a
126 ;; Custom buffer containing such variables. However, such Custom
127 ;; buffers can be created, for instance, by calling
128 ;; `customize-apropos' with a prefix arg or by calling
129 ;; `customize-option' non-interactively.
133 ;; There is no widget value.
137 ;; The widget value is not valid member of the :type specified for the
145 (defvar custom-versions-load-alist
) ; from cus-load
146 (defvar recentf-exclude
) ; from recentf.el
156 (put 'custom-define-hook
'custom-type
'hook
)
157 (put 'custom-define-hook
'standard-value
'(nil))
158 (custom-add-to-group 'customize
'custom-define-hook
'custom-variable
)
160 ;;; Customization Groups.
163 "Customization of the One True Editor."
164 :link
'(custom-manual "(emacs)Top"))
166 ;; Most of these groups are stolen from `finder.el',
167 (defgroup editing nil
168 "Basic text editing facilities."
172 "Abbreviation handling, typing shortcuts, macros."
176 (defgroup matching nil
177 "Various sorts of searching and matching."
180 (defgroup emulations nil
181 "Emulations of other editors."
182 :link
'(custom-manual "(emacs)Emulation")
189 (defgroup outlines nil
190 "Support for hierarchical outlining."
193 (defgroup external nil
194 "Interfacing to external utilities."
197 (defgroup processes nil
198 "Process, subshell, compilation, and job control support."
202 (defgroup convenience nil
203 "Convenience features for faster editing."
206 (defgroup programming nil
207 "Support for programming in other languages."
210 (defgroup languages nil
211 "Specialized modes for editing programming languages."
215 "Lisp support, including Emacs Lisp."
216 :link
'(custom-group-link :tag
"Font Lock Faces group" font-lock-faces
)
221 "Support for the C language and related languages."
222 :link
'(custom-group-link :tag
"Font Lock Faces group" font-lock-faces
)
223 :link
'(custom-manual "(ccmode)")
231 "Support for object-oriented programming."
234 (defgroup applications nil
235 "Applications written in Emacs."
238 (defgroup calendar nil
239 "Calendar and time management support."
240 :group
'applications
)
243 "Modes for electronic-mail handling."
244 :group
'applications
)
247 "Support for netnews reading and posting."
248 :link
'(custom-manual "(gnus)")
249 :group
'applications
)
252 "Games, jokes and amusements."
253 :group
'applications
)
255 (defgroup development nil
256 "Support for further development of Emacs."
260 "Support for Emacs documentation."
263 (defgroup extensions nil
264 "Emacs Lisp language extensions."
267 (defgroup internal nil
268 "Code for Emacs internals, build process, defaults."
272 "Maintenance aids for the Emacs development group."
276 (defgroup environment nil
277 "Fitting Emacs with its environment."
281 "Communications, networking, remote access to files."
285 (defgroup hardware nil
286 "Support for interfacing with exotic hardware."
289 (defgroup terminals nil
290 "Support for terminal types."
294 "Front-ends/assistants for, or emulators of, UNIX features."
298 "Support code for vms."
302 "Internationalization and alternate character-set support."
303 :link
'(custom-manual "(emacs)International")
308 "The X Window system."
312 "Support for Emacs frames and window systems."
316 "Support editing files of data."
320 "Support editing files."
328 "Code related to the TeX formatter."
329 :link
'(custom-group-link :tag
"Font Lock Faces group" font-lock-faces
)
333 "Support for multiple fonts."
336 (defgroup hypermedia nil
337 "Support for links between text or other media types."
341 "Support for on-line help systems."
344 (defgroup multimedia nil
345 "Non-textual support, specifically images and sound."
349 "Code local to your site."
352 (defgroup customize
'((widgets custom-group
))
353 "Customization of the Customization support."
357 (defgroup custom-faces nil
358 "Faces used by customize."
362 (defgroup custom-browse nil
363 "Control customize browser."
367 (defgroup custom-buffer nil
368 "Control customize buffers."
372 (defgroup custom-menu nil
373 "Control customize menus."
378 "Storage allocation and gc for GNU Emacs Lisp interpreter."
379 :tag
"Storage Allocation"
383 "Undoing changes in buffers."
384 :link
'(custom-manual "(emacs)Undo")
387 (defgroup mode-line nil
388 "Content of the modeline."
391 (defgroup editing-basics nil
392 "Most basic editing facilities."
395 (defgroup display nil
396 "How characters are displayed in buffers."
399 (defgroup execute nil
400 "Executing external commands."
403 (defgroup installation nil
404 "The Emacs installation."
412 "Internal Emacs limits."
416 "Debugging Emacs itself."
419 (defgroup keyboard nil
420 "Input from the keyboard."
424 "Input from the mouse."
428 "Input from the menus."
432 "Handling data from drag and drop."
435 (defgroup auto-save nil
436 "Preventing accidental loss of data."
439 (defgroup processes-basics nil
440 "Basic stuff dealing with processes."
444 "MULE Emacs internationalization."
447 (defgroup windows nil
448 "Windows within a frame."
449 :link
'(custom-manual "(emacs)Windows")
453 "Mac specific features."
454 :link
'(custom-manual "(emacs)Mac OS")
459 ;;; Custom mode keymaps
461 (defvar custom-mode-map
462 ;; This keymap should be dense, but a dense keymap would prevent inheriting
463 ;; "\r" bindings from the parent map.
464 ;; Actually, this misfeature of dense keymaps was fixed on 2001-11-26.
465 (let ((map (make-keymap)))
466 (set-keymap-parent map widget-keymap
)
467 (define-key map
[remap self-insert-command
] 'Custom-no-edit
)
468 (define-key map
"\^m" 'Custom-newline
)
469 (define-key map
" " 'scroll-up
)
470 (define-key map
"\177" 'scroll-down
)
471 (define-key map
"\C-c\C-c" 'Custom-set
)
472 (define-key map
"\C-x\C-s" 'Custom-save
)
473 (define-key map
"q" 'Custom-buffer-done
)
474 (define-key map
"u" 'Custom-goto-parent
)
475 (define-key map
"n" 'widget-forward
)
476 (define-key map
"p" 'widget-backward
)
478 "Keymap for `Custom-mode'.")
480 (defvar custom-mode-link-map
481 (let ((map (make-keymap)))
482 (set-keymap-parent map custom-mode-map
)
483 (define-key map
[down-mouse-2
] nil
)
484 (define-key map
[down-mouse-1
] 'mouse-drag-region
)
485 (define-key map
[mouse-2
] 'widget-move-and-invoke
)
487 "Local keymap for links in `Custom-mode'.")
489 (defvar custom-field-keymap
490 (let ((map (copy-keymap widget-field-keymap
)))
491 (define-key map
"\C-c\C-c" 'Custom-set
)
492 (define-key map
"\C-x\C-s" 'Custom-save
)
494 "Keymap used inside editable fields in customization buffers.")
496 (widget-put (get 'editable-field
'widget-type
) :keymap custom-field-keymap
)
500 (defun custom-split-regexp-maybe (regexp)
501 "If REGEXP is a string, split it to a list at `\\|'.
502 You can get the original back from the result with:
503 (mapconcat 'identity result \"\\|\")
505 IF REGEXP is not a string, return it unchanged."
507 (split-string regexp
"\\\\|")
510 (defun custom-variable-prompt ()
511 "Prompt for a custom variable, defaulting to the variable at point.
512 Return a list suitable for use in `interactive'."
513 (let* ((v (variable-at-point))
514 (default (and (symbolp v
) (custom-variable-p v
) (symbol-name v
)))
515 (enable-recursive-minibuffers t
)
517 (setq val
(completing-read
518 (if default
(format "Customize variable (default %s): " default
)
519 "Customize variable: ")
520 obarray
'custom-variable-p t nil nil default
))
521 (list (if (equal val
"")
522 (if (symbolp v
) v nil
)
525 (defun custom-menu-filter (menu widget
)
526 "Convert MENU to the form used by `widget-choose'.
527 MENU should be in the same format as `custom-variable-menu'.
528 WIDGET is the widget to apply the filter entries of MENU on."
530 current name action filter
)
532 (setq current
(car menu
)
534 action
(nth 1 current
)
535 filter
(nth 2 current
)
537 (if (or (null filter
) (funcall filter widget
))
538 (push (cons name action
) result
)
544 (defvar custom-prefix-list nil
545 "List of prefixes that should be ignored by `custom-unlispify'.")
547 (defcustom custom-unlispify-menu-entries t
548 "Display menu entries as words instead of symbols if non-nil."
552 (defcustom custom-unlispify-remove-prefixes nil
553 "Non-nil means remove group prefixes from option names in buffer."
555 :group
'custom-buffer
558 (defun custom-unlispify-menu-entry (symbol &optional no-suffix
)
559 "Convert SYMBOL into a menu entry."
560 (cond ((not custom-unlispify-menu-entries
)
561 (symbol-name symbol
))
562 ((get symbol
'custom-tag
)
564 (get symbol
'custom-tag
)
565 (concat (get symbol
'custom-tag
) "...")))
567 (with-current-buffer (get-buffer-create " *Custom-Work*")
569 (princ symbol
(current-buffer))
570 (goto-char (point-min))
571 ;; FIXME: Boolean variables are not predicates, so they shouldn't
572 ;; end with `-p'. -stef
573 ;; (when (and (eq (get symbol 'custom-type) 'boolean)
574 ;; (re-search-forward "-p\\'" nil t))
575 ;; (replace-match "" t t)
576 ;; (goto-char (point-min)))
577 (if custom-unlispify-remove-prefixes
578 (let ((prefixes custom-prefix-list
)
581 (setq prefix
(car prefixes
))
582 (if (search-forward prefix
(+ (point) (length prefix
)) t
)
585 (delete-region (point-min) (point)))
586 (setq prefixes
(cdr prefixes
))))))
587 (subst-char-in-region (point-min) (point-max) ?- ?\ t
)
588 (capitalize-region (point-min) (point-max))
590 (goto-char (point-max))
594 (defcustom custom-unlispify-tag-names t
595 "Display tag names as words instead of symbols if non-nil."
596 :group
'custom-buffer
599 (defun custom-unlispify-tag-name (symbol)
600 "Convert SYMBOL into a menu entry."
601 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names
))
602 (custom-unlispify-menu-entry symbol t
)))
604 (defun custom-prefix-add (symbol prefixes
)
605 "Add SYMBOL to list of ignored PREFIXES."
606 (cons (or (get symbol
'custom-prefix
)
607 (concat (symbol-name symbol
) "-"))
612 (defcustom custom-guess-name-alist
618 ("-function\\'" function
)
619 ("-functions\\'" (repeat function
))
620 ("-list\\'" (repeat sexp
))
621 ("-alist\\'" (repeat (cons sexp sexp
))))
622 "Alist of (MATCH TYPE).
624 MATCH should be a regexp matching the name of a symbol, and TYPE should
625 be a widget suitable for editing the value of that symbol. The TYPE
626 of the first entry where MATCH matches the name of the symbol will be
629 This is used for guessing the type of variables not declared with
631 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
632 :group
'custom-buffer
)
634 (defcustom custom-guess-doc-alist
635 '(("\\`\\*?Non-nil " boolean
))
636 "Alist of (MATCH TYPE).
638 MATCH should be a regexp matching a documentation string, and TYPE
639 should be a widget suitable for editing the value of a variable with
640 that documentation string. The TYPE of the first entry where MATCH
641 matches the name of the symbol will be used.
643 This is used for guessing the type of variables not declared with
645 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
646 :group
'custom-buffer
)
648 (defun custom-guess-type (symbol)
649 "Guess a widget suitable for editing the value of SYMBOL.
650 This is done by matching SYMBOL with `custom-guess-name-alist' and
651 if that fails, the doc string with `custom-guess-doc-alist'."
652 (let ((name (symbol-name symbol
))
653 (names custom-guess-name-alist
)
656 (setq current
(car names
)
658 (when (string-match (nth 0 current
) name
)
659 (setq found
(nth 1 current
)
662 (let ((doc (documentation-property symbol
'variable-documentation
))
663 (docs custom-guess-doc-alist
))
666 (setq current
(car docs
)
668 (when (string-match (nth 0 current
) doc
)
669 (setq found
(nth 1 current
)
676 (defcustom custom-browse-sort-alphabetically nil
677 "If non-nil, sort customization group alphabetically in `custom-browse'."
679 :group
'custom-browse
)
681 (defcustom custom-browse-order-groups nil
682 "If non-nil, order group members within each customization group.
683 If `first', order groups before non-groups.
684 If `last', order groups after non-groups."
685 :type
'(choice (const first
)
687 (const :tag
"none" nil
))
688 :group
'custom-browse
)
690 (defcustom custom-browse-only-groups nil
691 "If non-nil, show group members only within each customization group."
693 :group
'custom-browse
)
696 (defcustom custom-buffer-sort-alphabetically nil
697 "If non-nil, sort each customization group alphabetically in Custom buffer."
699 :group
'custom-buffer
)
701 (defcustom custom-buffer-order-groups
'last
702 "If non-nil, order group members within each customization group.
703 If `first', order groups before non-groups.
704 If `last', order groups after non-groups."
705 :type
'(choice (const first
)
707 (const :tag
"none" nil
))
708 :group
'custom-buffer
)
711 (defcustom custom-menu-sort-alphabetically nil
712 "If non-nil, sort each customization group alphabetically in menus."
716 (defcustom custom-menu-order-groups
'first
717 "If non-nil, order group members within each customization group.
718 If `first', order groups before non-groups.
719 If `last', order groups after non-groups."
720 :type
'(choice (const first
)
722 (const :tag
"none" nil
))
725 ;;;###autoload (add-hook 'same-window-regexps "\\`\\*Customiz.*\\*\\'")
727 (defun custom-sort-items (items sort-alphabetically order-groups
)
728 "Return a sorted copy of ITEMS.
729 ITEMS should be a `custom-group' property.
730 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
731 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
732 groups after non-groups, if nil do not order groups at all."
733 (sort (copy-sequence items
)
735 (let ((typea (nth 1 a
)) (typeb (nth 1 b
))
736 (namea (nth 0 a
)) (nameb (nth 0 b
)))
737 (cond ((not order-groups
)
738 ;; Since we don't care about A and B order, maybe sort.
739 (when sort-alphabetically
740 (string-lessp namea nameb
)))
741 ((eq typea
'custom-group
)
742 ;; If B is also a group, maybe sort. Otherwise, order A and B.
743 (if (eq typeb
'custom-group
)
744 (when sort-alphabetically
745 (string-lessp namea nameb
))
746 (eq order-groups
'first
)))
747 ((eq typeb
'custom-group
)
748 ;; Since A cannot be a group, order A and B.
749 (eq order-groups
'last
))
751 ;; Since A and B cannot be groups, sort.
752 (string-lessp namea nameb
)))))))
754 ;;; Custom Mode Commands.
756 ;; This variable is used by `custom-tool-bar-map', or directly by
757 ;; `custom-buffer-create-internal' if the toolbar is not present and
758 ;; `custom-buffer-verbose-help' is non-nil.
760 (defvar custom-commands
761 '(("Set for current session" Custom-set t
762 "Apply all settings in this buffer to the current session"
764 ("Save for future sessions" Custom-save
765 (or custom-file user-init-file
)
766 "Apply all settings in this buffer and save them for future Emacs sessions."
768 ("Undo edits" Custom-reset-current t
769 "Restore all settings in this buffer to reflect their current values."
771 ("Reset to saved" Custom-reset-saved t
772 "Restore all settings in this buffer to their saved values (if any)."
774 ("Erase customizations" Custom-reset-standard
775 (or custom-file user-init-file
)
776 "Un-customize all settings in this buffer and save them with standard values."
778 ("Help for Customize" Custom-help t
779 "Get help for using Customize."
781 ("Exit" Custom-buffer-done t
"Exit Customize." "exit")))
783 (defun Custom-help ()
784 "Read the node on Easy Customization in the Emacs manual."
786 (info "(emacs)Easy Customization"))
788 (defvar custom-reset-menu
789 '(("Undo Edits" . Custom-reset-current
)
790 ("Reset to Saved" . Custom-reset-saved
)
791 ("Erase Customizations (use standard values)" . Custom-reset-standard
))
792 "Alist of actions for the `Reset' button.
793 The key is a string containing the name of the action, the value is a
794 Lisp function taking the widget as an element which will be called
795 when the action is chosen.")
797 (defvar custom-options nil
798 "Customization widgets in the current buffer.")
800 (defun custom-command-apply (fun query
&optional strong-query
)
801 "Call function FUN on all widgets in `custom-options'.
802 If there is more than one widget, ask user for confirmation using
803 the query string QUERY, using `y-or-n-p' if STRONG-QUERY is nil,
804 and `yes-or-no-p' otherwise."
805 (if (or (and (= 1 (length custom-options
))
806 (memq (widget-type (car custom-options
))
807 '(custom-variable custom-face
)))
808 (funcall (if strong-query
'yes-or-no-p
'y-or-n-p
) query
))
809 (progn (mapc fun custom-options
) t
)
813 (defun Custom-set (&rest ignore
)
814 "Set the current value of all edited settings in the buffer."
816 (custom-command-apply
818 (when (eq (widget-get child
:custom-state
) 'modified
)
819 (widget-apply child
:custom-set
)))
820 "Set all values according to this buffer? "))
822 (defun Custom-save (&rest ignore
)
823 "Set all edited settings, then save all settings that have been set.
824 If a setting was edited and set before, this saves it. If a
825 setting was merely edited before, this sets it then saves it."
827 (when (custom-command-apply
829 (when (memq (widget-get child
:custom-state
)
830 '(modified set changed rogue
))
831 (widget-apply child
:custom-mark-to-save
)))
832 "Save all settings in this buffer? " t
)
833 ;; Save changes to buffer and redraw.
835 (dolist (child custom-options
)
836 (widget-apply child
:custom-state-set-and-redraw
))))
838 (defun custom-reset (widget &optional event
)
839 "Select item from reset menu."
840 (let* ((completion-ignore-case t
)
841 (answer (widget-choose "Reset settings"
847 (defun Custom-reset-current (&rest ignore
)
848 "Reset all edited settings in the buffer to show their current values."
850 (custom-command-apply
852 (if (memq (widget-get widget
:custom-state
) '(modified changed
))
853 (widget-apply widget
:custom-reset-current
)))
854 "Reset all settings' buffer text to show current values? "))
856 (defun Custom-reset-saved (&rest ignore
)
857 "Reset all edited or set settings in the buffer to their saved value.
858 This also shows the saved values in the buffer."
860 (custom-command-apply
862 (if (memq (widget-get widget
:custom-state
) '(modified set changed rogue
))
863 (widget-apply widget
:custom-reset-saved
)))
864 "Reset all settings (current values and buffer text) to saved values? "))
866 ;; The next two variables are bound to '(t) by `Custom-reset-standard'
867 ;; and `custom-group-reset-standard'. If these variables are nil, both
868 ;; `custom-variable-reset-standard' and `custom-face-reset-standard'
869 ;; save, reset and redraw the handled widget immediately. Otherwise,
870 ;; they add the widget to the corresponding list and leave it to
871 ;; `custom-reset-standard-save-and-update' to save, reset and redraw it.
872 (defvar custom-reset-standard-variables-list nil
)
873 (defvar custom-reset-standard-faces-list nil
)
875 ;; The next function was excerpted from `custom-variable-reset-standard'
876 ;; and `custom-face-reset-standard' and is used to avoid calling
877 ;; `custom-save-all' repeatedly (and thus saving settings to file one by
878 ;; one) when erasing all customizations.
879 (defun custom-reset-standard-save-and-update ()
880 "Save settings and redraw after erasing customizations."
881 (when (or (and custom-reset-standard-variables-list
882 (not (eq custom-reset-standard-variables-list
'(t))))
883 (and custom-reset-standard-faces-list
884 (not (eq custom-reset-standard-faces-list
'(t)))))
885 ;; Save settings to file.
887 ;; Set state of and redraw variables.
888 (dolist (widget custom-reset-standard-variables-list
)
889 (unless (eq widget t
)
890 (widget-put widget
:custom-state
'unknown
)
891 (custom-redraw widget
)))
892 ;; Set state of and redraw faces.
893 (dolist (widget custom-reset-standard-faces-list
)
894 (unless (eq widget t
)
895 (let* ((symbol (widget-value widget
))
896 (child (car (widget-get widget
:children
)))
897 (value (get symbol
'face-defface-spec
))
898 (comment-widget (widget-get widget
:comment-widget
)))
899 (put symbol
'face-comment nil
)
900 (widget-value-set child
901 (custom-pre-filter-face-spec
902 (list (list t
(custom-face-attributes-get
904 ;; This call manages the comment visibility
905 (widget-value-set comment-widget
"")
906 (custom-face-state-set widget
)
907 (custom-redraw-magic widget
))))))
909 (defun Custom-reset-standard (&rest ignore
)
910 "Erase all customizations (either current or saved) in current buffer.
911 The immediate result is to restore them to their standard values.
912 This operation eliminates any saved values for the group members,
913 making them as if they had never been customized at all."
915 ;; Bind these temporarily.
916 (let ((custom-reset-standard-variables-list '(t))
917 (custom-reset-standard-faces-list '(t)))
918 (custom-command-apply
920 (and (or (null (widget-get widget
:custom-standard-value
))
921 (widget-apply widget
:custom-standard-value
))
922 (memq (widget-get widget
:custom-state
)
923 '(modified set changed saved rogue
))
924 (widget-apply widget
:custom-mark-to-reset-standard
)))
925 "Erase all customizations for settings in this buffer? " t
)
926 (custom-reset-standard-save-and-update)))
928 ;;; The Customize Commands
930 (defun custom-prompt-variable (prompt-var prompt-val
&optional comment
)
931 "Prompt for a variable and a value and return them as a list.
932 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
933 prompt for the value. The %s escape in PROMPT-VAL is replaced with
934 the name of the variable.
936 If the variable has a `variable-interactive' property, that is used as if
937 it were the arg to `interactive' (which see) to interactively read the value.
939 If the variable has a `custom-type' property, it must be a widget and the
940 `:prompt-value' property of that widget will be used for reading the value.
942 If optional COMMENT argument is non-nil, also prompt for a comment and return
943 it as the third element in the list."
944 (let* ((var (read-variable prompt-var
))
945 (minibuffer-help-form '(describe-variable var
))
947 (let ((prop (get var
'variable-interactive
))
948 (type (get var
'custom-type
))
949 (prompt (format prompt-val var
)))
951 (setq type
(list type
)))
953 ;; Use VAR's `variable-interactive' property
954 ;; as an interactive spec for prompting.
955 (call-interactively `(lambda (arg)
959 (widget-prompt-value type
965 (eval-minibuffer prompt
))))))
968 (read-string "Comment: " (get var
'variable-comment
)))
972 (defun customize-set-value (variable value
&optional comment
)
973 "Set VARIABLE to VALUE, and return VALUE. VALUE is a Lisp object.
975 If VARIABLE has a `variable-interactive' property, that is used as if
976 it were the arg to `interactive' (which see) to interactively read the value.
978 If VARIABLE has a `custom-type' property, it must be a widget and the
979 `:prompt-value' property of that widget will be used for reading the value.
981 If given a prefix (or a COMMENT argument), also prompt for a comment."
982 (interactive (custom-prompt-variable "Set variable: "
986 (cond ((string= comment
"")
987 (put variable
'variable-comment nil
))
989 (put variable
'variable-comment comment
)))
990 (set variable value
))
993 (defun customize-set-variable (variable value
&optional comment
)
994 "Set the default for VARIABLE to VALUE, and return VALUE.
995 VALUE is a Lisp object.
997 If VARIABLE has a `custom-set' property, that is used for setting
998 VARIABLE, otherwise `set-default' is used.
1000 If VARIABLE has a `variable-interactive' property, that is used as if
1001 it were the arg to `interactive' (which see) to interactively read the value.
1003 If VARIABLE has a `custom-type' property, it must be a widget and the
1004 `:prompt-value' property of that widget will be used for reading the value.
1006 If given a prefix (or a COMMENT argument), also prompt for a comment."
1007 (interactive (custom-prompt-variable "Set variable: "
1008 "Set customized value for %s to: "
1009 current-prefix-arg
))
1010 (custom-load-symbol variable
)
1011 (custom-push-theme 'theme-value variable
'user
'set
(custom-quote value
))
1012 (funcall (or (get variable
'custom-set
) 'set-default
) variable value
)
1013 (put variable
'customized-value
(list (custom-quote value
)))
1014 (cond ((string= comment
"")
1015 (put variable
'variable-comment nil
)
1016 (put variable
'customized-variable-comment nil
))
1018 (put variable
'variable-comment comment
)
1019 (put variable
'customized-variable-comment comment
)))
1023 (defun customize-save-variable (variable value
&optional comment
)
1024 "Set the default for VARIABLE to VALUE, and save it for future sessions.
1027 If VARIABLE has a `custom-set' property, that is used for setting
1028 VARIABLE, otherwise `set-default' is used.
1030 If VARIABLE has a `variable-interactive' property, that is used as if
1031 it were the arg to `interactive' (which see) to interactively read the value.
1033 If VARIABLE has a `custom-type' property, it must be a widget and the
1034 `:prompt-value' property of that widget will be used for reading the value.
1036 If given a prefix (or a COMMENT argument), also prompt for a comment."
1037 (interactive (custom-prompt-variable "Set and save variable: "
1038 "Set and save value for %s as: "
1039 current-prefix-arg
))
1040 (funcall (or (get variable
'custom-set
) 'set-default
) variable value
)
1041 (put variable
'saved-value
(list (custom-quote value
)))
1042 (custom-push-theme 'theme-value variable
'user
'set
(custom-quote value
))
1043 (cond ((string= comment
"")
1044 (put variable
'variable-comment nil
)
1045 (put variable
'saved-variable-comment nil
))
1047 (put variable
'variable-comment comment
)
1048 (put variable
'saved-variable-comment comment
)))
1049 (put variable
'customized-value nil
)
1050 (put variable
'customized-variable-comment nil
)
1056 "Select a customization buffer which you can use to set user options.
1057 User options are structured into \"groups\".
1058 Initially the top-level group `Emacs' and its immediate subgroups
1059 are shown; the contents of those subgroups are initially hidden."
1061 (customize-group 'emacs
))
1064 (defun customize-mode (mode)
1065 "Customize options related to the current major mode.
1066 If a prefix \\[universal-argument] was given (or if the current major mode has no known group),
1067 then prompt for the MODE to customize."
1070 (let ((completion-regexp-list '("-mode\\'"))
1071 (group (custom-group-of-mode major-mode
)))
1072 (if (and group
(not current-prefix-arg
))
1075 (completing-read (if group
1076 (format "Major mode (default %s): " major-mode
)
1079 'custom-group-of-mode
1080 t nil nil
(if group
(symbol-name major-mode
))))))))
1081 (customize-group (custom-group-of-mode mode
)))
1083 (defun customize-read-group ()
1084 (let ((completion-ignore-case t
))
1085 (completing-read "Customize group (default emacs): "
1088 (or (and (get symbol
'custom-loads
)
1089 (not (get symbol
'custom-autoload
)))
1090 (get symbol
'custom-group
)))
1094 (defun customize-group (&optional group
)
1095 "Customize GROUP, which must be a customization group."
1096 (interactive (list (customize-read-group)))
1097 (when (stringp group
)
1098 (if (string-equal "" group
)
1100 (setq group
(intern group
))))
1101 (let ((name (format "*Customize Group: %s*"
1102 (custom-unlispify-tag-name group
))))
1103 (if (get-buffer name
)
1104 (pop-to-buffer name
)
1105 (custom-buffer-create
1106 (list (list group
'custom-group
))
1108 (concat " for group "
1109 (custom-unlispify-tag-name group
))))))
1112 (defun customize-group-other-window (&optional group
)
1113 "Customize GROUP, which must be a customization group, in another window."
1114 (interactive (list (customize-read-group)))
1115 (let ((pop-up-windows t
)
1116 (same-window-buffer-names nil
)
1117 (same-window-regexps nil
))
1118 (customize-group group
)))
1121 (defalias 'customize-variable
'customize-option
)
1124 (defun customize-option (symbol)
1125 "Customize SYMBOL, which must be a user option variable."
1126 (interactive (custom-variable-prompt))
1128 (error "No variable specified"))
1129 (let ((basevar (indirect-variable symbol
)))
1130 (custom-buffer-create (list (list basevar
'custom-variable
))
1131 (format "*Customize Option: %s*"
1132 (custom-unlispify-tag-name basevar
)))
1133 (unless (eq symbol basevar
)
1134 (message "`%s' is an alias for `%s'" symbol basevar
))))
1137 (defalias 'customize-variable-other-window
'customize-option-other-window
)
1140 (defun customize-option-other-window (symbol)
1141 "Customize SYMBOL, which must be a user option variable.
1142 Show the buffer in another window, but don't select it."
1143 (interactive (custom-variable-prompt))
1145 (error "No variable specified"))
1146 (let ((basevar (indirect-variable symbol
)))
1147 (custom-buffer-create-other-window
1148 (list (list basevar
'custom-variable
))
1149 (format "*Customize Option: %s*" (custom-unlispify-tag-name basevar
)))
1150 (unless (eq symbol basevar
)
1151 (message "`%s' is an alias for `%s'" symbol basevar
))))
1153 (defvar customize-changed-options-previous-release
"21.1"
1154 "Version for `customize-changed-options' to refer back to by default.")
1156 ;; Packages will update this variable, so make it available.
1158 (defvar customize-package-emacs-version-alist nil
1159 "Alist mapping versions of a package to Emacs versions.
1160 We use this for packages that have their own names, but are released
1161 as part of Emacs itself.
1163 Each elements looks like this:
1165 (PACKAGE (PVERSION . EVERSION)...)
1167 Here PACKAGE is the name of a package, as a symbol. After
1168 PACKAGE come one or more elements, each associating a
1169 package version PVERSION with the first Emacs version
1170 EVERSION in which it (or a subsequent version of PACKAGE)
1171 was first released. Both PVERSION and EVERSION are strings.
1172 PVERSION should be a string that this package used in
1173 the :package-version keyword for `defcustom', `defgroup',
1176 For example, the MH-E package updates this alist as follows:
1178 (add-to-list 'customize-package-emacs-version-alist
1179 '(MH-E (\"6.0\" . \"22.1\") (\"6.1\" . \"22.1\")
1180 (\"7.0\" . \"22.1\") (\"7.1\" . \"22.1\")
1181 (\"7.2\" . \"22.1\") (\"7.3\" . \"22.1\")
1182 (\"7.4\" . \"22.1\") (\"8.0\" . \"22.1\")))
1184 The value of PACKAGE needs to be unique and it needs to match the
1185 PACKAGE value appearing in the :package-version keyword. Since
1186 the user might see the value in a error message, a good choice is
1187 the official name of the package, such as MH-E or Gnus.")
1190 (defalias 'customize-changed
'customize-changed-options
)
1193 (defun customize-changed-options (&optional since-version
)
1194 "Customize all settings whose meanings have changed in Emacs itself.
1195 This includes new user option variables and faces, and new
1196 customization groups, as well as older options and faces whose meanings
1197 or default values have changed since the previous major Emacs release.
1199 With argument SINCE-VERSION (a string), customize all settings
1200 that were added or redefined since that version."
1204 (read-from-minibuffer
1205 (format "Customize options changed, since version (default %s): "
1206 customize-changed-options-previous-release
))))
1207 (if (equal since-version
"")
1208 (setq since-version nil
)
1209 (unless (condition-case nil
1210 (numberp (read since-version
))
1212 (signal 'wrong-type-argument
(list 'numberp since-version
))))
1213 (unless since-version
1214 (setq since-version customize-changed-options-previous-release
))
1216 ;; Load the information for versions since since-version. We use
1217 ;; custom-load-symbol for this.
1218 (put 'custom-versions-load-alist
'custom-loads nil
)
1219 (dolist (elt custom-versions-load-alist
)
1220 (if (customize-version-lessp since-version
(car elt
))
1221 (dolist (load (cdr elt
))
1222 (custom-add-load 'custom-versions-load-alist load
))))
1223 (custom-load-symbol 'custom-versions-load-alist
)
1224 (put 'custom-versions-load-alist
'custom-loads nil
)
1229 (let* ((package-version (get symbol
'custom-package-version
))
1231 (or (and package-version
1232 (customize-package-emacs-version symbol
1234 (get symbol
'custom-version
))))
1236 (when (customize-version-lessp since-version version
)
1237 (if (or (get symbol
'custom-group
)
1238 (get symbol
'group-documentation
))
1239 (push (list symbol
'custom-group
) found
))
1240 (if (custom-variable-p symbol
)
1241 (push (list symbol
'custom-variable
) found
))
1242 (if (custom-facep symbol
)
1243 (push (list symbol
'custom-face
) found
)))))))
1245 (custom-buffer-create (custom-sort-items found t
'first
)
1246 "*Customize Changed Options*")
1247 (error "No user option defaults have been changed since Emacs %s"
1250 (defun customize-package-emacs-version (symbol package-version
)
1251 "Return the Emacs version in which SYMBOL's meaning last changed.
1252 PACKAGE-VERSION has the form (PACKAGE . VERSION). We use
1253 `customize-package-emacs-version-alist' to find the version of
1254 Emacs that is associated with version VERSION of PACKAGE."
1255 (let (package-versions emacs-version
)
1256 ;; Use message instead of error since we want user to be able to
1257 ;; see the rest of the symbols even if a package author has
1258 ;; botched things up.
1259 (cond ((not (listp package-version
))
1260 (message "Invalid package-version value for %s" symbol
))
1261 ((setq package-versions
(assq (car package-version
)
1262 customize-package-emacs-version-alist
))
1264 (cdr (assoc (cdr package-version
) package-versions
)))
1265 (unless emacs-version
1266 (message "%s version %s not found in %s" symbol
1267 (cdr package-version
)
1268 "customize-package-emacs-version-alist")))
1270 (message "Package %s version %s lists no corresponding Emacs version"
1271 (car package-version
)
1272 (cdr package-version
))))
1275 (defun customize-version-lessp (version1 version2
)
1276 ;; Why are the versions strings, and given that they are, why aren't
1277 ;; they converted to numbers and compared as such here? -- fx
1279 ;; In case someone made a mistake and left out the quotes
1280 ;; in the :version value.
1281 (if (numberp version2
)
1282 (setq version2
(prin1-to-string version2
)))
1283 (let (major1 major2 minor1 minor2
)
1284 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version1
)
1285 (setq major1
(read (or (match-string 1 version1
)
1287 (setq minor1
(read (or (match-string 3 version1
)
1289 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version2
)
1290 (setq major2
(read (or (match-string 1 version2
)
1292 (setq minor2
(read (or (match-string 3 version2
)
1294 (or (< major1 major2
)
1295 (and (= major1 major2
)
1296 (< minor1 minor2
)))))
1299 (defun customize-face (&optional face
)
1300 "Customize FACE, which should be a face name or nil.
1301 If FACE is nil, customize all faces. If FACE is actually a
1302 face-alias, customize the face it is aliased to.
1304 Interactively, when point is on text which has a face specified,
1305 suggest to customize that face, if it's customizable."
1306 (interactive (list (read-face-name "Customize face" "all faces" t
)))
1307 (if (member face
'(nil ""))
1308 (setq face
(face-list)))
1309 (if (and (listp face
) (null (cdr face
)))
1310 (setq face
(car face
)))
1312 (custom-buffer-create
1314 (mapcar (lambda (s) (list s
'custom-face
)) face
)
1316 "*Customize Faces*")
1317 ;; If FACE is actually an alias, customize the face it is aliased to.
1318 (if (get face
'face-alias
)
1319 (setq face
(get face
'face-alias
)))
1320 (unless (facep face
)
1321 (error "Invalid face %S" face
))
1322 (custom-buffer-create
1323 (list (list face
'custom-face
))
1324 (format "*Customize Face: %s*"
1325 (custom-unlispify-tag-name face
)))))
1328 (defun customize-face-other-window (&optional face
)
1329 "Show customization buffer for face FACE in other window.
1330 If FACE is actually a face-alias, customize the face it is aliased to.
1332 Interactively, when point is on text which has a face specified,
1333 suggest to customize that face, if it's customizable."
1334 (interactive (list (read-face-name "Customize face" "all faces" t
)))
1335 (let ((pop-up-windows t
)
1336 (same-window-buffer-names nil
)
1337 (same-window-regexps nil
))
1338 (customize-face face
)))
1340 (defalias 'customize-customized
'customize-unsaved
)
1343 (defun customize-unsaved ()
1344 "Customize all user options set in this session but not saved."
1347 (mapatoms (lambda (symbol)
1348 (and (or (get symbol
'customized-face
)
1349 (get symbol
'customized-face-comment
))
1350 (custom-facep symbol
)
1351 (push (list symbol
'custom-face
) found
))
1352 (and (or (get symbol
'customized-value
)
1353 (get symbol
'customized-variable-comment
))
1355 (push (list symbol
'custom-variable
) found
))))
1357 (error "No user options are set but unsaved")
1358 (custom-buffer-create (custom-sort-items found t nil
)
1359 "*Customize Unsaved*"))))
1362 (defun customize-rogue ()
1363 "Customize all user variables modified outside customize."
1366 (mapatoms (lambda (symbol)
1367 (let ((cval (or (get symbol
'customized-value
)
1368 (get symbol
'saved-value
)
1369 (get symbol
'standard-value
))))
1370 (when (and cval
;Declared with defcustom.
1371 (default-boundp symbol
) ;Has a value.
1372 (not (equal (eval (car cval
))
1373 ;; Which does not match customize.
1374 (default-value symbol
))))
1375 (push (list symbol
'custom-variable
) found
)))))
1377 (error "No rogue user options")
1378 (custom-buffer-create (custom-sort-items found t nil
)
1379 "*Customize Rogue*"))))
1381 (defun customize-saved ()
1382 "Customize all already saved user options."
1385 (mapatoms (lambda (symbol)
1386 (and (or (get symbol
'saved-face
)
1387 (get symbol
'saved-face-comment
))
1388 (custom-facep symbol
)
1389 (push (list symbol
'custom-face
) found
))
1390 (and (or (get symbol
'saved-value
)
1391 (get symbol
'saved-variable-comment
))
1393 (push (list symbol
'custom-variable
) found
))))
1395 (error "No saved user options")
1396 (custom-buffer-create (custom-sort-items found t nil
)
1397 "*Customize Saved*"))))
1400 (defun customize-apropos (regexp &optional all
)
1401 "Customize all loaded options, faces and groups matching REGEXP.
1402 If ALL is `options', include only options.
1403 If ALL is `faces', include only faces.
1404 If ALL is `groups', include only groups.
1405 If ALL is t (interactively, with prefix arg), include variables
1406 that are not customizable options, as well as faces and groups
1407 \(but we recommend using `apropos-variable' instead)."
1408 (interactive "sCustomize (regexp): \nP")
1410 (mapatoms (lambda (symbol)
1411 (when (string-match regexp
(symbol-name symbol
))
1412 (when (and (not (memq all
'(faces options
)))
1413 (get symbol
'custom-group
))
1414 (push (list symbol
'custom-group
) found
))
1415 (when (and (not (memq all
'(options groups
)))
1416 (custom-facep symbol
))
1417 (push (list symbol
'custom-face
) found
))
1418 (when (and (not (memq all
'(groups faces
)))
1420 (eq (indirect-variable symbol
) symbol
)
1421 (or (get symbol
'saved-value
)
1422 (custom-variable-p symbol
)
1423 (and (not (memq all
'(nil options
)))
1424 (get symbol
'variable-documentation
))))
1425 (push (list symbol
'custom-variable
) found
)))))
1427 (error "No %s matching %s"
1430 (format "customizable %s"
1431 (if (memq all
'(options faces groups
))
1435 (custom-buffer-create
1436 (custom-sort-items found t custom-buffer-order-groups
)
1437 "*Customize Apropos*"))))
1440 (defun customize-apropos-options (regexp &optional arg
)
1441 "Customize all loaded customizable options matching REGEXP.
1442 With prefix arg, include variables that are not customizable options
1443 \(but it is better to use `apropos-variable' if you want to find those)."
1444 (interactive "sCustomize options (regexp): \nP")
1445 (customize-apropos regexp
(or arg
'options
)))
1448 (defun customize-apropos-faces (regexp)
1449 "Customize all loaded faces matching REGEXP."
1450 (interactive "sCustomize faces (regexp): \n")
1451 (customize-apropos regexp
'faces
))
1454 (defun customize-apropos-groups (regexp)
1455 "Customize all loaded groups matching REGEXP."
1456 (interactive "sCustomize groups (regexp): \n")
1457 (customize-apropos regexp
'groups
))
1461 (defcustom custom-buffer-style
'links
1462 "Control the presentation style for customization buffers.
1463 The value should be a symbol, one of:
1465 brackets: groups nest within each other with big horizontal brackets.
1466 links: groups have links to subgroups."
1467 :type
'(radio (const brackets
)
1469 :group
'custom-buffer
)
1471 (defcustom custom-buffer-done-kill nil
1472 "*Non-nil means exiting a Custom buffer should kill it."
1475 :group
'custom-buffer
)
1477 (defcustom custom-buffer-indent
3
1478 "Number of spaces to indent nested groups."
1480 :group
'custom-buffer
)
1482 (defun custom-get-fresh-buffer (name)
1483 "Get a fresh new buffer with name NAME.
1484 If the buffer already exist, clean it up to be like new.
1485 Beware: it's not quite like new. Good enough for custom, but maybe
1487 ;; To be more complete, we should also kill all permanent-local variables,
1488 ;; but it's not needed for custom.
1489 (let ((buf (get-buffer name
)))
1490 (when (and buf
(buffer-local-value 'buffer-file-name buf
))
1491 ;; This will check if the file is not saved.
1495 (get-buffer-create name
)
1496 (with-current-buffer buf
1497 (kill-all-local-variables)
1498 (run-hooks 'kill-buffer-hook
)
1499 ;; Delete overlays before erasing the buffer so the overlay hooks
1500 ;; don't get run spuriously when we erase the buffer.
1501 (let ((ols (overlay-lists)))
1502 (dolist (ol (nconc (car ols
) (cdr ols
)))
1503 (delete-overlay ol
)))
1508 (defun custom-buffer-create (options &optional name description
)
1509 "Create a buffer containing OPTIONS.
1510 Optional NAME is the name of the buffer.
1511 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1512 SYMBOL is a customization option, and WIDGET is a widget for editing
1514 (pop-to-buffer (custom-get-fresh-buffer (or name
"*Customization*")))
1515 (custom-buffer-create-internal options description
))
1518 (defun custom-buffer-create-other-window (options &optional name description
)
1519 "Create a buffer containing OPTIONS, and display it in another window.
1520 The result includes selecting that window.
1521 Optional NAME is the name of the buffer.
1522 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1523 SYMBOL is a customization option, and WIDGET is a widget for editing
1525 (unless name
(setq name
"*Customization*"))
1526 (let ((pop-up-windows t
)
1527 (same-window-buffer-names nil
)
1528 (same-window-regexps nil
))
1529 (pop-to-buffer (custom-get-fresh-buffer name
))
1530 (custom-buffer-create-internal options description
)))
1532 (defcustom custom-reset-button-menu nil
1533 "If non-nil, only show a single reset button in customize buffers.
1534 This button will have a menu with all three reset operations."
1536 :group
'custom-buffer
)
1538 (defcustom custom-buffer-verbose-help t
1539 "If non-nil, include explanatory text in the customization buffer."
1541 :group
'custom-buffer
)
1543 (defun Custom-buffer-done (&rest ignore
)
1544 "Exit current Custom buffer according to `custom-buffer-done-kill'."
1546 (quit-window custom-buffer-done-kill
))
1548 (defvar custom-button nil
1549 "Face used for buttons in customization buffers.")
1551 (defvar custom-button-mouse nil
1552 "Mouse face used for buttons in customization buffers.")
1554 (defvar custom-button-pressed nil
1555 "Face used for pressed buttons in customization buffers.")
1557 (defcustom custom-raised-buttons
(not (equal (face-valid-attribute-values :box
)
1558 '(("unspecified" . unspecified
))))
1559 "If non-nil, indicate active buttons in a `raised-button' style.
1560 Otherwise use brackets."
1563 :group
'custom-buffer
1564 :set
(lambda (variable value
)
1565 (custom-set-default variable value
)
1567 (if value
'custom-button
'custom-button-unraised
))
1568 (setq custom-button-mouse
1569 (if value
'custom-button-mouse
'highlight
))
1570 (setq custom-button-pressed
1572 'custom-button-pressed
1573 'custom-button-pressed-unraised
))))
1575 (defun custom-buffer-create-internal (options &optional description
)
1577 (let ((init-file (or custom-file user-init-file
)))
1578 ;; Insert verbose help at the top of the custom buffer.
1579 (when custom-buffer-verbose-help
1580 (widget-insert "Editing a setting changes only the text in this buffer."
1583 To apply your changes, use the Save or Set buttons.
1584 Saving a change normally works by editing your init file."
1586 Currently, these settings cannot be saved for future Emacs sessions,
1587 possibly because you started Emacs with `-q'.")
1588 "\nFor details, see ")
1589 (widget-create 'custom-manual
1590 :tag
"Saving Customizations"
1591 "(emacs)Saving Customizations")
1592 (widget-insert " in the ")
1593 (widget-create 'custom-manual
1595 :help-echo
"Read the Emacs manual."
1597 (widget-insert "."))
1598 ;; Insert custom command buttons if the toolbar is not in use.
1600 (widget-insert "\n")
1601 ;; tool-bar is not dumped in builds without x.
1602 (when (not (and (bound-and-true-p tool-bar-mode
) (display-graphic-p)))
1603 (if custom-buffer-verbose-help
1605 Operate on all settings in this buffer that are not marked HIDDEN:\n"))
1606 (let ((button (lambda (tag action active help icon
)
1609 (widget-create 'push-button
:tag tag
1610 :help-echo help
:action action
))))
1611 (commands custom-commands
))
1612 (apply button
(pop commands
)) ; Set for current session
1613 (apply button
(pop commands
)) ; Save for future sessions
1614 (if custom-reset-button-menu
1617 (widget-create 'push-button
1619 :help-echo
"Show a menu with reset operations."
1620 :mouse-down-action
'ignore
1621 :action
'custom-reset
))
1622 (widget-insert "\n")
1623 (apply button
(pop commands
)) ; Undo edits
1624 (apply button
(pop commands
)) ; Reset to saved
1625 (apply button
(pop commands
)) ; Erase customization
1627 (pop commands
) ; Help (omitted)
1628 (apply button
(pop commands
))))) ; Exit
1629 (widget-insert "\n\n"))
1631 ;; Now populate the custom buffer.
1632 (message "Creating customization items...")
1633 (buffer-disable-undo)
1634 (setq custom-options
1635 (if (= (length options
) 1)
1636 (mapcar (lambda (entry)
1637 (widget-create (nth 1 entry
)
1638 :documentation-shown t
1639 :custom-state
'unknown
1640 :tag
(custom-unlispify-tag-name
1642 :value
(nth 0 entry
)))
1645 (length (length options
)))
1646 (mapcar (lambda (entry)
1648 (message "Creating customization items ...%2d%%"
1649 (/ (* 100.0 count
) length
))
1650 (widget-create (nth 1 entry
)
1651 :tag
(custom-unlispify-tag-name
1653 :value
(nth 0 entry
))
1654 (setq count
(1+ count
))
1655 (unless (eq (preceding-char) ?
\n)
1656 (widget-insert "\n"))
1657 (widget-insert "\n")))
1659 (unless (eq (preceding-char) ?
\n)
1660 (widget-insert "\n"))
1661 (message "Creating customization items ...done")
1662 (message "Resetting customization items...")
1663 (unless (eq custom-buffer-style
'tree
)
1664 (mapc 'custom-magic-reset custom-options
))
1665 (message "Resetting customization items...done")
1666 (message "Creating customization setup...")
1668 (buffer-enable-undo)
1669 (goto-char (point-min))
1670 (message "Creating customization setup...done"))
1672 ;;; The Tree Browser.
1675 (defun customize-browse (&optional group
)
1676 "Create a tree browser for the customize hierarchy."
1679 (setq group
'emacs
))
1680 (let ((name "*Customize Browser*"))
1681 (pop-to-buffer (custom-get-fresh-buffer name
)))
1683 (widget-insert (format "\
1684 %s buttons; type RET or click mouse-1
1685 on a button to invoke its action.
1686 Invoke [+] to expand a group, and [-] to collapse an expanded group.\n"
1687 (if custom-raised-buttons
1688 "`Raised' text indicates"
1689 "Square brackets indicate")))
1692 (if custom-browse-only-groups
1694 Invoke the [Group] button below to edit that item in another window.\n\n")
1695 (widget-insert "Invoke the ")
1696 (widget-create 'item
1699 :tag-glyph
"folder")
1700 (widget-insert ", ")
1701 (widget-create 'item
1705 (widget-insert ", and ")
1706 (widget-create 'item
1709 :tag-glyph
"option")
1710 (widget-insert " buttons below to edit that
1711 item in another window.\n\n"))
1712 (let ((custom-buffer-style 'tree
))
1713 (widget-create 'custom-group
1715 :custom-state
'unknown
1716 :tag
(custom-unlispify-tag-name group
)
1719 (goto-char (point-min)))
1721 (define-widget 'custom-browse-visibility
'item
1722 "Control visibility of items in the customize tree browser."
1724 :action
'custom-browse-visibility-action
)
1726 (defun custom-browse-visibility-action (widget &rest ignore
)
1727 (let ((custom-buffer-style 'tree
))
1728 (custom-toggle-parent widget
)))
1730 (define-widget 'custom-browse-group-tag
'custom-group-link
1731 "Show parent in other window when activated."
1734 :action
'custom-browse-group-tag-action
)
1736 (defun custom-browse-group-tag-action (widget &rest ignore
)
1737 (let ((parent (widget-get widget
:parent
)))
1738 (customize-group-other-window (widget-value parent
))))
1740 (define-widget 'custom-browse-variable-tag
'custom-group-link
1741 "Show parent in other window when activated."
1744 :action
'custom-browse-variable-tag-action
)
1746 (defun custom-browse-variable-tag-action (widget &rest ignore
)
1747 (let ((parent (widget-get widget
:parent
)))
1748 (customize-variable-other-window (widget-value parent
))))
1750 (define-widget 'custom-browse-face-tag
'custom-group-link
1751 "Show parent in other window when activated."
1754 :action
'custom-browse-face-tag-action
)
1756 (defun custom-browse-face-tag-action (widget &rest ignore
)
1757 (let ((parent (widget-get widget
:parent
)))
1758 (customize-face-other-window (widget-value parent
))))
1760 (defconst custom-browse-alist
'((" " "space")
1766 (defun custom-browse-insert-prefix (prefix)
1767 "Insert PREFIX. On XEmacs convert it to line graphics."
1768 ;; Fixme: do graphics.
1769 (if nil
; (featurep 'xemacs)
1772 (while (not (string-equal prefix
""))
1773 (let ((entry (substring prefix
0 3)))
1774 (setq prefix
(substring prefix
3))
1775 (let ((overlay (make-overlay (1- (point)) (point) nil t nil
))
1776 (name (nth 1 (assoc entry custom-browse-alist
))))
1777 (overlay-put overlay
'end-glyph
(widget-glyph-find name entry
))
1778 (overlay-put overlay
'start-open t
)
1779 (overlay-put overlay
'end-open t
)))))
1782 ;;; Modification of Basic Widgets.
1784 ;; We add extra properties to the basic widgets needed here. This is
1785 ;; fine, as long as we are careful to stay within our own namespace.
1787 ;; We want simple widgets to be displayed by default, but complex
1788 ;; widgets to be hidden.
1790 (widget-put (get 'item
'widget-type
) :custom-show t
)
1791 (widget-put (get 'editable-field
'widget-type
)
1792 :custom-show
(lambda (widget value
)
1793 (let ((pp (pp-to-string value
)))
1794 (cond ((string-match "\n" pp
)
1799 (widget-put (get 'menu-choice
'widget-type
) :custom-show t
)
1801 ;;; The `custom-manual' Widget.
1803 (define-widget 'custom-manual
'info-link
1804 "Link to the manual entry for this customization option."
1805 :help-echo
"Read the manual entry for this option."
1806 :keymap custom-mode-link-map
1807 :follow-link
'mouse-face
1808 :button-face
'custom-link
1809 :mouse-face
'highlight
1810 :pressed-face
'highlight
1813 ;;; The `custom-magic' Widget.
1815 (defgroup custom-magic-faces nil
1816 "Faces used by the magic button."
1817 :group
'custom-faces
1818 :group
'custom-buffer
)
1820 (defface custom-invalid
'((((class color
))
1821 (:foreground
"yellow1" :background
"red1"))
1823 (:weight bold
:slant italic
:underline t
)))
1824 "Face used when the customize item is invalid."
1825 :group
'custom-magic-faces
)
1826 ;; backward-compatibility alias
1827 (put 'custom-invalid-face
'face-alias
'custom-invalid
)
1829 (defface custom-rogue
'((((class color
))
1830 (:foreground
"pink" :background
"black"))
1833 "Face used when the customize item is not defined for customization."
1834 :group
'custom-magic-faces
)
1835 ;; backward-compatibility alias
1836 (put 'custom-rogue-face
'face-alias
'custom-rogue
)
1838 (defface custom-modified
'((((min-colors 88) (class color
))
1839 (:foreground
"white" :background
"blue1"))
1841 (:foreground
"white" :background
"blue"))
1843 (:slant italic
:bold
)))
1844 "Face used when the customize item has been modified."
1845 :group
'custom-magic-faces
)
1846 ;; backward-compatibility alias
1847 (put 'custom-modified-face
'face-alias
'custom-modified
)
1849 (defface custom-set
'((((min-colors 88) (class color
))
1850 (:foreground
"blue1" :background
"white"))
1852 (:foreground
"blue" :background
"white"))
1855 "Face used when the customize item has been set."
1856 :group
'custom-magic-faces
)
1857 ;; backward-compatibility alias
1858 (put 'custom-set-face
'face-alias
'custom-set
)
1860 (defface custom-changed
'((((min-colors 88) (class color
))
1861 (:foreground
"white" :background
"blue1"))
1863 (:foreground
"white" :background
"blue"))
1866 "Face used when the customize item has been changed."
1867 :group
'custom-magic-faces
)
1868 ;; backward-compatibility alias
1869 (put 'custom-changed-face
'face-alias
'custom-changed
)
1871 (defface custom-themed
'((((min-colors 88) (class color
))
1872 (:foreground
"white" :background
"blue1"))
1874 (:foreground
"white" :background
"blue"))
1877 "Face used when the customize item has been set by a theme."
1878 :group
'custom-magic-faces
)
1880 (defface custom-saved
'((t (:underline t
)))
1881 "Face used when the customize item has been saved."
1882 :group
'custom-magic-faces
)
1883 ;; backward-compatibility alias
1884 (put 'custom-saved-face
'face-alias
'custom-saved
)
1886 (defconst custom-magic-alist
1887 '((nil "#" underline
"\
1888 UNINITIALIZED, you should not see this.")
1889 (unknown "?" italic
"\
1890 UNKNOWN, you should not see this.")
1891 (hidden "-" default
"\
1892 HIDDEN, invoke \"Show\" in the previous line to show." "\
1893 group now hidden, invoke \"Show\", above, to show contents.")
1894 (invalid "x" custom-invalid
"\
1895 INVALID, the displayed value cannot be set.")
1896 (modified "*" custom-modified
"\
1897 EDITED, shown value does not take effect until you set or save it." "\
1898 something in this group has been edited but not set.")
1899 (set "+" custom-set
"\
1900 SET for current session only." "\
1901 something in this group has been set but not saved.")
1902 (changed ":" custom-changed
"\
1903 CHANGED outside Customize; operating on it here may be unreliable." "\
1904 something in this group has been changed outside customize.")
1905 (saved "!" custom-saved
"\
1907 something in this group has been set and saved.")
1908 (themed "o" custom-themed
"\
1910 visible group members are all at standard values.")
1911 (rogue "@" custom-rogue
"\
1912 NO CUSTOMIZATION DATA; not intended to be customized." "\
1913 something in this group is not prepared for customization.")
1914 (standard " " nil
"\
1916 visible group members are all at standard values."))
1917 "Alist of customize option states.
1918 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1920 STATE is one of the following symbols:
1923 For internal use, should never occur.
1925 For internal use, should never occur.
1927 This item is not being displayed.
1929 This item is modified, but has an invalid form.
1931 This item is modified, and has a valid form.
1933 This item has been set but not saved.
1935 The current value of this item has been changed outside Customize.
1937 This item is marked for saving.
1939 This item has no customization information.
1941 This item is unchanged from the standard setting.
1943 MAGIC is a string used to present that state.
1945 FACE is a face used to present the state.
1947 ITEM-DESC is a string describing the state for options.
1949 GROUP-DESC is a string describing the state for groups. If this is
1950 left out, ITEM-DESC will be used.
1952 The string %c in either description will be replaced with the
1953 category of the item. These are `group'. `option', and `face'.
1955 The list should be sorted most significant first.")
1957 (defcustom custom-magic-show
'long
1958 "If non-nil, show textual description of the state.
1959 If `long', show a full-line description, not just one word."
1960 :type
'(choice (const :tag
"no" nil
)
1962 (other :tag
"short" short
))
1963 :group
'custom-buffer
)
1965 (defcustom custom-magic-show-hidden
'(option face
)
1966 "Control whether the State button is shown for hidden items.
1967 The value should be a list with the custom categories where the State
1968 button should be visible. Possible categories are `group', `option',
1970 :type
'(set (const group
) (const option
) (const face
))
1971 :group
'custom-buffer
)
1973 (defcustom custom-magic-show-button nil
1974 "Show a \"magic\" button indicating the state of each customization option."
1976 :group
'custom-buffer
)
1978 (define-widget 'custom-magic
'default
1979 "Show and manipulate state for a customization option."
1981 :action
'widget-parent-action
1984 :value-create
'custom-magic-value-create
1985 :value-delete
'widget-children-value-delete
)
1987 (defun widget-magic-mouse-down-action (widget &optional event
)
1988 ;; Non-nil unless hidden.
1989 (not (eq (widget-get (widget-get (widget-get widget
:parent
) :parent
)
1993 (defun custom-magic-value-create (widget)
1994 "Create compact status report for WIDGET."
1995 (let* ((parent (widget-get widget
:parent
))
1996 (state (widget-get parent
:custom-state
))
1997 (hidden (eq state
'hidden
))
1998 (entry (assq state custom-magic-alist
))
1999 (magic (nth 1 entry
))
2000 (face (nth 2 entry
))
2001 (category (widget-get parent
:custom-category
))
2002 (text (or (and (eq category
'group
)
2005 (form (widget-get parent
:custom-form
))
2007 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text
)
2008 (setq text
(concat (match-string 1 text
)
2009 (symbol-name category
)
2010 (match-string 2 text
))))
2011 (when (and custom-magic-show
2013 (memq category custom-magic-show-hidden
)))
2015 (when (and (eq category
'group
)
2016 (not (and (eq custom-buffer-style
'links
)
2017 (> (widget-get parent
:custom-level
) 1))))
2018 (insert-char ?\
(* custom-buffer-indent
2019 (widget-get parent
:custom-level
))))
2020 (push (widget-create-child-and-convert
2022 :help-echo
"Change the state of this item."
2023 :format
(if hidden
"%t" "%[%t%]")
2024 :button-prefix
'widget-push-button-prefix
2025 :button-suffix
'widget-push-button-suffix
2026 :mouse-down-action
'widget-magic-mouse-down-action
2030 (let ((start (point)))
2031 (if (eq custom-magic-show
'long
)
2033 (insert (symbol-name state
)))
2034 (cond ((eq form
'lisp
)
2036 ((eq form
'mismatch
)
2037 (insert " (mismatch)")))
2038 (put-text-property start
(point) 'face
'custom-state
))
2040 (when (and (eq category
'group
)
2041 (not (and (eq custom-buffer-style
'links
)
2042 (> (widget-get parent
:custom-level
) 1))))
2043 (insert-char ?\
(* custom-buffer-indent
2044 (widget-get parent
:custom-level
))))
2045 (when custom-magic-show-button
2046 (when custom-magic-show
2047 (let ((indent (widget-get parent
:indent
)))
2049 (insert-char ? indent
))))
2050 (push (widget-create-child-and-convert
2052 :mouse-down-action
'widget-magic-mouse-down-action
2056 :help-echo
"Change the state."
2057 :format
(if hidden
"%t" "%[%t%]")
2058 :tag
(if (memq form
'(lisp mismatch
))
2059 (concat "(" magic
")")
2060 (concat "[" magic
"]")))
2063 (widget-put widget
:children children
)))
2065 (defun custom-magic-reset (widget)
2066 "Redraw the :custom-magic property of WIDGET."
2067 (let ((magic (widget-get widget
:custom-magic
)))
2068 (widget-value-set magic
(widget-value magic
))))
2070 ;;; The `custom' Widget.
2072 (defface custom-button
2073 '((((type x w32 mac
) (class color
)) ; Like default modeline
2074 (:box
(:line-width
2 :style released-button
)
2075 :background
"lightgrey" :foreground
"black"))
2078 "Face for custom buffer buttons if `custom-raised-buttons' is non-nil."
2080 :group
'custom-faces
)
2081 ;; backward-compatibility alias
2082 (put 'custom-button-face
'face-alias
'custom-button
)
2084 (defface custom-button-mouse
2085 '((((type x w32 mac
) (class color
))
2086 (:box
(:line-width
2 :style released-button
)
2087 :background
"grey90" :foreground
"black"))
2090 "Mouse face for custom buffer buttons if `custom-raised-buttons' is non-nil."
2092 :group
'custom-faces
)
2094 (defface custom-button-unraised
2095 '((t :inherit underline
))
2096 "Face for custom buffer buttons if `custom-raised-buttons' is nil."
2098 :group
'custom-faces
)
2101 (if custom-raised-buttons
'custom-button
'custom-button-unraised
))
2103 (setq custom-button-mouse
2104 (if custom-raised-buttons
'custom-button-mouse
'highlight
))
2106 (defface custom-button-pressed
2107 '((((type x w32 mac
) (class color
))
2108 (:box
(:line-width
2 :style pressed-button
)
2109 :background
"lightgrey" :foreground
"black"))
2111 (:inverse-video t
)))
2112 "Face for pressed custom buttons if `custom-raised-buttons' is non-nil."
2114 :group
'custom-faces
)
2115 ;; backward-compatibility alias
2116 (put 'custom-button-pressed-face
'face-alias
'custom-button-pressed
)
2118 (defface custom-button-pressed-unraised
2119 '((default :inherit custom-button-unraised
)
2120 (((class color
) (background light
)) :foreground
"magenta4")
2121 (((class color
) (background dark
)) :foreground
"violet"))
2122 "Face for pressed custom buttons if `custom-raised-buttons' is nil."
2124 :group
'custom-faces
)
2126 (setq custom-button-pressed
2127 (if custom-raised-buttons
2128 'custom-button-pressed
2129 'custom-button-pressed-unraised
))
2131 (defface custom-documentation
'((t nil
))
2132 "Face used for documentation strings in customization buffers."
2133 :group
'custom-faces
)
2134 ;; backward-compatibility alias
2135 (put 'custom-documentation-face
'face-alias
'custom-documentation
)
2137 (defface custom-state
'((((class color
)
2139 (:foreground
"lime green"))
2142 (:foreground
"dark green"))
2144 "Face used for State descriptions in the customize buffer."
2145 :group
'custom-faces
)
2146 ;; backward-compatibility alias
2147 (put 'custom-state-face
'face-alias
'custom-state
)
2149 (defface custom-link
2150 '((t :inherit link
))
2151 "Face for links in customization buffers."
2153 :group
'custom-faces
)
2155 (define-widget 'custom
'default
2156 "Customize a user option."
2158 :convert-widget
'custom-convert-widget
2159 :notify
'custom-notify
2162 :custom-state
'hidden
2163 :documentation-property
'widget-subclass-responsibility
2164 :value-create
'widget-subclass-responsibility
2165 :value-delete
'widget-children-value-delete
2166 :value-get
'widget-value-value-get
2167 :validate
'widget-children-validate
2168 :match
(lambda (widget value
) (symbolp value
)))
2170 (defun custom-convert-widget (widget)
2171 "Initialize :value and :tag from :args in WIDGET."
2172 (let ((args (widget-get widget
:args
)))
2174 (widget-put widget
:value
(widget-apply widget
2175 :value-to-internal
(car args
)))
2176 (widget-put widget
:tag
(custom-unlispify-tag-name (car args
)))
2177 (widget-put widget
:args nil
)))
2180 (defun custom-notify (widget &rest args
)
2181 "Keep track of changes."
2182 (let ((state (widget-get widget
:custom-state
)))
2183 (unless (eq state
'modified
)
2184 (unless (memq state
'(nil unknown hidden
))
2185 (widget-put widget
:custom-state
'modified
))
2186 (custom-magic-reset widget
)
2187 (apply 'widget-default-notify widget args
))))
2189 (defun custom-redraw (widget)
2190 "Redraw WIDGET with current settings."
2191 (let ((line (count-lines (point-min) (point)))
2192 (column (current-column))
2194 (from (marker-position (widget-get widget
:from
)))
2195 (to (marker-position (widget-get widget
:to
))))
2197 (widget-value-set widget
(widget-value widget
))
2198 (custom-redraw-magic widget
))
2199 (when (and (>= pos from
) (<= pos to
))
2204 (goto-line (1+ line
)))
2205 (move-to-column column
))
2208 (defun custom-redraw-magic (widget)
2209 "Redraw WIDGET state with current settings."
2211 (let ((magic (widget-get widget
:custom-magic
)))
2213 (widget-value-set magic
(widget-value magic
))
2214 (when (setq widget
(widget-get widget
:group
))
2215 (custom-group-state-update widget
)))
2217 (setq widget nil
)))))
2220 (defun custom-show (widget value
)
2221 "Non-nil if WIDGET should be shown with VALUE by default."
2222 (let ((show (widget-get widget
:custom-show
)))
2228 (funcall show widget value
)))))
2230 (defun custom-load-widget (widget)
2231 "Load all dependencies for WIDGET."
2232 (custom-load-symbol (widget-value widget
)))
2234 (defun custom-unloaded-symbol-p (symbol)
2235 "Return non-nil if the dependencies of SYMBOL have not yet been loaded."
2237 (loads (get symbol
'custom-loads
))
2240 (setq load
(car loads
)
2242 (cond ((symbolp load
)
2243 (unless (featurep load
)
2245 ((assoc load load-history
))
2246 ((assoc (locate-library load
) load-history
)
2252 (defun custom-unloaded-widget-p (widget)
2253 "Return non-nil if the dependencies of WIDGET have not yet been loaded."
2254 (custom-unloaded-symbol-p (widget-value widget
)))
2256 (defun custom-toggle-hide (widget)
2257 "Toggle visibility of WIDGET."
2258 (custom-load-widget widget
)
2259 (let ((state (widget-get widget
:custom-state
)))
2260 (cond ((memq state
'(invalid modified
))
2261 (error "There are unset changes"))
2263 (widget-put widget
:custom-state
'unknown
))
2265 (widget-put widget
:documentation-shown nil
)
2266 (widget-put widget
:custom-state
'hidden
)))
2267 (custom-redraw widget
)
2270 (defun custom-toggle-parent (widget &rest ignore
)
2271 "Toggle visibility of parent of WIDGET."
2272 (custom-toggle-hide (widget-get widget
:parent
)))
2274 (defun custom-add-see-also (widget &optional prefix
)
2275 "Add `See also ...' to WIDGET if there are any links.
2276 Insert PREFIX first if non-nil."
2277 (let* ((symbol (widget-get widget
:value
))
2278 (links (get symbol
'custom-links
))
2279 (many (> (length links
) 2))
2280 (buttons (widget-get widget
:buttons
))
2281 (indent (widget-get widget
:indent
)))
2284 (insert-char ?\ indent
))
2287 (insert "See also ")
2289 (push (widget-create-child-and-convert
2291 :button-face
'custom-link
2292 :mouse-face
'highlight
2293 :pressed-face
'highlight
)
2295 (setq links
(cdr links
))
2304 (widget-put widget
:buttons buttons
))))
2306 (defun custom-add-parent-links (widget &optional initial-string
2308 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
2309 The value is non-nil if any parents were found.
2310 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
2311 (let ((name (widget-value widget
))
2312 (type (widget-type widget
))
2313 (buttons (widget-get widget
:buttons
))
2316 (insert (or initial-string
"Groups:"))
2317 (mapatoms (lambda (symbol)
2318 (when (member (list name type
) (get symbol
'custom-group
))
2320 (push (widget-create-child-and-convert
2321 widget
'custom-group-link
2322 :tag
(custom-unlispify-tag-name symbol
)
2325 (setq parents
(cons symbol parents
)))))
2326 (and (null (get name
'custom-links
)) ;No links of its own.
2327 (= (length parents
) 1) ;A single parent.
2328 (let* ((links (delq nil
(mapcar (lambda (w)
2329 (unless (eq (widget-type w
)
2332 (get (car parents
) 'custom-links
))))
2333 (many (> (length links
) 2)))
2336 (left-margin (+ left-margin
2)))
2337 (insert "\n" (or doc-initial-string
"Group documentation:") " ")
2339 (push (widget-create-child-and-convert
2341 :button-face
'custom-link
2342 :mouse-face
'highlight
2343 :pressed-face
'highlight
)
2345 (setq links
(cdr links
))
2354 (fill-region-as-paragraph pt
(point))
2355 (delete-to-left-margin (1+ pt
) (+ pt
2))))))
2358 (delete-region start
(point)))
2359 (widget-put widget
:buttons buttons
)
2362 ;;; The `custom-comment' Widget.
2364 ;; like the editable field
2365 (defface custom-comment
'((((type tty
))
2366 :background
"yellow3"
2367 :foreground
"black")
2368 (((class grayscale color
)
2370 :background
"gray85")
2371 (((class grayscale color
)
2373 :background
"dim gray")
2376 "Face used for comments on variables or faces"
2378 :group
'custom-faces
)
2379 ;; backward-compatibility alias
2380 (put 'custom-comment-face
'face-alias
'custom-comment
)
2382 ;; like font-lock-comment-face
2383 (defface custom-comment-tag
2384 '((((class color
) (background dark
)) (:foreground
"gray80"))
2385 (((class color
) (background light
)) (:foreground
"blue4"))
2386 (((class grayscale
) (background light
))
2387 (:foreground
"DimGray" :weight bold
:slant italic
))
2388 (((class grayscale
) (background dark
))
2389 (:foreground
"LightGray" :weight bold
:slant italic
))
2391 "Face used for variables or faces comment tags"
2392 :group
'custom-faces
)
2393 ;; backward-compatibility alias
2394 (put 'custom-comment-tag-face
'face-alias
'custom-comment-tag
)
2396 (define-widget 'custom-comment
'string
2399 :help-echo
"Edit a comment here."
2400 :sample-face
'custom-comment-tag-face
2401 :value-face
'custom-comment-face
2403 :create
'custom-comment-create
)
2405 (defun custom-comment-create (widget)
2406 (let* ((null-comment (equal "" (widget-value widget
))))
2407 (if (or (widget-get (widget-get widget
:parent
) :comment-shown
)
2409 (widget-default-create widget
)
2410 ;; `widget-default-delete' expects markers in these slots --
2411 ;; maybe it shouldn't.
2412 (widget-put widget
:from
(point-marker))
2413 (widget-put widget
:to
(point-marker)))))
2415 (defun custom-comment-hide (widget)
2416 (widget-put (widget-get widget
:parent
) :comment-shown nil
))
2418 ;; Those functions are for the menu. WIDGET is NOT the comment widget. It's
2419 ;; the global custom one
2420 (defun custom-comment-show (widget)
2421 (widget-put widget
:comment-shown t
)
2422 (custom-redraw widget
)
2425 (defun custom-comment-invisible-p (widget)
2426 (let ((val (widget-value (widget-get widget
:comment-widget
))))
2428 (not (widget-get widget
:comment-shown
)))))
2430 ;;; The `custom-variable' Widget.
2432 ;; When this was underlined blue, users confused it with a
2433 ;; Mosaic-style hyperlink...
2434 (defface custom-variable-tag
2437 (:foreground
"light blue" :weight bold
))
2438 (((min-colors 88) (class color
)
2440 (:foreground
"blue1" :weight bold
))
2443 (:foreground
"blue" :weight bold
))
2445 "Face used for unpushable variable tags."
2446 :group
'custom-faces
)
2447 ;; backward-compatibility alias
2448 (put 'custom-variable-tag-face
'face-alias
'custom-variable-tag
)
2450 (defface custom-variable-button
'((t (:underline t
:weight bold
)))
2451 "Face used for pushable variable tags."
2452 :group
'custom-faces
)
2453 ;; backward-compatibility alias
2454 (put 'custom-variable-button-face
'face-alias
'custom-variable-button
)
2456 (defcustom custom-variable-default-form
'edit
2457 "Default form of displaying variable values."
2458 :type
'(choice (const edit
)
2460 :group
'custom-buffer
2463 (defun custom-variable-documentation (variable)
2464 "Return documentation of VARIABLE for use in Custom buffer.
2465 Normally just return the docstring. But if VARIABLE automatically
2466 becomes buffer local when set, append a message to that effect."
2467 (if (and (local-variable-if-set-p variable
)
2468 (or (not (local-variable-p variable
))
2470 (local-variable-if-set-p variable
))))
2471 (concat (documentation-property variable
'variable-documentation
)
2473 This variable automatically becomes buffer-local when set outside Custom.
2474 However, setting it through Custom sets the default value.")
2475 (documentation-property variable
'variable-documentation
)))
2477 (define-widget 'custom-variable
'custom
2478 "Customize variable."
2480 :help-echo
"Set or reset this variable."
2481 :documentation-property
#'custom-variable-documentation
2482 :custom-category
'option
2484 :custom-menu
'custom-variable-menu-create
2485 :custom-form nil
; defaults to value of `custom-variable-default-form'
2486 :value-create
'custom-variable-value-create
2487 :action
'custom-variable-action
2488 :custom-set
'custom-variable-set
2489 :custom-mark-to-save
'custom-variable-mark-to-save
2490 :custom-reset-current
'custom-redraw
2491 :custom-reset-saved
'custom-variable-reset-saved
2492 :custom-reset-standard
'custom-variable-reset-standard
2493 :custom-mark-to-reset-standard
'custom-variable-mark-to-reset-standard
2494 :custom-standard-value
'custom-variable-standard-value
2495 :custom-state-set-and-redraw
'custom-variable-state-set-and-redraw
)
2497 (defun custom-variable-type (symbol)
2498 "Return a widget suitable for editing the value of SYMBOL.
2499 If SYMBOL has a `custom-type' property, use that.
2500 Otherwise, try matching SYMBOL against `custom-guess-name-alist' and
2501 try matching its doc string against `custom-guess-doc-alist'."
2502 (let* ((type (or (get symbol
'custom-type
)
2503 (and (not (get symbol
'standard-value
))
2504 (custom-guess-type symbol
))
2506 (options (get symbol
'custom-options
))
2507 (tmp (if (listp type
)
2508 (copy-sequence type
)
2511 (widget-put tmp
:options options
))
2514 (defun custom-variable-value-create (widget)
2515 "Here is where you edit the variable's value."
2516 (custom-load-widget widget
)
2517 (unless (widget-get widget
:custom-form
)
2518 (widget-put widget
:custom-form custom-variable-default-form
))
2519 (let* ((buttons (widget-get widget
:buttons
))
2520 (children (widget-get widget
:children
))
2521 (form (widget-get widget
:custom-form
))
2522 (state (widget-get widget
:custom-state
))
2523 (symbol (widget-get widget
:value
))
2524 (tag (widget-get widget
:tag
))
2525 (type (custom-variable-type symbol
))
2526 (conv (widget-convert type
))
2527 (get (or (get symbol
'custom-get
) 'default-value
))
2528 (prefix (widget-get widget
:custom-prefix
))
2529 (last (widget-get widget
:custom-last
))
2530 (value (if (default-boundp symbol
)
2531 (funcall get symbol
)
2532 (widget-get conv
:value
))))
2533 ;; If the widget is new, the child determines whether it is hidden.
2535 ((custom-show type value
)
2536 (setq state
'unknown
))
2538 (setq state
'hidden
)))
2539 ;; If we don't know the state, see if we need to edit it in lisp form.
2540 (when (eq state
'unknown
)
2541 (unless (widget-apply conv
:match value
)
2542 ;; (widget-apply (widget-convert type) :match value)
2543 (setq form
'mismatch
)))
2544 ;; Now we can create the child widget.
2545 (cond ((eq custom-buffer-style
'tree
)
2546 (insert prefix
(if last
" `--- " " |--- "))
2547 (push (widget-create-child-and-convert
2548 widget
'custom-browse-variable-tag
)
2550 (insert " " tag
"\n")
2551 (widget-put widget
:buttons buttons
))
2553 ;; Indicate hidden value.
2554 (push (widget-create-child-and-convert
2557 :sample-face
'custom-variable-tag-face
2561 (push (widget-create-child-and-convert
2563 :help-echo
"Show the value of this option."
2565 :action
'custom-toggle-parent
2568 ((memq form
'(lisp mismatch
))
2569 ;; In lisp mode edit the saved value when possible.
2570 (let* ((value (cond ((get symbol
'saved-value
)
2571 (car (get symbol
'saved-value
)))
2572 ((get symbol
'standard-value
)
2573 (car (get symbol
'standard-value
)))
2574 ((default-boundp symbol
)
2575 (custom-quote (funcall get symbol
)))
2577 (custom-quote (widget-get conv
:value
))))))
2578 (insert (symbol-name symbol
) ": ")
2579 (push (widget-create-child-and-convert
2581 :help-echo
"Hide the value of this option."
2584 :action
'custom-toggle-parent
2588 (push (widget-create-child-and-convert
2590 :button-face
'custom-variable-button-face
2592 :tag
(symbol-name symbol
)
2598 (let* ((format (widget-get type
:format
))
2599 tag-format value-format
)
2600 (unless (string-match ":" format
)
2601 (error "Bad format"))
2602 (setq tag-format
(substring format
0 (match-end 0)))
2603 (setq value-format
(substring format
(match-end 0)))
2604 (push (widget-create-child-and-convert
2607 :action
'custom-tag-action
2608 :help-echo
"Change value of this option."
2609 :mouse-down-action
'custom-tag-mouse-down-action
2610 :button-face
'custom-variable-button-face
2611 :sample-face
'custom-variable-tag-face
2615 (push (widget-create-child-and-convert
2617 :help-echo
"Hide the value of this option."
2620 :action
'custom-toggle-parent
2623 (push (widget-create-child-and-convert
2625 :format value-format
2628 (unless (eq custom-buffer-style
'tree
)
2629 (unless (eq (preceding-char) ?
\n)
2630 (widget-insert "\n"))
2631 ;; Create the magic button.
2632 (let ((magic (widget-create-child-and-convert
2633 widget
'custom-magic nil
)))
2634 (widget-put widget
:custom-magic magic
)
2635 (push magic buttons
))
2636 (widget-put widget
:buttons buttons
)
2637 ;; Insert documentation.
2638 (widget-put widget
:documentation-indent
3)
2639 (widget-add-documentation-string-button
2640 widget
:visibility-widget
'custom-visibility
)
2642 ;; The comment field
2643 (unless (eq state
'hidden
)
2644 (let* ((comment (get symbol
'variable-comment
))
2646 (widget-create-child-and-convert
2647 widget
'custom-comment
2649 :value
(or comment
""))))
2650 (widget-put widget
:comment-widget comment-widget
)
2651 ;; Don't push it !!! Custom assumes that the first child is the
2653 (setq children
(append children
(list comment-widget
)))))
2654 ;; Update the rest of the properties properties.
2655 (widget-put widget
:custom-form form
)
2656 (widget-put widget
:children children
)
2657 ;; Now update the state.
2658 (if (eq state
'hidden
)
2659 (widget-put widget
:custom-state state
)
2660 (custom-variable-state-set widget
))
2662 (unless (eq state
'hidden
)
2663 (when (eq (widget-get widget
:custom-level
) 1)
2664 (custom-add-parent-links widget
))
2665 (custom-add-see-also widget
)))))
2667 (defun custom-tag-action (widget &rest args
)
2668 "Pass :action to first child of WIDGET's parent."
2669 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2672 (defun custom-tag-mouse-down-action (widget &rest args
)
2673 "Pass :mouse-down-action to first child of WIDGET's parent."
2674 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2675 :mouse-down-action args
))
2677 (defun custom-variable-state-set (widget)
2678 "Set the state of WIDGET."
2679 (let* ((symbol (widget-value widget
))
2680 (get (or (get symbol
'custom-get
) 'default-value
))
2681 (value (if (default-boundp symbol
)
2682 (funcall get symbol
)
2683 (widget-get widget
:value
)))
2684 (comment (get symbol
'variable-comment
))
2687 (state (cond ((progn (setq tmp
(get symbol
'customized-value
))
2689 (get symbol
'customized-variable-comment
))
2691 (if (condition-case nil
2692 (and (equal value
(eval (car tmp
)))
2693 (equal comment temp
))
2697 ((progn (setq tmp
(get symbol
'theme-value
))
2698 (setq temp
(get symbol
'saved-variable-comment
))
2700 (if (condition-case nil
2701 (and (equal comment temp
)
2704 (car (custom-variable-theme-value
2708 ((eq (caar tmp
) 'user
) 'saved
)
2709 ((eq (caar tmp
) 'changed
)
2710 (if (condition-case nil
2714 (car (get symbol
'standard-value
)))))
2716 ;; The value was originally set outside
2717 ;; custom, but it was set to the standard
2718 ;; value (probably an autoloaded defcustom).
2723 ((setq tmp
(get symbol
'standard-value
))
2724 (if (condition-case nil
2725 (and (equal value
(eval (car tmp
)))
2726 (equal comment nil
))
2731 (widget-put widget
:custom-state state
)))
2733 (defun custom-variable-standard-value (widget)
2734 (get (widget-value widget
) 'standard-value
))
2736 (defvar custom-variable-menu
2737 `(("Set for Current Session" custom-variable-set
2739 (eq (widget-get widget
:custom-state
) 'modified
)))
2740 ;; Note that in all the backquoted code in this file, we test
2741 ;; init-file-user rather than user-init-file. This is in case
2742 ;; cus-edit is loaded by something in site-start.el, because
2743 ;; user-init-file is not set at that stage.
2744 ;; http://lists.gnu.org/archive/html/emacs-devel/2007-10/msg00310.html
2745 ,@(when (or custom-file init-file-user
)
2746 '(("Save for Future Sessions" custom-variable-save
2748 (memq (widget-get widget
:custom-state
)
2749 '(modified set changed rogue
))))))
2750 ("Undo Edits" custom-redraw
2752 (and (default-boundp (widget-value widget
))
2753 (memq (widget-get widget
:custom-state
) '(modified changed
)))))
2754 ("Reset to Saved" custom-variable-reset-saved
2756 (and (or (get (widget-value widget
) 'saved-value
)
2757 (get (widget-value widget
) 'saved-variable-comment
))
2758 (memq (widget-get widget
:custom-state
)
2759 '(modified set changed rogue
)))))
2760 ,@(when (or custom-file init-file-user
)
2761 '(("Erase Customization" custom-variable-reset-standard
2763 (and (get (widget-value widget
) 'standard-value
)
2764 (memq (widget-get widget
:custom-state
)
2765 '(modified set changed saved rogue
)))))))
2766 ("Set to Backup Value" custom-variable-reset-backup
2768 (get (widget-value widget
) 'backup-value
)))
2769 ("---" ignore ignore
)
2770 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
2771 ("---" ignore ignore
)
2772 ("Show Current Value" custom-variable-edit
2774 (eq (widget-get widget
:custom-form
) 'lisp
)))
2775 ("Show Saved Lisp Expression" custom-variable-edit-lisp
2777 (eq (widget-get widget
:custom-form
) 'edit
))))
2778 "Alist of actions for the `custom-variable' widget.
2779 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2780 the menu entry, ACTION is the function to call on the widget when the
2781 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2782 widget as an argument, and returns non-nil if ACTION is valid on that
2783 widget. If FILTER is nil, ACTION is always valid.")
2785 (defun custom-variable-action (widget &optional event
)
2786 "Show the menu for `custom-variable' WIDGET.
2787 Optional EVENT is the location for the menu."
2788 (if (eq (widget-get widget
:custom-state
) 'hidden
)
2789 (custom-toggle-hide widget
)
2790 (unless (eq (widget-get widget
:custom-state
) 'modified
)
2791 (custom-variable-state-set widget
))
2792 (custom-redraw-magic widget
)
2793 (let* ((completion-ignore-case t
)
2794 (answer (widget-choose (concat "Operation on "
2795 (custom-unlispify-tag-name
2796 (widget-get widget
:value
)))
2797 (custom-menu-filter custom-variable-menu
2801 (funcall answer widget
)))))
2803 (defun custom-variable-edit (widget)
2804 "Edit value of WIDGET."
2805 (widget-put widget
:custom-state
'unknown
)
2806 (widget-put widget
:custom-form
'edit
)
2807 (custom-redraw widget
))
2809 (defun custom-variable-edit-lisp (widget)
2810 "Edit the Lisp representation of the value of WIDGET."
2811 (widget-put widget
:custom-state
'unknown
)
2812 (widget-put widget
:custom-form
'lisp
)
2813 (custom-redraw widget
))
2815 (defun custom-variable-set (widget)
2816 "Set the current value for the variable being edited by WIDGET."
2817 (let* ((form (widget-get widget
:custom-form
))
2818 (state (widget-get widget
:custom-state
))
2819 (child (car (widget-get widget
:children
)))
2820 (symbol (widget-value widget
))
2821 (set (or (get symbol
'custom-set
) 'set-default
))
2822 (comment-widget (widget-get widget
:comment-widget
))
2823 (comment (widget-value comment-widget
))
2825 (cond ((eq state
'hidden
)
2826 (error "Cannot set hidden variable"))
2827 ((setq val
(widget-apply child
:validate
))
2828 (goto-char (widget-get val
:from
))
2829 (error "%s" (widget-get val
:error
)))
2830 ((memq form
'(lisp mismatch
))
2831 (when (equal comment
"")
2833 ;; Make the comment invisible by hand if it's empty
2834 (custom-comment-hide comment-widget
))
2835 (custom-variable-backup-value widget
)
2836 (custom-push-theme 'theme-value symbol
'user
2837 'set
(custom-quote (widget-value child
)))
2838 (funcall set symbol
(eval (setq val
(widget-value child
))))
2839 (put symbol
'customized-value
(list val
))
2840 (put symbol
'variable-comment comment
)
2841 (put symbol
'customized-variable-comment comment
))
2843 (when (equal comment
"")
2845 ;; Make the comment invisible by hand if it's empty
2846 (custom-comment-hide comment-widget
))
2847 (custom-variable-backup-value widget
)
2848 (custom-push-theme 'theme-value symbol
'user
2849 'set
(custom-quote (widget-value child
)))
2850 (funcall set symbol
(setq val
(widget-value child
)))
2851 (put symbol
'customized-value
(list (custom-quote val
)))
2852 (put symbol
'variable-comment comment
)
2853 (put symbol
'customized-variable-comment comment
)))
2854 (custom-variable-state-set widget
)
2855 (custom-redraw-magic widget
)))
2857 (defun custom-variable-mark-to-save (widget)
2858 "Set value and mark for saving the variable edited by WIDGET."
2859 (let* ((form (widget-get widget
:custom-form
))
2860 (state (widget-get widget
:custom-state
))
2861 (child (car (widget-get widget
:children
)))
2862 (symbol (widget-value widget
))
2863 (set (or (get symbol
'custom-set
) 'set-default
))
2864 (comment-widget (widget-get widget
:comment-widget
))
2865 (comment (widget-value comment-widget
))
2867 (cond ((eq state
'hidden
)
2868 (error "Cannot set hidden variable"))
2869 ((setq val
(widget-apply child
:validate
))
2870 (goto-char (widget-get val
:from
))
2871 (error "Saving %s: %s" symbol
(widget-get val
:error
)))
2872 ((memq form
'(lisp mismatch
))
2873 (when (equal comment
"")
2875 ;; Make the comment invisible by hand if it's empty
2876 (custom-comment-hide comment-widget
))
2877 (put symbol
'saved-value
(list (widget-value child
)))
2878 (custom-push-theme 'theme-value symbol
'user
2879 'set
(custom-quote (widget-value child
)))
2880 (funcall set symbol
(eval (widget-value child
)))
2881 (put symbol
'variable-comment comment
)
2882 (put symbol
'saved-variable-comment comment
))
2884 (when (equal comment
"")
2886 ;; Make the comment invisible by hand if it's empty
2887 (custom-comment-hide comment-widget
))
2888 (put symbol
'saved-value
2889 (list (custom-quote (widget-value child
))))
2890 (custom-push-theme 'theme-value symbol
'user
2891 'set
(custom-quote (widget-value child
)))
2892 (funcall set symbol
(widget-value child
))
2893 (put symbol
'variable-comment comment
)
2894 (put symbol
'saved-variable-comment comment
)))
2895 (put symbol
'customized-value nil
)
2896 (put symbol
'customized-variable-comment nil
)))
2898 (defsubst custom-variable-state-set-and-redraw
(widget)
2899 "Set state of variable widget WIDGET and redraw with current settings."
2900 (custom-variable-state-set widget
)
2901 (custom-redraw-magic widget
))
2903 (defun custom-variable-save (widget)
2904 "Save value of variable edited by widget WIDGET."
2905 (custom-variable-mark-to-save widget
)
2907 (custom-variable-state-set-and-redraw widget
))
2909 (defun custom-variable-reset-saved (widget)
2910 "Restore the saved value for the variable being edited by WIDGET.
2911 This also updates the buffer to show that value.
2912 The value that was current before this operation
2913 becomes the backup value, so you can get it again."
2914 (let* ((symbol (widget-value widget
))
2915 (set (or (get symbol
'custom-set
) 'set-default
))
2916 (value (get symbol
'saved-value
))
2917 (comment (get symbol
'saved-variable-comment
)))
2918 (cond ((or value comment
)
2919 (put symbol
'variable-comment comment
)
2920 (custom-variable-backup-value widget
)
2921 (custom-push-theme 'theme-value symbol
'user
'set
(car-safe value
))
2923 (funcall set symbol
(eval (car value
)))
2926 (error "No saved value for %s" symbol
)))
2927 (put symbol
'customized-value nil
)
2928 (put symbol
'customized-variable-comment nil
)
2929 (widget-put widget
:custom-state
'unknown
)
2930 ;; This call will possibly make the comment invisible
2931 (custom-redraw widget
)))
2933 (defun custom-variable-mark-to-reset-standard (widget)
2934 "Mark to restore standard setting for the variable edited by widget WIDGET.
2935 If `custom-reset-standard-variables-list' is nil, save, reset and
2936 redraw the widget immediately."
2937 (let* ((symbol (widget-value widget
)))
2938 (if (get symbol
'standard-value
)
2939 (custom-variable-backup-value widget
)
2940 (error "No standard setting known for %S" symbol
))
2941 (put symbol
'variable-comment nil
)
2942 (put symbol
'customized-value nil
)
2943 (put symbol
'customized-variable-comment nil
)
2944 (custom-push-theme 'theme-value symbol
'user
'reset
)
2945 (custom-theme-recalc-variable symbol
)
2946 (if (and custom-reset-standard-variables-list
2947 (or (get symbol
'saved-value
) (get symbol
'saved-variable-comment
)))
2949 (put symbol
'saved-value nil
)
2950 (put symbol
'saved-variable-comment nil
)
2951 ;; Append this to `custom-reset-standard-variables-list' to
2952 ;; have `custom-reset-standard-save-and-update' save setting
2953 ;; to the file, update the widget's state, and redraw it.
2954 (setq custom-reset-standard-variables-list
2955 (cons widget custom-reset-standard-variables-list
)))
2956 (when (or (get symbol
'saved-value
) (get symbol
'saved-variable-comment
))
2957 (put symbol
'saved-value nil
)
2958 (put symbol
'saved-variable-comment nil
)
2960 (widget-put widget
:custom-state
'unknown
)
2961 ;; This call will possibly make the comment invisible
2962 (custom-redraw widget
))))
2964 (defun custom-variable-reset-standard (widget)
2965 "Restore standard setting for the variable edited by WIDGET.
2966 This operation eliminates any saved setting for the variable,
2967 restoring it to the state of a variable that has never been customized.
2968 The value that was current before this operation
2969 becomes the backup value, so you can get it again."
2970 (let (custom-reset-standard-variables-list)
2971 (custom-variable-mark-to-reset-standard widget
)))
2973 (defun custom-variable-backup-value (widget)
2974 "Back up the current value for WIDGET's variable.
2975 The backup value is kept in the car of the `backup-value' property."
2976 (let* ((symbol (widget-value widget
))
2977 (get (or (get symbol
'custom-get
) 'default-value
))
2978 (type (custom-variable-type symbol
))
2979 (conv (widget-convert type
))
2980 (value (if (default-boundp symbol
)
2981 (funcall get symbol
)
2982 (widget-get conv
:value
))))
2983 (put symbol
'backup-value
(list value
))))
2985 (defun custom-variable-reset-backup (widget)
2986 "Restore the backup value for the variable being edited by WIDGET.
2987 The value that was current before this operation
2988 becomes the backup value, so you can use this operation repeatedly
2989 to switch between two values."
2990 (let* ((symbol (widget-value widget
))
2991 (set (or (get symbol
'custom-set
) 'set-default
))
2992 (value (get symbol
'backup-value
))
2993 (comment-widget (widget-get widget
:comment-widget
))
2994 (comment (widget-value comment-widget
)))
2997 (custom-variable-backup-value widget
)
2998 (custom-push-theme 'theme-value symbol
'user
'set value
)
3000 (funcall set symbol
(car value
))
3002 (error "No backup value for %s" symbol
))
3003 (put symbol
'customized-value
(list (car value
)))
3004 (put symbol
'variable-comment comment
)
3005 (put symbol
'customized-variable-comment comment
)
3006 (custom-variable-state-set widget
)
3007 ;; This call will possibly make the comment invisible
3008 (custom-redraw widget
)))
3010 ;;; The `custom-visibility' Widget
3012 (define-widget 'custom-visibility
'visibility
3013 "Show or hide a documentation string."
3014 :button-face
'custom-visibility
3015 :pressed-face
'custom-visibility
3016 :mouse-face
'highlight
3017 :pressed-face
'highlight
)
3019 (defface custom-visibility
3020 '((t :height
0.8 :inherit link
))
3021 "Face for the `custom-visibility' widget."
3023 :group
'custom-faces
)
3025 ;;; The `custom-face-edit' Widget.
3027 (define-widget 'custom-face-edit
'checklist
3028 "Edit face attributes."
3032 :button-args
'(:help-echo
"Control whether this attribute has any effect.")
3033 :value-to-internal
'custom-face-edit-fix-value
3034 :match
(lambda (widget value
)
3035 (widget-checklist-match widget
3036 (custom-face-edit-fix-value widget value
)))
3037 :convert-widget
'custom-face-edit-convert-widget
3038 :args
(mapcar (lambda (att)
3041 :sibling-args
(widget-get (nth 1 att
) :sibling-args
)
3042 (list 'const
:format
"" :value
(nth 0 att
))
3044 custom-face-attributes
))
3046 (defun custom-face-edit-fix-value (widget value
)
3047 "Ignoring WIDGET, convert :bold and :italic in VALUE to new form.
3048 Also change :reverse-video to :inverse-video."
3052 (let ((key (car value
))
3053 (val (car (cdr value
))))
3054 (cond ((eq key
:italic
)
3055 (push :slant result
)
3056 (push (if val
'italic
'normal
) result
))
3058 (push :weight result
)
3059 (push (if val
'bold
'normal
) result
))
3060 ((eq key
:reverse-video
)
3061 (push :inverse-video result
)
3065 (push val result
))))
3066 (setq value
(cdr (cdr value
))))
3067 (setq result
(nreverse result
))
3071 (defun custom-face-edit-convert-widget (widget)
3072 "Convert :args as widget types in WIDGET."
3075 :args
(mapcar (lambda (arg)
3077 :deactivate
'custom-face-edit-deactivate
3078 :activate
'custom-face-edit-activate
3079 :delete
'custom-face-edit-delete
))
3080 (widget-get widget
:args
)))
3083 (defun custom-face-edit-deactivate (widget)
3084 "Make face widget WIDGET inactive for user modifications."
3085 (unless (widget-get widget
:inactive
)
3086 (let ((tag (custom-face-edit-attribute-tag widget
))
3087 (from (copy-marker (widget-get widget
:from
)))
3088 (value (widget-value widget
))
3089 (inhibit-read-only t
)
3090 (inhibit-modification-hooks t
))
3093 (widget-default-delete widget
)
3094 (insert tag
": *\n")
3095 (widget-put widget
:inactive
3096 (cons value
(cons from
(- (point) from
))))))))
3098 (defun custom-face-edit-activate (widget)
3099 "Make face widget WIDGET active for user modifications."
3100 (let ((inactive (widget-get widget
:inactive
))
3101 (inhibit-read-only t
)
3102 (inhibit-modification-hooks t
))
3103 (when (consp inactive
)
3105 (goto-char (car (cdr inactive
)))
3106 (delete-region (point) (+ (point) (cdr (cdr inactive
))))
3107 (widget-put widget
:inactive nil
)
3108 (widget-apply widget
:create
)
3109 (widget-value-set widget
(car inactive
))
3112 (defun custom-face-edit-delete (widget)
3113 "Remove WIDGET from the buffer."
3114 (let ((inactive (widget-get widget
:inactive
))
3115 (inhibit-read-only t
)
3116 (inhibit-modification-hooks t
))
3118 ;; Widget is alive, we don't have to do anything special
3119 (widget-default-delete widget
)
3120 ;; WIDGET is already deleted because we did so to inactivate it;
3121 ;; now just get rid of the label we put in its place.
3122 (delete-region (car (cdr inactive
))
3123 (+ (car (cdr inactive
)) (cdr (cdr inactive
))))
3124 (widget-put widget
:inactive nil
))))
3127 (defun custom-face-edit-attribute-tag (widget)
3128 "Returns the first :tag property in WIDGET or one of its children."
3129 (let ((tag (widget-get widget
:tag
)))
3130 (or (and (not (equal tag
"")) tag
)
3131 (let ((children (widget-get widget
:children
)))
3132 (while (and (null tag
) children
)
3133 (setq tag
(custom-face-edit-attribute-tag (pop children
))))
3136 ;;; The `custom-display' Widget.
3138 (define-widget 'custom-display
'menu-choice
3139 "Select a display type."
3142 :help-echo
"Specify frames where the face attributes should be used."
3143 :args
'((const :tag
"all" t
)
3144 (const :tag
"defaults" default
)
3148 :args
((group :sibling-args
(:help-echo
"\
3149 Only match the specified window systems.")
3150 (const :format
"Type: "
3152 (checklist :inline t
3155 :sibling-args
(:help-echo
"\
3156 The X11 Window System.")
3158 (const :format
"PM "
3159 :sibling-args
(:help-echo
"\
3160 OS/2 Presentation Manager.")
3162 (const :format
"W32 "
3163 :sibling-args
(:help-echo
"\
3166 (const :format
"MAC "
3167 :sibling-args
(:help-echo
"\
3170 (const :format
"DOS "
3171 :sibling-args
(:help-echo
"\
3174 (const :format
"TTY%n"
3175 :sibling-args
(:help-echo
"\
3176 Plain text terminals.")
3178 (group :sibling-args
(:help-echo
"\
3179 Only match the frames with the specified color support.")
3180 (const :format
"Class: "
3182 (checklist :inline t
3184 (const :format
"Color "
3185 :sibling-args
(:help-echo
"\
3186 Match color frames.")
3188 (const :format
"Grayscale "
3189 :sibling-args
(:help-echo
"\
3190 Match grayscale frames.")
3192 (const :format
"Monochrome%n"
3193 :sibling-args
(:help-echo
"\
3194 Match frames with no color support.")
3196 (group :sibling-args
(:help-echo
"\
3197 The minimum number of colors the frame should support.")
3198 (const :format
"" min-colors
)
3199 (integer :tag
"Minimum number of colors" ))
3200 (group :sibling-args
(:help-echo
"\
3201 Only match frames with the specified intensity.")
3203 Background brightness: "
3205 (checklist :inline t
3207 (const :format
"Light "
3208 :sibling-args
(:help-echo
"\
3209 Match frames with light backgrounds.")
3211 (const :format
"Dark\n"
3212 :sibling-args
(:help-echo
"\
3213 Match frames with dark backgrounds.")
3215 (group :sibling-args
(:help-echo
"\
3216 Only match frames that support the specified face attributes.")
3217 (const :format
"Supports attributes:" supports
)
3218 (custom-face-edit :inline t
:format
"%n%v"))))))
3220 ;;; The `custom-face' Widget.
3222 (defface custom-face-tag
3223 `((t (:weight bold
:height
1.2 :inherit variable-pitch
)))
3224 "Face used for face tags."
3225 :group
'custom-faces
)
3226 ;; backward-compatibility alias
3227 (put 'custom-face-tag-face
'face-alias
'custom-face-tag
)
3229 (defcustom custom-face-default-form
'selected
3230 "Default form of displaying face definition."
3231 :type
'(choice (const all
)
3234 :group
'custom-buffer
3237 (define-widget 'custom-face
'custom
3239 :sample-face
'custom-face-tag-face
3240 :help-echo
"Set or reset this face."
3241 :documentation-property
#'face-doc-string
3242 :value-create
'custom-face-value-create
3243 :action
'custom-face-action
3244 :custom-category
'face
3245 :custom-form nil
; defaults to value of `custom-face-default-form'
3246 :custom-set
'custom-face-set
3247 :custom-mark-to-save
'custom-face-mark-to-save
3248 :custom-reset-current
'custom-redraw
3249 :custom-reset-saved
'custom-face-reset-saved
3250 :custom-reset-standard
'custom-face-reset-standard
3251 :custom-mark-to-reset-standard
'custom-face-mark-to-reset-standard
3252 :custom-standard-value
'custom-face-standard-value
3253 :custom-state-set-and-redraw
'custom-face-state-set-and-redraw
3254 :custom-menu
'custom-face-menu-create
)
3256 (define-widget 'custom-face-all
'editable-list
3257 "An editable list of display specifications and attributes."
3258 :entry-format
"%i %d %v"
3259 :insert-button-args
'(:help-echo
"Insert new display specification here.")
3260 :append-button-args
'(:help-echo
"Append new display specification here.")
3261 :delete-button-args
'(:help-echo
"Delete this display specification.")
3262 :args
'((group :format
"%v" custom-display custom-face-edit
)))
3264 (defconst custom-face-all
(widget-convert 'custom-face-all
)
3265 "Converted version of the `custom-face-all' widget.")
3267 (define-widget 'custom-display-unselected
'item
3268 "A display specification that doesn't match the selected display."
3269 :match
'custom-display-unselected-match
)
3271 (defun custom-display-unselected-match (widget value
)
3272 "Non-nil if VALUE is an unselected display specification."
3273 (not (face-spec-set-match-display value
(selected-frame))))
3275 (define-widget 'custom-face-selected
'group
3276 "Edit the attributes of the selected display in a face specification."
3277 :args
'((choice :inline t
3278 (group :tag
"With Defaults" :inline t
3279 (group (const :tag
"" default
)
3280 (custom-face-edit :tag
" Default\n Attributes"))
3283 (group custom-display-unselected sexp
))
3284 (group (sexp :format
"")
3285 (custom-face-edit :tag
" Overriding\n Attributes"))
3289 (group :tag
"No Defaults" :inline t
3292 (group custom-display-unselected sexp
))
3293 (group (sexp :format
"")
3294 (custom-face-edit :tag
"\n Attributes"))
3301 (defconst custom-face-selected
(widget-convert 'custom-face-selected
)
3302 "Converted version of the `custom-face-selected' widget.")
3304 (defun custom-filter-face-spec (spec filter-index
&optional default-filter
)
3305 "Return a canonicalized version of SPEC using.
3306 FILTER-INDEX is the index in the entry for each attribute in
3307 `custom-face-attributes' at which the appropriate filter function can be
3308 found, and DEFAULT-FILTER is the filter to apply for attributes that
3310 (mapcar (lambda (entry)
3311 ;; Filter a single face-spec entry
3312 (let ((tests (car entry
))
3314 ;; Handle both old- and new-style attribute syntax
3315 (if (listp (car (cdr entry
)))
3318 (filtered-attrs nil
))
3319 ;; Filter each face attribute
3320 (while unfiltered-attrs
3321 (let* ((attr (pop unfiltered-attrs
))
3322 (pre-filtered-value (pop unfiltered-attrs
))
3324 (or (nth filter-index
(assq attr custom-face-attributes
))
3328 (funcall filter pre-filtered-value
)
3329 pre-filtered-value
)))
3330 (push filtered-value filtered-attrs
)
3331 (push attr filtered-attrs
)))
3333 (list tests filtered-attrs
)))
3336 (defun custom-pre-filter-face-spec (spec)
3337 "Return SPEC changed as necessary for editing by the face customization widget.
3338 SPEC must be a full face spec."
3339 (custom-filter-face-spec spec
2))
3341 (defun custom-post-filter-face-spec (spec)
3342 "Return the customized SPEC in a form suitable for setting the face."
3343 (custom-filter-face-spec spec
3))
3345 (defun custom-face-value-create (widget)
3346 "Create a list of the display specifications for WIDGET."
3347 (let ((buttons (widget-get widget
:buttons
))
3349 (symbol (widget-get widget
:value
))
3350 (tag (widget-get widget
:tag
))
3351 (state (widget-get widget
:custom-state
))
3353 (is-last (widget-get widget
:custom-last
))
3354 (prefix (widget-get widget
:custom-prefix
)))
3356 (setq tag
(prin1-to-string symbol
)))
3357 (cond ((eq custom-buffer-style
'tree
)
3358 (insert prefix
(if is-last
" `--- " " |--- "))
3359 (push (widget-create-child-and-convert
3360 widget
'custom-browse-face-tag
)
3362 (insert " " tag
"\n")
3363 (widget-put widget
:buttons buttons
))
3367 (widget-specify-sample widget begin
(point))
3368 (if (eq custom-buffer-style
'face
)
3370 (if (string-match "face\\'" tag
)
3372 (insert " face: ")))
3374 (push (widget-create-child-and-convert widget
'item
3381 (push (widget-create-child-and-convert
3383 :help-echo
"Hide or show this face."
3386 :action
'custom-toggle-parent
3387 (not (eq state
'hidden
)))
3391 (let ((magic (widget-create-child-and-convert
3392 widget
'custom-magic nil
)))
3393 (widget-put widget
:custom-magic magic
)
3394 (push magic buttons
))
3396 (widget-put widget
:buttons buttons
)
3397 ;; Insert documentation.
3398 (widget-put widget
:documentation-indent
3)
3399 (widget-add-documentation-string-button
3400 widget
:visibility-widget
'custom-visibility
)
3402 ;; The comment field
3403 (unless (eq state
'hidden
)
3404 (let* ((comment (get symbol
'face-comment
))
3406 (widget-create-child-and-convert
3407 widget
'custom-comment
3409 :value
(or comment
""))))
3410 (widget-put widget
:comment-widget comment-widget
)
3411 (push comment-widget children
)))
3413 (unless (eq state
'hidden
)
3414 (when (eq (widget-get widget
:custom-level
) 1)
3415 (custom-add-parent-links widget
))
3416 (custom-add-see-also widget
))
3418 (unless (eq (preceding-char) ?
\n)
3420 (unless (eq state
'hidden
)
3421 (message "Creating face editor...")
3422 (custom-load-widget widget
)
3423 (unless (widget-get widget
:custom-form
)
3424 (widget-put widget
:custom-form custom-face-default-form
))
3425 (let* ((symbol (widget-value widget
))
3426 (spec (or (get symbol
'customized-face
)
3427 (get symbol
'saved-face
)
3428 (get symbol
'face-defface-spec
)
3429 ;; Attempt to construct it.
3430 (list (list t
(custom-face-attributes-get
3431 symbol
(selected-frame))))))
3432 (form (widget-get widget
:custom-form
))
3433 (indent (widget-get widget
:indent
))
3435 ;; If the user has changed this face in some other way,
3436 ;; edit it as the user has specified it.
3437 (if (not (face-spec-match-p symbol spec
(selected-frame)))
3438 (setq spec
(list (list t
(face-attr-construct symbol
(selected-frame))))))
3439 (setq spec
(custom-pre-filter-face-spec spec
))
3440 (setq edit
(widget-create-child-and-convert
3442 (cond ((and (eq form
'selected
)
3443 (widget-apply custom-face-selected
3445 (when indent
(insert-char ?\ indent
))
3446 'custom-face-selected
)
3447 ((and (not (eq form
'lisp
))
3448 (widget-apply custom-face-all
3452 (when indent
(insert-char ?\ indent
))
3455 (custom-face-state-set widget
)
3456 (push edit children
)
3457 (widget-put widget
:children children
))
3458 (message "Creating face editor...done"))))))
3460 (defvar custom-face-menu
3461 `(("Set for Current Session" custom-face-set
)
3462 ,@(when (or custom-file init-file-user
)
3463 '(("Save for Future Sessions" custom-face-save
)))
3464 ("Undo Edits" custom-redraw
3466 (memq (widget-get widget
:custom-state
) '(modified changed
))))
3467 ("Reset to Saved" custom-face-reset-saved
3469 (or (get (widget-value widget
) 'saved-face
)
3470 (get (widget-value widget
) 'saved-face-comment
))))
3471 ,@(when (or custom-file init-file-user
)
3472 '(("Erase Customization" custom-face-reset-standard
3474 (get (widget-value widget
) 'face-defface-spec
)))))
3475 ("---" ignore ignore
)
3476 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
3477 ("---" ignore ignore
)
3478 ("For Current Display" custom-face-edit-selected
3480 (not (eq (widget-get widget
:custom-form
) 'selected
))))
3481 ("For All Kinds of Displays" custom-face-edit-all
3483 (not (eq (widget-get widget
:custom-form
) 'all
))))
3484 ("Show Lisp Expression" custom-face-edit-lisp
3486 (not (eq (widget-get widget
:custom-form
) 'lisp
)))))
3487 "Alist of actions for the `custom-face' widget.
3488 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3489 the menu entry, ACTION is the function to call on the widget when the
3490 menu is selected, and FILTER is a predicate which takes a `custom-face'
3491 widget as an argument, and returns non-nil if ACTION is valid on that
3492 widget. If FILTER is nil, ACTION is always valid.")
3494 (defun custom-face-edit-selected (widget)
3495 "Edit selected attributes of the value of WIDGET."
3496 (widget-put widget
:custom-state
'unknown
)
3497 (widget-put widget
:custom-form
'selected
)
3498 (custom-redraw widget
))
3500 (defun custom-face-edit-all (widget)
3501 "Edit all attributes of the value of WIDGET."
3502 (widget-put widget
:custom-state
'unknown
)
3503 (widget-put widget
:custom-form
'all
)
3504 (custom-redraw widget
))
3506 (defun custom-face-edit-lisp (widget)
3507 "Edit the Lisp representation of the value of WIDGET."
3508 (widget-put widget
:custom-state
'unknown
)
3509 (widget-put widget
:custom-form
'lisp
)
3510 (custom-redraw widget
))
3512 (defun custom-face-state-set (widget)
3513 "Set the state of WIDGET."
3514 (let* ((symbol (widget-value widget
))
3515 (comment (get symbol
'face-comment
))
3519 (setq tmp
(get symbol
'customized-face
))
3520 (setq temp
(get symbol
'customized-face-comment
))
3522 (if (equal temp comment
)
3526 (setq tmp
(get symbol
'saved-face
))
3527 (setq temp
(get symbol
'saved-face-comment
))
3529 (if (equal temp comment
)
3531 ((eq 'user
(caar (get symbol
'theme-face
)))
3533 ((eq 'changed
(caar (get symbol
'theme-face
)))
3537 ((get symbol
'face-defface-spec
)
3538 (if (equal comment nil
)
3543 ;; If the user called set-face-attribute to change the default
3544 ;; for new frames, this face is "set outside of Customize".
3545 (if (and (not (eq state
'rogue
))
3546 (get symbol
'face-modified
))
3547 (setq state
'changed
))
3548 (widget-put widget
:custom-state state
)))
3550 (defun custom-face-action (widget &optional event
)
3551 "Show the menu for `custom-face' WIDGET.
3552 Optional EVENT is the location for the menu."
3553 (if (eq (widget-get widget
:custom-state
) 'hidden
)
3554 (custom-toggle-hide widget
)
3555 (let* ((completion-ignore-case t
)
3556 (symbol (widget-get widget
:value
))
3557 (answer (widget-choose (concat "Operation on "
3558 (custom-unlispify-tag-name symbol
))
3559 (custom-menu-filter custom-face-menu
3563 (funcall answer widget
)))))
3565 (defun custom-face-set (widget)
3566 "Make the face attributes in WIDGET take effect."
3567 (let* ((symbol (widget-value widget
))
3568 (child (car (widget-get widget
:children
)))
3569 (value (custom-post-filter-face-spec (widget-value child
)))
3570 (comment-widget (widget-get widget
:comment-widget
))
3571 (comment (widget-value comment-widget
)))
3572 (when (equal comment
"")
3574 ;; Make the comment invisible by hand if it's empty
3575 (custom-comment-hide comment-widget
))
3576 (put symbol
'customized-face value
)
3577 (custom-push-theme 'theme-face symbol
'user
'set value
)
3578 (if (face-spec-choose value
)
3579 (face-spec-set symbol value t
)
3580 ;; face-set-spec ignores empty attribute lists, so just give it
3581 ;; something harmless instead.
3582 (face-spec-set symbol
'((t :foreground unspecified
)) t
))
3583 (put symbol
'customized-face-comment comment
)
3584 (put symbol
'face-comment comment
)
3585 (custom-face-state-set widget
)
3586 (custom-redraw-magic widget
)))
3588 (defun custom-face-mark-to-save (widget)
3589 "Mark for saving the face edited by WIDGET."
3590 (let* ((symbol (widget-value widget
))
3591 (child (car (widget-get widget
:children
)))
3592 (value (custom-post-filter-face-spec (widget-value child
)))
3593 (comment-widget (widget-get widget
:comment-widget
))
3594 (comment (widget-value comment-widget
)))
3595 (when (equal comment
"")
3597 ;; Make the comment invisible by hand if it's empty
3598 (custom-comment-hide comment-widget
))
3599 (custom-push-theme 'theme-face symbol
'user
'set value
)
3600 (if (face-spec-choose value
)
3601 (face-spec-set symbol value t
)
3602 ;; face-set-spec ignores empty attribute lists, so just give it
3603 ;; something harmless instead.
3604 (face-spec-set symbol
'((t :foreground unspecified
)) t
))
3605 (unless (eq (widget-get widget
:custom-state
) 'standard
)
3606 (put symbol
'saved-face value
))
3607 (put symbol
'customized-face nil
)
3608 (put symbol
'face-comment comment
)
3609 (put symbol
'customized-face-comment nil
)
3610 (put symbol
'saved-face-comment comment
)))
3612 (defsubst custom-face-state-set-and-redraw
(widget)
3613 "Set state of face widget WIDGET and redraw with current settings."
3614 (custom-face-state-set widget
)
3615 (custom-redraw-magic widget
))
3617 (defun custom-face-save (widget)
3618 "Save the face edited by WIDGET."
3619 (custom-face-mark-to-save widget
)
3621 (custom-face-state-set-and-redraw widget
))
3623 ;; For backward compatibility.
3624 (define-obsolete-function-alias 'custom-face-save-command
'custom-face-save
3627 (defun custom-face-reset-saved (widget)
3628 "Restore WIDGET to the face's default attributes."
3629 (let* ((symbol (widget-value widget
))
3630 (child (car (widget-get widget
:children
)))
3631 (value (get symbol
'saved-face
))
3632 (comment (get symbol
'saved-face-comment
))
3633 (comment-widget (widget-get widget
:comment-widget
)))
3634 (unless (or value comment
)
3635 (error "No saved value for this face"))
3636 (put symbol
'customized-face nil
)
3637 (put symbol
'customized-face-comment nil
)
3638 (custom-push-theme 'theme-face symbol
'user
'set value
)
3639 (face-spec-set symbol value t
)
3640 (put symbol
'face-comment comment
)
3641 (widget-value-set child value
)
3642 ;; This call manages the comment visibility
3643 (widget-value-set comment-widget
(or comment
""))
3644 (custom-face-state-set widget
)
3645 (custom-redraw-magic widget
)))
3647 (defun custom-face-standard-value (widget)
3648 (get (widget-value widget
) 'face-defface-spec
))
3650 (defun custom-face-mark-to-reset-standard (widget)
3651 "Restore widget WIDGET to the face's standard attribute values.
3652 If `custom-reset-standard-faces-list' is nil, save, reset and
3653 redraw the widget immediately."
3654 (let* ((symbol (widget-value widget
))
3655 (child (car (widget-get widget
:children
)))
3656 (value (get symbol
'face-defface-spec
))
3657 (comment-widget (widget-get widget
:comment-widget
)))
3659 (error "No standard setting for this face"))
3660 (put symbol
'customized-face nil
)
3661 (put symbol
'customized-face-comment nil
)
3662 (custom-push-theme 'theme-face symbol
'user
'reset
)
3663 (face-spec-set symbol value t
)
3664 (custom-theme-recalc-face symbol
)
3665 (if (and custom-reset-standard-faces-list
3666 (or (get symbol
'saved-face
) (get symbol
'saved-face-comment
)))
3669 (put symbol
'saved-face nil
)
3670 (put symbol
'saved-face-comment nil
)
3671 ;; Append this to `custom-reset-standard-faces-list' and have
3672 ;; `custom-reset-standard-save-and-update' save setting to the
3673 ;; file, update the widget's state, and redraw it.
3674 (setq custom-reset-standard-faces-list
3675 (cons widget custom-reset-standard-faces-list
)))
3676 (when (or (get symbol
'saved-face
) (get symbol
'saved-face-comment
))
3677 (put symbol
'saved-face nil
)
3678 (put symbol
'saved-face-comment nil
)
3680 (put symbol
'face-comment nil
)
3681 (widget-value-set child
3682 (custom-pre-filter-face-spec
3683 (list (list t
(custom-face-attributes-get
3685 ;; This call manages the comment visibility
3686 (widget-value-set comment-widget
"")
3687 (custom-face-state-set widget
)
3688 (custom-redraw-magic widget
))))
3690 (defun custom-face-reset-standard (widget)
3691 "Restore WIDGET to the face's standard attribute values.
3692 This operation eliminates any saved attributes for the face,
3693 restoring it to the state of a face that has never been customized."
3694 (let (custom-reset-standard-faces-list)
3695 (custom-face-mark-to-reset-standard widget
)))
3697 ;;; The `face' Widget.
3699 (defvar widget-face-prompt-value-history nil
3700 "History of input to `widget-face-prompt-value'.")
3702 (define-widget 'face
'symbol
3703 "A Lisp face name (with sample)."
3704 :format
"%{%t%}: (%{sample%}) %v"
3707 :sample-face-get
'widget-face-sample-face-get
3708 :notify
'widget-face-notify
3709 :match
(lambda (widget value
) (facep value
))
3710 :complete-function
(lambda ()
3712 (lisp-complete-symbol 'facep
))
3713 :prompt-match
'facep
3714 :prompt-history
'widget-face-prompt-value-history
3715 :validate
(lambda (widget)
3716 (unless (facep (widget-value widget
))
3718 :error
(format "Invalid face: %S"
3719 (widget-value widget
)))
3722 (defun widget-face-sample-face-get (widget)
3723 (let ((value (widget-value widget
)))
3728 (defun widget-face-notify (widget child
&optional event
)
3729 "Update the sample, and notify the parent."
3730 (overlay-put (widget-get widget
:sample-overlay
)
3731 'face
(widget-apply widget
:sample-face-get
))
3732 (widget-default-notify widget child event
))
3735 ;;; The `hook' Widget.
3737 (define-widget 'hook
'list
3738 "An Emacs Lisp hook."
3739 :value-to-internal
(lambda (widget value
)
3740 (if (and value
(symbolp value
))
3743 :match
(lambda (widget value
)
3745 (widget-group-match widget value
)))
3746 ;; Avoid adding undefined functions to the hook, especially for
3747 ;; things like `find-file-hook' or even more basic ones, to avoid
3749 :set
(lambda (symbol value
)
3752 (add-hook symbol elt
))))
3753 :convert-widget
'custom-hook-convert-widget
3756 (defun custom-hook-convert-widget (widget)
3757 ;; Handle `:options'.
3758 (let* ((options (widget-get widget
:options
))
3759 (other `(editable-list :inline t
3760 :entry-format
"%i %d%v"
3761 (function :format
" %v")))
3763 (list `(checklist :inline t
3764 ,@(mapcar (lambda (entry)
3765 `(function-item ,entry
))
3769 (widget-put widget
:args args
)
3772 ;;; The `custom-group-link' Widget.
3774 (define-widget 'custom-group-link
'link
3775 "Show parent in other window when activated."
3776 :button-face
'custom-link
3777 :mouse-face
'highlight
3778 :pressed-face
'highlight
3779 :help-echo
"Create customization buffer for this group."
3780 :keymap custom-mode-link-map
3781 :follow-link
'mouse-face
3782 :action
'custom-group-link-action
)
3784 (defun custom-group-link-action (widget &rest ignore
)
3785 (customize-group (widget-value widget
)))
3787 ;;; The `custom-group' Widget.
3789 (defcustom custom-group-tag-faces nil
3790 ;; In XEmacs, this ought to play games with font size.
3791 ;; Fixme: make it do so in Emacs.
3792 "Face used for group tags.
3793 The first member is used for level 1 groups, the second for level 2,
3794 and so forth. The remaining group tags are shown with `custom-group-tag'."
3795 :type
'(repeat face
)
3796 :group
'custom-faces
)
3798 (defface custom-group-tag-1
3801 (:foreground
"pink" :weight bold
:height
1.2 :inherit variable-pitch
))
3802 (((min-colors 88) (class color
)
3804 (:foreground
"red1" :weight bold
:height
1.2 :inherit variable-pitch
))
3807 (:foreground
"red" :weight bold
:height
1.2 :inherit variable-pitch
))
3809 "Face used for group tags."
3810 :group
'custom-faces
)
3811 ;; backward-compatibility alias
3812 (put 'custom-group-tag-face-1
'face-alias
'custom-group-tag-1
)
3814 (defface custom-group-tag
3817 (:foreground
"light blue" :weight bold
:height
1.2 :inherit variable-pitch
))
3818 (((min-colors 88) (class color
)
3820 (:foreground
"blue1" :weight bold
:height
1.2 :inherit variable-pitch
))
3823 (:foreground
"blue" :weight bold
:height
1.2 :inherit variable-pitch
))
3825 "Face used for low level group tags."
3826 :group
'custom-faces
)
3827 ;; backward-compatibility alias
3828 (put 'custom-group-tag-face
'face-alias
'custom-group-tag
)
3830 (define-widget 'custom-group
'custom
3833 :sample-face-get
'custom-group-sample-face-get
3834 :documentation-property
'group-documentation
3835 :help-echo
"Set or reset all members of this group."
3836 :value-create
'custom-group-value-create
3837 :action
'custom-group-action
3838 :custom-category
'group
3839 :custom-set
'custom-group-set
3840 :custom-mark-to-save
'custom-group-mark-to-save
3841 :custom-reset-current
'custom-group-reset-current
3842 :custom-reset-saved
'custom-group-reset-saved
3843 :custom-reset-standard
'custom-group-reset-standard
3844 :custom-mark-to-reset-standard
'custom-group-mark-to-reset-standard
3845 :custom-state-set-and-redraw
'custom-group-state-set-and-redraw
3846 :custom-menu
'custom-group-menu-create
)
3848 (defun custom-group-sample-face-get (widget)
3849 ;; Use :sample-face.
3850 (or (nth (1- (widget-get widget
:custom-level
)) custom-group-tag-faces
)
3853 (define-widget 'custom-group-visibility
'visibility
3854 "An indicator and manipulator for hidden group contents."
3855 :create
'custom-group-visibility-create
)
3857 (defun custom-group-visibility-create (widget)
3858 (let ((visible (widget-value widget
)))
3860 (insert "--------")))
3861 (widget-default-create widget
))
3863 (defun custom-group-members (symbol groups-only
)
3864 "Return SYMBOL's custom group members.
3865 If GROUPS-ONLY non-nil, return only those members that are groups."
3866 (if (not groups-only
)
3867 (get symbol
'custom-group
)
3869 (dolist (entry (get symbol
'custom-group
))
3870 (when (eq (nth 1 entry
) 'custom-group
)
3871 (push entry members
)))
3872 (nreverse members
))))
3874 (defun custom-group-value-create (widget)
3875 "Insert a customize group for WIDGET in the current buffer."
3876 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
3877 (custom-load-widget widget
))
3878 (let* ((state (widget-get widget
:custom-state
))
3879 (level (widget-get widget
:custom-level
))
3880 ;; (indent (widget-get widget :indent))
3881 (prefix (widget-get widget
:custom-prefix
))
3882 (buttons (widget-get widget
:buttons
))
3883 (tag (widget-get widget
:tag
))
3884 (symbol (widget-value widget
))
3885 (members (custom-group-members symbol
3886 (and (eq custom-buffer-style
'tree
)
3887 custom-browse-only-groups
))))
3888 (cond ((and (eq custom-buffer-style
'tree
)
3890 (or members
(custom-unloaded-widget-p widget
)))
3891 (custom-browse-insert-prefix prefix
)
3892 (push (widget-create-child-and-convert
3893 widget
'custom-browse-visibility
3894 ;; :tag-glyph "plus"
3898 ;; (widget-glyph-insert nil "-- " "horizontal")
3899 (push (widget-create-child-and-convert
3900 widget
'custom-browse-group-tag
)
3902 (insert " " tag
"\n")
3903 (widget-put widget
:buttons buttons
))
3904 ((and (eq custom-buffer-style
'tree
)
3905 (zerop (length members
)))
3906 (custom-browse-insert-prefix prefix
)
3908 ;; (widget-glyph-insert nil "[ ]" "empty")
3909 ;; (widget-glyph-insert nil "-- " "horizontal")
3910 (push (widget-create-child-and-convert
3911 widget
'custom-browse-group-tag
)
3913 (insert " " tag
"\n")
3914 (widget-put widget
:buttons buttons
))
3915 ((eq custom-buffer-style
'tree
)
3916 (custom-browse-insert-prefix prefix
)
3917 (if (zerop (length members
))
3919 (custom-browse-insert-prefix prefix
)
3921 ;; (widget-glyph-insert nil "[ ]" "empty")
3922 ;; (widget-glyph-insert nil "-- " "horizontal")
3923 (push (widget-create-child-and-convert
3924 widget
'custom-browse-group-tag
)
3926 (insert " " tag
"\n")
3927 (widget-put widget
:buttons buttons
))
3928 (push (widget-create-child-and-convert
3929 widget
'custom-browse-visibility
3930 ;; :tag-glyph "minus"
3934 ;; (widget-glyph-insert nil "-\\ " "top")
3935 (push (widget-create-child-and-convert
3936 widget
'custom-browse-group-tag
)
3938 (insert " " tag
"\n")
3939 (widget-put widget
:buttons buttons
)
3940 (message "Creating group...")
3941 (let* ((members (custom-sort-items members
3942 custom-browse-sort-alphabetically
3943 custom-browse-order-groups
))
3944 (prefixes (widget-get widget
:custom-prefixes
))
3945 (custom-prefix-list (custom-prefix-add symbol prefixes
))
3946 (extra-prefix (if (widget-get widget
:custom-last
)
3949 (prefix (concat prefix extra-prefix
))
3952 (setq entry
(car members
)
3953 members
(cdr members
))
3954 (push (widget-create-child-and-convert
3955 widget
(nth 1 entry
)
3957 :tag
(custom-unlispify-tag-name (nth 0 entry
))
3958 :custom-prefixes custom-prefix-list
3959 :custom-level
(1+ level
)
3960 :custom-last
(null members
)
3961 :value
(nth 0 entry
)
3962 :custom-prefix prefix
)
3964 (widget-put widget
:children
(reverse children
)))
3965 (message "Creating group...done")))
3968 ;; Create level indicator.
3970 (if (eq custom-buffer-style
'links
)
3971 (push (widget-create-child-and-convert
3972 widget
'custom-group-link
3976 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3978 (push (widget-create-child-and-convert
3979 widget
'custom-group-visibility
3980 :help-echo
"Show members of this group."
3981 :action
'custom-toggle-parent
3982 (not (eq state
'hidden
)))
3985 ;; Create magic button.
3986 (let ((magic (widget-create-child-and-convert
3987 widget
'custom-magic nil
)))
3988 (widget-put widget
:custom-magic magic
)
3989 (push magic buttons
))
3991 (widget-put widget
:buttons buttons
)
3992 ;; Insert documentation.
3993 (if (and (eq custom-buffer-style
'links
) (> level
1))
3994 (widget-put widget
:documentation-indent
0))
3995 (widget-add-documentation-string-button
3996 widget
:visibility-widget
'custom-visibility
))
4000 ;; Add parent groups references above the group.
4001 (if t
;;; This should test that the buffer
4002 ;;; was made to display a group.
4004 (if (custom-add-parent-links widget
4006 "Parent group documentation:")
4008 ;; Create level indicator.
4009 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
4012 (let ((start (point)))
4013 (insert tag
" group: ")
4014 (widget-specify-sample widget start
(point)))
4015 (insert (widget-docstring widget
))
4016 ;; Create visibility indicator.
4017 (unless (eq custom-buffer-style
'links
)
4019 (push (widget-create-child-and-convert
4021 :help-echo
"Hide members of this group."
4022 :action
'custom-toggle-parent
4023 (not (eq state
'hidden
)))
4026 ;; Create more dashes.
4027 ;; Use 76 instead of 75 to compensate for the temporary "<"
4028 ;; added by `widget-insert'.
4029 (insert-char ?-
(- 76 (current-column)
4030 (* custom-buffer-indent level
)))
4032 ;; Create magic button.
4033 (let ((magic (widget-create-child-and-convert
4034 widget
'custom-magic
4037 (widget-put widget
:custom-magic magic
)
4038 (push magic buttons
))
4040 (widget-put widget
:buttons buttons
)
4041 ;; Insert documentation.
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 members
4057 custom-buffer-sort-alphabetically
4058 custom-buffer-order-groups
))
4059 (prefixes (widget-get widget
:custom-prefixes
))
4060 (custom-prefix-list (custom-prefix-add symbol prefixes
))
4061 (length (length members
))
4063 (children (mapcar (lambda (entry)
4064 (widget-insert "\n")
4066 Creating group members... %2d%%"
4067 (/ (* 100.0 count
) length
))
4068 (setq count
(1+ count
))
4070 (widget-create-child-and-convert
4071 widget
(nth 1 entry
)
4073 :tag
(custom-unlispify-tag-name
4075 :custom-prefixes custom-prefix-list
4076 :custom-level
(1+ level
)
4077 :value
(nth 0 entry
))
4078 (unless (eq (preceding-char) ?
\n)
4079 (widget-insert "\n"))))
4081 (message "Creating group magic...")
4082 (mapc 'custom-magic-reset children
)
4083 (message "Creating group state...")
4084 (widget-put widget
:children children
)
4085 (custom-group-state-update widget
)
4086 (message "Creating group... done"))
4089 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
4090 (insert "\\- " (widget-get widget
:tag
) " group end ")
4091 (insert-char ?-
(- 75 (current-column) (* custom-buffer-indent level
)))
4094 (defvar custom-group-menu
4095 `(("Set for Current Session" custom-group-set
4097 (eq (widget-get widget
:custom-state
) 'modified
)))
4098 ,@(when (or custom-file init-file-user
)
4099 '(("Save for Future Sessions" custom-group-save
4101 (memq (widget-get widget
:custom-state
) '(modified set
))))))
4102 ("Undo Edits" custom-group-reset-current
4104 (memq (widget-get widget
:custom-state
) '(modified))))
4105 ("Reset to Saved" custom-group-reset-saved
4107 (memq (widget-get widget
:custom-state
) '(modified set
))))
4108 ,@(when (or custom-file init-file-user
)
4109 '(("Erase Customization" custom-group-reset-standard
4111 (memq (widget-get widget
:custom-state
) '(modified set saved
)))))))
4112 "Alist of actions for the `custom-group' widget.
4113 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
4114 the menu entry, ACTION is the function to call on the widget when the
4115 menu is selected, and FILTER is a predicate which takes a `custom-group'
4116 widget as an argument, and returns non-nil if ACTION is valid on that
4117 widget. If FILTER is nil, ACTION is always valid.")
4119 (defun custom-group-action (widget &optional event
)
4120 "Show the menu for `custom-group' WIDGET.
4121 Optional EVENT is the location for the menu."
4122 (if (eq (widget-get widget
:custom-state
) 'hidden
)
4123 (custom-toggle-hide widget
)
4124 (let* ((completion-ignore-case t
)
4125 (answer (widget-choose (concat "Operation on "
4126 (custom-unlispify-tag-name
4127 (widget-get widget
:value
)))
4128 (custom-menu-filter custom-group-menu
4132 (funcall answer widget
)))))
4134 (defun custom-group-set (widget)
4135 "Set changes in all modified group members."
4136 (dolist (child (widget-get widget
:children
))
4137 (when (eq (widget-get child
:custom-state
) 'modified
)
4138 (widget-apply child
:custom-set
))))
4140 (defun custom-group-mark-to-save (widget)
4141 "Mark all modified group members for saving."
4142 (dolist (child (widget-get widget
:children
))
4143 (when (memq (widget-get child
:custom-state
) '(modified set
))
4144 (widget-apply child
:custom-mark-to-save
))))
4146 (defsubst custom-group-state-set-and-redraw
(widget)
4147 "Set state of group widget WIDGET and redraw with current settings."
4148 (dolist (child (widget-get widget
:children
))
4149 (when (memq (widget-get child
:custom-state
) '(modified set
))
4150 (widget-apply child
:custom-state-set-and-redraw
))))
4152 (defun custom-group-save (widget)
4153 "Save all modified group members."
4154 (custom-group-mark-to-save widget
)
4156 (custom-group-state-set-and-redraw widget
))
4158 (defun custom-group-reset-current (widget)
4159 "Reset all modified group members."
4160 (dolist (child (widget-get widget
:children
))
4161 (when (eq (widget-get child
:custom-state
) 'modified
)
4162 (widget-apply child
:custom-reset-current
))))
4164 (defun custom-group-reset-saved (widget)
4165 "Reset all modified or set group members."
4166 (dolist (child (widget-get widget
:children
))
4167 (when (memq (widget-get child
:custom-state
) '(modified set
))
4168 (widget-apply child
:custom-reset-saved
))))
4170 (defun custom-group-reset-standard (widget)
4171 "Reset all modified, set, or saved group members."
4172 (let ((custom-reset-standard-variables-list '(t))
4173 (custom-reset-standard-faces-list '(t)))
4174 (custom-group-mark-to-reset-standard widget
)
4175 (custom-reset-standard-save-and-update)))
4177 (defun custom-group-mark-to-reset-standard (widget)
4178 "Mark to reset all modified, set, or saved group members."
4179 (dolist (child (widget-get widget
:children
))
4180 (when (memq (widget-get child
:custom-state
)
4181 '(modified set saved
))
4182 (widget-apply child
:custom-mark-to-reset-standard
))))
4184 (defun custom-group-state-update (widget)
4186 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
4187 (let* ((children (widget-get widget
:children
))
4188 (states (mapcar (lambda (child)
4189 (widget-get child
:custom-state
))
4191 (magics custom-magic-alist
)
4194 (let ((magic (car (car magics
))))
4195 (if (and (not (eq magic
'hidden
))
4196 (memq magic states
))
4199 (setq magics
(cdr magics
)))))
4200 (widget-put widget
:custom-state found
)))
4201 (custom-magic-reset widget
))
4203 ;;; Reading and writing the custom file.
4206 (defcustom custom-file nil
4207 "File used for storing customization information.
4208 The default is nil, which means to use your init file
4209 as specified by `user-init-file'. If the value is not nil,
4210 it should be an absolute file name.
4212 You can set this option through Custom, if you carefully read the
4213 last paragraph below. However, usually it is simpler to write
4214 something like the following in your init file:
4216 \(setq custom-file \"~/.emacs-custom.el\")
4219 Note that both lines are necessary: the first line tells Custom to
4220 save all customizations in this file, but does not load it.
4222 When you change this variable outside Custom, look in the
4223 previous custom file \(usually your init file) for the
4224 forms `(custom-set-variables ...)' and `(custom-set-faces ...)',
4225 and copy them (whichever ones you find) to the new custom file.
4226 This will preserve your existing customizations.
4228 If you save this option using Custom, Custom will write all
4229 currently saved customizations, including the new one for this
4230 option itself, into the file you specify, overwriting any
4231 `custom-set-variables' and `custom-set-faces' forms already
4232 present in that file. It will not delete any customizations from
4233 the old custom file. You should do that manually if that is what you
4234 want. You also have to put something like `\(load \"CUSTOM-FILE\")
4235 in your init file, where CUSTOM-FILE is the actual name of the
4236 file. Otherwise, Emacs will not load the file when it starts up,
4237 and hence will not set `custom-file' to that file either."
4238 :type
'(choice (const :tag
"Your Emacs init file" nil
)
4239 (file :format
"%t:%v%d"
4241 "Please read entire docstring below before setting \
4242 this through Custom.
4243 Click om \"More\" \(or position point there and press RETURN)
4244 if only the first line of the docstring is shown."))
4247 (defun custom-file ()
4248 "Return the file name for saving customizations."
4251 (let ((user-init-file user-init-file
)
4253 (if (eq system-type
'ms-dos
) "~/_emacs" "~/.emacs")))
4254 (when (null user-init-file
)
4255 (if (or (file-exists-p default-init-file
)
4256 (and (eq system-type
'windows-nt
)
4257 (file-exists-p "~/_emacs")))
4258 ;; Started with -q, i.e. the file containing
4259 ;; Custom settings hasn't been read. Saving
4260 ;; settings there would overwrite other settings.
4261 (error "Saving settings from \"emacs -q\" would overwrite existing customizations"))
4262 (setq user-init-file default-init-file
))
4265 ;; If recentf-mode is non-nil, this is defined.
4266 (declare-function recentf-expand-file-name
"recentf" (name))
4269 (defun custom-save-all ()
4270 "Save all customizations in `custom-file'."
4271 (when (and (null custom-file
) init-file-had-error
)
4272 (error "Cannot save customizations; init file was not fully loaded"))
4273 (let* ((filename (custom-file))
4278 (recentf-expand-file-name (custom-file)))
4281 (old-buffer (find-buffer-visiting filename
)))
4282 (with-current-buffer (let ((find-file-visit-truename t
))
4283 (or old-buffer
(find-file-noselect filename
)))
4284 (unless (eq major-mode
'emacs-lisp-mode
)
4286 (let ((inhibit-read-only t
))
4287 (custom-save-variables)
4288 (custom-save-faces))
4289 (let ((file-precious-flag t
))
4292 (kill-buffer (current-buffer))))))
4295 (defun customize-save-customized ()
4296 "Save all user options which have been set in this session."
4298 (mapatoms (lambda (symbol)
4299 (let ((face (get symbol
'customized-face
))
4300 (value (get symbol
'customized-value
))
4301 (face-comment (get symbol
'customized-face-comment
))
4303 (get symbol
'customized-variable-comment
)))
4305 (put symbol
'saved-face face
)
4306 (custom-push-theme 'theme-face symbol
'user
'set value
)
4307 (put symbol
'customized-face nil
))
4309 (put symbol
'saved-value value
)
4310 (custom-push-theme 'theme-value symbol
'user
'set value
)
4311 (put symbol
'customized-value nil
))
4312 (when variable-comment
4313 (put symbol
'saved-variable-comment variable-comment
)
4314 (put symbol
'customized-variable-comment nil
))
4316 (put symbol
'saved-face-comment face-comment
)
4317 (put symbol
'customized-face-comment nil
)))))
4318 ;; We really should update all custom buffers here.
4321 ;; Editing the custom file contents in a buffer.
4323 (defun custom-save-delete (symbol)
4324 "Delete all calls to SYMBOL from the contents of the current buffer.
4325 Leave point at the old location of the first such call,
4326 or (if there were none) at the end of the buffer.
4328 This function does not save the buffer."
4329 (goto-char (point-min))
4330 ;; Skip all whitespace and comments.
4331 (while (forward-comment 1))
4333 (save-excursion (forward-sexp (buffer-size)))) ; Test for scan errors.
4336 (while t
;; We exit this loop only via throw.
4337 ;; Skip all whitespace and comments.
4338 (while (forward-comment 1))
4339 (let ((start (point))
4340 (sexp (condition-case nil
4341 (read (current-buffer))
4342 (end-of-file (throw 'found nil
)))))
4343 (when (and (listp sexp
)
4344 (eq (car sexp
) symbol
))
4345 (delete-region start
(point))
4347 (setq first
(point)))))))
4350 ;; Move in front of local variables, otherwise long Custom
4351 ;; entries would make them ineffective.
4352 (let ((pos (point-max))
4353 (case-fold-search t
))
4355 (goto-char (point-max))
4356 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
4358 (when (search-forward "Local Variables:" nil t
)
4359 (setq pos
(line-beginning-position))))
4362 (defun custom-save-variables ()
4363 "Save all customized variables in `custom-file'."
4365 (custom-save-delete 'custom-set-variables
)
4366 (let ((standard-output (current-buffer))
4367 (saved-list (make-list 1 0))
4369 ;; First create a sorted list of saved variables.
4372 (if (and (get symbol
'saved-value
)
4373 ;; ignore theme values
4374 (or (null (get symbol
'theme-value
))
4375 (eq 'user
(caar (get symbol
'theme-value
)))))
4376 (nconc saved-list
(list symbol
)))))
4377 (setq saved-list
(sort (cdr saved-list
) 'string
<))
4380 (princ "(custom-set-variables
4381 ;; custom-set-variables was added by Custom.
4382 ;; If you edit it by hand, you could mess it up, so be careful.
4383 ;; Your init file should contain only one such instance.
4384 ;; If there is more than one, they won't work right.\n")
4385 (dolist (symbol saved-list
)
4386 (let ((spec (car-safe (get symbol
'theme-value
)))
4387 (value (get symbol
'saved-value
))
4388 (requests (get symbol
'custom-requests
))
4389 (now (and (not (custom-variable-p symbol
))
4391 (eq (get symbol
'force-value
)
4393 (comment (get symbol
'saved-variable-comment
)))
4394 ;; Check REQUESTS for validity.
4395 (dolist (request requests
)
4396 (when (and (symbolp request
) (not (featurep request
)))
4397 (message "Unknown requested feature: %s" request
)
4398 (setq requests
(delq request requests
))))
4399 ;; Is there anything customized about this variable?
4400 (when (or (and spec
(eq (car spec
) 'user
))
4402 (and (null spec
) (get symbol
'saved-value
)))
4403 ;; Output an element for this variable.
4404 ;; It has the form (SYMBOL VALUE-FORM NOW REQUESTS COMMENT).
4405 ;; SYMBOL is the variable name.
4406 ;; VALUE-FORM is an expression to return the customized value.
4407 ;; NOW if non-nil means always set the variable immediately
4408 ;; when the customizations are reloaded. This is used
4409 ;; for rogue variables
4410 ;; REQUESTS is a list of packages to load before setting the
4411 ;; variable. Each element of it will be passed to `require'.
4412 ;; COMMENT is whatever comment the user has specified
4413 ;; with the customize facility.
4420 (when (or now requests comment
)
4423 (when (or requests comment
)
4433 (unless (looking-at "\n")
4436 (defun custom-save-faces ()
4437 "Save all customized faces in `custom-file'."
4439 (custom-save-delete 'custom-reset-faces
)
4440 (custom-save-delete 'custom-set-faces
)
4441 (let ((standard-output (current-buffer))
4442 (saved-list (make-list 1 0))
4444 ;; First create a sorted list of saved faces.
4447 (if (and (get symbol
'saved-face
)
4448 (eq 'user
(car (car-safe (get symbol
'theme-face
)))))
4449 (nconc saved-list
(list symbol
)))))
4450 (setq saved-list
(sort (cdr saved-list
) 'string
<))
4451 ;; The default face must be first, since it affects the others.
4452 (if (memq 'default saved-list
)
4453 (setq saved-list
(cons 'default
(delq 'default saved-list
))))
4456 (princ "(custom-set-faces
4457 ;; custom-set-faces was added by Custom.
4458 ;; If you edit it by hand, you could mess it up, so be careful.
4459 ;; Your init file should contain only one such instance.
4460 ;; If there is more than one, they won't work right.\n")
4461 (dolist (symbol saved-list
)
4462 (let ((spec (car-safe (get symbol
'theme-face
)))
4463 (value (get symbol
'saved-face
))
4464 (now (not (or (get symbol
'face-defface-spec
)
4465 (and (not (custom-facep symbol
))
4466 (not (get symbol
'force-face
))))))
4467 (comment (get symbol
'saved-face-comment
)))
4468 (when (or (and spec
(eq (nth 0 spec
) 'user
))
4470 (and (null spec
) (get symbol
'saved-face
)))
4471 ;; Don't print default face here.
4478 (when (or now comment
)
4488 (unless (looking-at "\n")
4491 ;;; The Customize Menu.
4495 (defcustom custom-menu-nesting
2
4496 "Maximum nesting in custom menus."
4498 :group
'custom-menu
)
4500 (defun custom-face-menu-create (widget symbol
)
4501 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
4502 (vector (custom-unlispify-menu-entry symbol
)
4503 `(customize-face ',symbol
)
4506 (defun custom-variable-menu-create (widget symbol
)
4507 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
4508 (let ((type (get symbol
'custom-type
)))
4509 (unless (listp type
)
4510 (setq type
(list type
)))
4511 (if (and type
(widget-get type
:custom-menu
))
4512 (widget-apply type
:custom-menu symbol
)
4513 (vector (custom-unlispify-menu-entry symbol
)
4514 `(customize-variable ',symbol
)
4517 ;; Add checkboxes to boolean variable entries.
4518 (widget-put (get 'boolean
'widget-type
)
4519 :custom-menu
(lambda (widget symbol
)
4520 (vector (custom-unlispify-menu-entry symbol
)
4521 `(customize-variable ',symbol
)
4523 ':selected symbol
)))
4525 (defun custom-group-menu-create (widget symbol
)
4526 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
4527 `( ,(custom-unlispify-menu-entry symbol t
)
4528 :filter
(lambda (&rest junk
)
4529 (let* ((menu (custom-menu-create ',symbol
)))
4530 (if (consp menu
) (cdr menu
) menu
)))))
4533 (defun custom-menu-create (symbol)
4534 "Create menu for customization group SYMBOL.
4535 The menu is in a format applicable to `easy-menu-define'."
4536 (let* ((deactivate-mark nil
)
4537 (item (vector (custom-unlispify-menu-entry symbol
)
4538 `(customize-group ',symbol
)
4540 (if (and (or (not (boundp 'custom-menu-nesting
))
4541 (>= custom-menu-nesting
0))
4543 (custom-load-symbol symbol
)
4544 (< (length (get symbol
'custom-group
)) widget-menu-max-size
)))
4545 (let ((custom-prefix-list (custom-prefix-add symbol
4546 custom-prefix-list
))
4547 (members (custom-sort-items (get symbol
'custom-group
)
4548 custom-menu-sort-alphabetically
4549 custom-menu-order-groups
)))
4550 `(,(custom-unlispify-menu-entry symbol t
)
4553 ,@(mapcar (lambda (entry)
4554 (widget-apply (if (listp (nth 1 entry
))
4556 (list (nth 1 entry
)))
4557 :custom-menu
(nth 0 entry
)))
4562 (defun customize-menu-create (symbol &optional name
)
4563 "Return a customize menu for customization group SYMBOL.
4564 If optional NAME is given, use that as the name of the menu.
4565 Otherwise the menu will be named `Customize'.
4566 The format is suitable for use with `easy-menu-define'."
4568 (setq name
"Customize"))
4570 :filter
(lambda (&rest junk
)
4571 (let ((menu (custom-menu-create ',symbol
)))
4572 (if (consp menu
) (cdr menu
) menu
)))))
4574 ;;; Toolbar and menubar support
4577 Custom-mode-menu
(list custom-mode-map custom-field-keymap
)
4578 "Menu used in customization buffers."
4579 (nconc (list "Custom"
4580 (customize-menu-create 'customize
))
4581 (mapcar (lambda (arg)
4582 (let ((tag (nth 0 arg
))
4583 (command (nth 1 arg
))
4584 (active (nth 2 arg
))
4586 (vector tag command
:active
(eval active
) :help help
)))
4589 (defvar tool-bar-map
)
4591 ;;; `custom-tool-bar-map' used to be set up here. This will fail to
4592 ;;; DTRT when `display-graphic-p' returns nil during compilation. Hence
4593 ;;; we set this up lazily in `Custom-mode'.
4594 (defvar custom-tool-bar-map nil
4595 "Keymap for toolbar in Custom mode.")
4597 ;;; The Custom Mode.
4599 (defun Custom-no-edit (pos &optional event
)
4600 "Invoke button at POS, or refuse to allow editing of Custom buffer."
4602 (error "You can't edit this part of the Custom buffer"))
4604 (defun Custom-newline (pos &optional event
)
4605 "Invoke button at POS, or refuse to allow editing of Custom buffer."
4607 (let ((button (get-char-property pos
'button
)))
4609 (widget-apply-action button event
)
4610 (error "You can't edit this part of the Custom buffer"))))
4612 (defun Custom-goto-parent ()
4613 "Go to the parent group listed at the top of this buffer.
4614 If several parents are listed, go to the first of them."
4617 (goto-char (point-min))
4618 (if (search-forward "\nParent groups: " nil t
)
4619 (let* ((button (get-char-property (point) 'button
))
4620 (parent (downcase (widget-get button
:tag
))))
4621 (customize-group parent
)))))
4623 (defcustom Custom-mode-hook nil
4624 "Hook called when entering Custom mode."
4626 :group
'custom-buffer
)
4628 (defun custom-state-buffer-message (widget)
4629 (if (eq (widget-get (widget-get widget
:parent
) :custom-state
) 'modified
)
4630 (message "To install your edits, invoke [State] and choose the Set operation")))
4632 (define-derived-mode Custom-mode nil
"Custom"
4633 "Major mode for editing customization buffers.
4635 The following commands are available:
4638 Move to next button, link or editable field. \\[widget-forward]
4639 Move to previous button, link or editable field. \\[advertised-widget-backward]
4640 \\<custom-field-keymap>\
4641 Complete content of editable text field. \\[widget-complete]
4642 \\<custom-mode-map>\
4643 Invoke button under the mouse pointer. \\[widget-button-click]
4644 Invoke button under point. \\[widget-button-press]
4645 Set all options from current text. \\[Custom-set]
4646 Make values in current text permanent. \\[Custom-save]
4647 Make text match actual option values. \\[Custom-reset-current]
4648 Reset options to permanent settings. \\[Custom-reset-saved]
4649 Erase customizations; set options
4650 and buffer text to the standard values. \\[Custom-reset-standard]
4652 Entry to this mode calls the value of `Custom-mode-hook'
4653 if that value is non-nil."
4654 (use-local-map custom-mode-map
)
4655 (easy-menu-add Custom-mode-menu
)
4656 (when (display-graphic-p)
4657 (set (make-local-variable 'tool-bar-map
)
4658 (or custom-tool-bar-map
4659 ;; Set up `custom-tool-bar-map'.
4660 (let ((map (make-sparse-keymap)))
4663 (tool-bar-local-item-from-menu
4664 (nth 1 arg
) (nth 4 arg
) map custom-mode-map
))
4666 (setq custom-tool-bar-map map
)))))
4667 (make-local-variable 'custom-options
)
4668 (make-local-variable 'custom-local-buffer
)
4669 (make-local-variable 'widget-documentation-face
)
4670 (setq widget-documentation-face
'custom-documentation
)
4671 (make-local-variable 'widget-button-face
)
4672 (setq widget-button-face custom-button
)
4673 (setq show-trailing-whitespace nil
)
4675 ;; We need this because of the "More" button on docstrings.
4676 ;; Otherwise clicking on "More" can push point offscreen, which
4677 ;; causes the window to recenter on point, which pushes the
4678 ;; newly-revealed docstring offscreen; which is annoying. -- cyd.
4679 (set (make-local-variable 'widget-button-click-moves-point
) t
)
4681 (set (make-local-variable 'widget-button-pressed-face
) custom-button-pressed
)
4682 (set (make-local-variable 'widget-mouse-face
) custom-button-mouse
)
4684 ;; When possible, use relief for buttons, not bracketing. This test
4685 ;; may not be optimal.
4686 (when custom-raised-buttons
4687 (set (make-local-variable 'widget-push-button-prefix
) "")
4688 (set (make-local-variable 'widget-push-button-suffix
) "")
4689 (set (make-local-variable 'widget-link-prefix
) "")
4690 (set (make-local-variable 'widget-link-suffix
) ""))
4691 (add-hook 'widget-edit-functions
'custom-state-buffer-message nil t
))
4693 (put 'Custom-mode
'mode-class
'special
)
4695 ;; backward-compatibility
4696 (defun custom-mode ()
4697 "Non-interactive variant of `Custom-mode'."
4699 (make-obsolete 'custom-mode
'Custom-mode
"23.1")
4700 (put 'custom-mode
'mode-class
'special
)
4701 (define-obsolete-variable-alias 'custom-mode-hook
'Custom-mode-hook
"23.1")
4704 '("^No user option defaults have been changed since Emacs "
4706 "^No \\(?:customized\\|rogue\\|saved\\) user options"
4707 "^No customizable items matching "
4708 "^There are unset changes"
4709 "^Cannot set hidden variable"
4710 "^No \\(?:saved\\|backup\\) value for "
4711 "^No standard setting known for "
4712 "^No standard setting for this face"
4713 "^Saving settings from \"emacs -q\" would overwrite existing customizations"))
4714 (add-to-list 'debug-ignored-errors regexp
))
4720 ;; arch-tag: 64533aa4-1b1a-48c3-8812-f9dc718e8a6f
4721 ;;; cus-edit.el ends here