1 ;;; cus-edit.el --- tools for customizing Emacs and Lisp packages
3 ;; Copyright (C) 1996, 1997, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
7 ;; Keywords: help, faces
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
28 ;; This file implements the code to create and edit customize buffers.
32 ;; No commands should have names starting with `custom-' because
33 ;; that interferes with completion. Use `customize-' for commands
34 ;; that the user will run with M-x, and `Custom-' for interactive commands.
41 (defvar custom-versions-load-alist
)) ; from cus-load
51 (put 'custom-define-hook
'custom-type
'hook
)
52 (put 'custom-define-hook
'standard-value
'(nil))
53 (custom-add-to-group 'customize
'custom-define-hook
'custom-variable
)
55 ;;; Customization Groups.
58 "Customization of the One True Editor."
59 :link
'(custom-manual "(emacs)Top"))
61 ;; Most of these groups are stolen from `finder.el',
63 "Basic text editing facilities."
67 "Abbreviation handling, typing shortcuts, macros."
71 (defgroup matching nil
72 "Various sorts of searching and matching."
75 (defgroup emulations nil
76 "Emulations of other editors."
83 (defgroup outlines nil
84 "Support for hierarchical outlining."
87 (defgroup external nil
88 "Interfacing to external utilities."
92 "Code related to the `bib' bibliography processor."
96 (defgroup processes nil
97 "Process, subshell, compilation, and job control support."
101 (defgroup convenience nil
102 "Convenience features for faster editing."
105 (defgroup programming nil
106 "Support for programming in other languages."
109 (defgroup languages nil
110 "Specialized modes for editing programming languages."
114 "Lisp support, including Emacs Lisp."
119 "Support for the C language and related languages."
127 "Support for object-oriented programming."
130 (defgroup applications nil
131 "Applications written in Emacs."
134 (defgroup calendar nil
135 "Calendar and time management support."
136 :group
'applications
)
139 "Modes for electronic-mail handling."
140 :group
'applications
)
143 "Support for netnews reading and posting."
144 :group
'applications
)
147 "Games, jokes and amusements."
148 :group
'applications
)
150 (defgroup development nil
151 "Support for further development of Emacs."
155 "Support for Emacs documentation."
158 (defgroup extensions nil
159 "Emacs Lisp language extensions."
162 (defgroup internal nil
163 "Code for Emacs internals, build process, defaults."
167 "Maintenance aids for the Emacs development group."
171 (defgroup environment nil
172 "Fitting Emacs with its environment."
176 "Communications, networking, remote access to files."
180 (defgroup hardware nil
181 "Support for interfacing with exotic hardware."
184 (defgroup terminals nil
185 "Support for terminal types."
189 "Front-ends/assistants for, or emulators of, UNIX features."
193 "Support code for vms."
197 "Internationalization and alternate character-set support."
202 "The X Window system."
206 "Support for Emacs frames and window systems."
210 "Support editing files of data."
214 "Support editing files."
222 "Code related to the TeX formatter."
226 "Support for multiple fonts."
229 (defgroup hypermedia nil
230 "Support for links between text or other media types."
234 "Support for on-line help systems."
237 (defgroup multimedia nil
238 "Non-textual support, specifically images and sound."
242 "Code local to your site."
245 (defgroup customize
'((widgets custom-group
))
246 "Customization of the Customization support."
247 :link
'(custom-manual "(elisp)Customization")
248 :link
'(url-link :tag
"(Old?) Development Page"
249 "http://www.dina.kvl.dk/~abraham/custom/")
253 (defgroup custom-faces nil
254 "Faces used by customize."
258 (defgroup custom-browse nil
259 "Control customize browser."
263 (defgroup custom-buffer nil
264 "Control customize buffers."
268 (defgroup custom-menu nil
269 "Control customize menus."
273 (defgroup abbrev-mode nil
274 "Word abbreviations mode."
278 "Storage allocation and gc for GNU Emacs Lisp interpreter."
279 :tag
"Storage Allocation"
283 "Undoing changes in buffers."
286 (defgroup modeline nil
287 "Content of the modeline."
291 "Indenting and filling text."
294 (defgroup editing-basics nil
295 "Most basic editing facilities."
298 (defgroup display nil
299 "How characters are displayed in buffers."
302 (defgroup execute nil
303 "Executing external commands."
306 (defgroup installation nil
307 "The Emacs installation."
315 "Internal Emacs limits."
319 "Debugging Emacs itself."
322 (defgroup minibuffer nil
323 "Controling the behaviour of the minibuffer."
326 (defgroup keyboard nil
327 "Input from the keyboard."
331 "Input from the mouse."
335 "Input from the menus."
338 (defgroup auto-save nil
339 "Preventing accidential loss of data."
342 (defgroup processes-basics nil
343 "Basic stuff dealing with processes."
347 "MULE Emacs internationalization."
350 (defgroup windows nil
351 "Windows within a frame."
356 (defun custom-quote (sexp)
357 "Quote SEXP iff it is not self quoting."
358 (if (or (memq sexp
'(t nil
))
361 (memq (car sexp
) '(lambda)))
365 ;;; (and (fboundp 'characterp)
366 ;;; (characterp sexp))
371 (defun custom-split-regexp-maybe (regexp)
372 "If REGEXP is a string, split it to a list at `\\|'.
373 You can get the original back with from the result with:
374 (mapconcat 'identity result \"\\|\")
376 IF REGEXP is not a string, return it unchanged."
380 (while (string-match "\\\\|" regexp start
)
381 (setq all
(cons (substring regexp start
(match-beginning 0)) all
)
382 start
(match-end 0)))
383 (nreverse (cons (substring regexp start
) all
)))
386 (defun custom-variable-prompt ()
387 "Prompt for a custom variable, defaulting to the variable at point.
388 Return a list suitable for use in `interactive'."
389 (let ((v (variable-at-point))
390 (enable-recursive-minibuffers t
)
392 (setq val
(completing-read
393 (if (and (symbolp v
) (custom-variable-p v
))
394 (format "Customize option: (default %s) " v
)
395 "Customize option: ")
396 obarray
'custom-variable-p t
))
397 (list (if (equal val
"")
398 (if (symbolp v
) v nil
)
401 (defun custom-menu-filter (menu widget
)
402 "Convert MENU to the form used by `widget-choose'.
403 MENU should be in the same format as `custom-variable-menu'.
404 WIDGET is the widget to apply the filter entries of MENU on."
406 current name action filter
)
408 (setq current
(car menu
)
410 action
(nth 1 current
)
411 filter
(nth 2 current
)
413 (if (or (null filter
) (funcall filter widget
))
414 (push (cons name action
) result
)
420 (defvar custom-prefix-list nil
421 "List of prefixes that should be ignored by `custom-unlispify'.")
423 (defcustom custom-unlispify-menu-entries t
424 "Display menu entries as words instead of symbols if non nil."
428 (defcustom custom-unlispify-remove-prefixes nil
429 "Non-nil means remove group prefixes from option names in buffer."
431 :group
'custom-buffer
434 (defun custom-unlispify-menu-entry (symbol &optional no-suffix
)
435 "Convert SYMBOL into a menu entry."
436 (cond ((not custom-unlispify-menu-entries
)
437 (symbol-name symbol
))
438 ((get symbol
'custom-tag
)
440 (get symbol
'custom-tag
)
441 (concat (get symbol
'custom-tag
) "...")))
443 (with-current-buffer (get-buffer-create " *Custom-Work*")
445 (princ symbol
(current-buffer))
446 (goto-char (point-min))
447 ;; FIXME: Boolean variables are not predicates, so they shouldn't
448 ;; end with `-p'. -stef
449 ;; (when (and (eq (get symbol 'custom-type) 'boolean)
450 ;; (re-search-forward "-p\\'" nil t))
451 ;; (replace-match "" t t)
452 ;; (goto-char (point-min)))
453 (if custom-unlispify-remove-prefixes
454 (let ((prefixes custom-prefix-list
)
457 (setq prefix
(car prefixes
))
458 (if (search-forward prefix
(+ (point) (length prefix
)) t
)
461 (delete-region (point-min) (point)))
462 (setq prefixes
(cdr prefixes
))))))
463 (subst-char-in-region (point-min) (point-max) ?- ?\ t
)
464 (capitalize-region (point-min) (point-max))
466 (goto-char (point-max))
470 (defcustom custom-unlispify-tag-names t
471 "Display tag names as words instead of symbols if non nil."
472 :group
'custom-buffer
475 (defun custom-unlispify-tag-name (symbol)
476 "Convert SYMBOL into a menu entry."
477 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names
))
478 (custom-unlispify-menu-entry symbol t
)))
480 (defun custom-prefix-add (symbol prefixes
)
481 "Add SYMBOL to list of ignored PREFIXES."
482 (cons (or (get symbol
'custom-prefix
)
483 (concat (symbol-name symbol
) "-"))
488 (defcustom custom-guess-name-alist
493 ("-function\\'" function
)
494 ("-functions\\'" (repeat function
))
495 ("-list\\'" (repeat sexp
))
496 ("-alist\\'" (repeat (cons sexp sexp
))))
497 "Alist of (MATCH TYPE).
499 MATCH should be a regexp matching the name of a symbol, and TYPE should
500 be a widget suitable for editing the value of that symbol. The TYPE
501 of the first entry where MATCH matches the name of the symbol will be
504 This is used for guessing the type of variables not declared with
506 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
509 (defcustom custom-guess-doc-alist
510 '(("\\`\\*?Non-nil " boolean
))
511 "Alist of (MATCH TYPE).
513 MATCH should be a regexp matching a documentation string, and TYPE
514 should be a widget suitable for editing the value of a variable with
515 that documentation string. The TYPE of the first entry where MATCH
516 matches the name of the symbol will be used.
518 This is used for guessing the type of variables not declared with
520 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
523 (defun custom-guess-type (symbol)
524 "Guess a widget suitable for editing the value of SYMBOL.
525 This is done by matching SYMBOL with `custom-guess-name-alist' and
526 if that fails, the doc string with `custom-guess-doc-alist'."
527 (let ((name (symbol-name symbol
))
528 (names custom-guess-name-alist
)
531 (setq current
(car names
)
533 (when (string-match (nth 0 current
) name
)
534 (setq found
(nth 1 current
)
537 (let ((doc (documentation-property symbol
'variable-documentation
))
538 (docs custom-guess-doc-alist
))
541 (setq current
(car docs
)
543 (when (string-match (nth 0 current
) doc
)
544 (setq found
(nth 1 current
)
550 (defcustom custom-browse-sort-alphabetically nil
551 "If non-nil, sort members of each customization group alphabetically."
553 :group
'custom-browse
)
555 (defcustom custom-browse-order-groups nil
556 "If non-nil, order group members within each customization group.
557 If `first', order groups before non-groups.
558 If `last', order groups after non-groups."
559 :type
'(choice (const first
)
561 (const :tag
"none" nil
))
562 :group
'custom-browse
)
564 (defcustom custom-browse-only-groups nil
565 "If non-nil, show group members only within each customization group."
567 :group
'custom-browse
)
569 (defcustom custom-buffer-sort-alphabetically nil
570 "If non-nil, sort members of each customization group alphabetically."
572 :group
'custom-buffer
)
574 (defcustom custom-buffer-order-groups
'last
575 "If non-nil, order group members within each customization group.
576 If `first', order groups before non-groups.
577 If `last', order groups after non-groups."
578 :type
'(choice (const first
)
580 (const :tag
"none" nil
))
581 :group
'custom-buffer
)
583 (defcustom custom-menu-sort-alphabetically nil
584 "If non-nil, sort members of each customization group alphabetically."
588 (defcustom custom-menu-order-groups
'first
589 "If non-nil, order group members within each customization group.
590 If `first', order groups before non-groups.
591 If `last', order groups after non-groups."
592 :type
'(choice (const first
)
594 (const :tag
"none" nil
))
597 ;;;###autoload (add-hook 'same-window-regexps "\\`\\*Customiz.*\\*\\'")
599 (defun custom-sort-items (items sort-alphabetically order-groups
)
600 "Return a sorted copy of ITEMS.
601 ITEMS should be a `custom-group' property.
602 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
603 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
604 groups after non-groups, if nil do not order groups at all."
605 (sort (copy-sequence items
)
607 (let ((typea (nth 1 a
)) (typeb (nth 1 b
))
608 (namea (nth 0 a
)) (nameb (nth 0 b
)))
609 (cond ((not order-groups
)
610 ;; Since we don't care about A and B order, maybe sort.
611 (when sort-alphabetically
612 (string-lessp namea nameb
)))
613 ((eq typea
'custom-group
)
614 ;; If B is also a group, maybe sort. Otherwise, order A and B.
615 (if (eq typeb
'custom-group
)
616 (when sort-alphabetically
617 (string-lessp namea nameb
))
618 (eq order-groups
'first
)))
619 ((eq typeb
'custom-group
)
620 ;; Since A cannot be a group, order A and B.
621 (eq order-groups
'last
))
623 ;; Since A and B cannot be groups, sort.
624 (string-lessp namea nameb
)))))))
626 ;;; Custom Mode Commands.
628 (defvar custom-options nil
629 "Customization widgets in the current buffer.")
632 "Set changes in all modified options."
634 (let ((children custom-options
))
635 (mapc (lambda (child)
636 (when (eq (widget-get child
:custom-state
) 'modified
)
637 (widget-apply child
:custom-set
)))
640 (defun Custom-save ()
641 "Set all modified group members and save them."
643 (let ((children custom-options
))
644 (mapc (lambda (child)
645 (when (memq (widget-get child
:custom-state
)
646 '(modified set changed rogue
))
647 (widget-apply child
:custom-save
)))
651 (defvar custom-reset-menu
652 '(("Current" . Custom-reset-current
)
653 ("Saved" . Custom-reset-saved
)
654 ("Erase Customization (use standard settings)" . Custom-reset-standard
))
655 "Alist of actions for the `Reset' button.
656 The key is a string containing the name of the action, the value is a
657 Lisp function taking the widget as an element which will be called
658 when the action is chosen.")
660 (defun custom-reset (event)
661 "Select item from reset menu."
662 (let* ((completion-ignore-case t
)
663 (answer (widget-choose "Reset to"
669 (defun Custom-reset-current (&rest ignore
)
670 "Reset all modified group members to their current value."
672 (let ((children custom-options
))
673 (mapc (lambda (widget)
674 (if (memq (widget-get widget
:custom-state
)
676 (widget-apply widget
:custom-reset-current
)))
679 (defun Custom-reset-saved (&rest ignore
)
680 "Reset all modified or set group members to their saved value."
682 (let ((children custom-options
))
683 (mapc (lambda (widget)
684 (if (memq (widget-get widget
:custom-state
)
685 '(modified set changed rogue
))
686 (widget-apply widget
:custom-reset-saved
)))
689 (defun Custom-reset-standard (&rest ignore
)
690 "Erase all customization (either current or saved) for the group members.
691 The immediate result is to restore them to their standard settings.
692 This operation eliminates any saved settings for the group members,
693 making them as if they had never been customized at all."
695 (let ((children custom-options
))
696 (mapc (lambda (widget)
697 (and (widget-apply widget
:custom-standard-value
)
698 (if (memq (widget-get widget
:custom-state
)
699 '(modified set changed saved rogue
))
700 (widget-apply widget
:custom-reset-standard
))))
703 ;;; The Customize Commands
705 (defun custom-prompt-variable (prompt-var prompt-val
&optional comment
)
706 "Prompt for a variable and a value and return them as a list.
707 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
708 prompt for the value. The %s escape in PROMPT-VAL is replaced with
709 the name of the variable.
711 If the variable has a `variable-interactive' property, that is used as if
712 it were the arg to `interactive' (which see) to interactively read the value.
714 If the variable has a `custom-type' property, it must be a widget and the
715 `:prompt-value' property of that widget will be used for reading the value.
717 If optional COMMENT argument is non nil, also prompt for a comment and return
718 it as the third element in the list."
719 (let* ((var (read-variable prompt-var
))
720 (minibuffer-help-form '(describe-variable var
))
722 (let ((prop (get var
'variable-interactive
))
723 (type (get var
'custom-type
))
724 (prompt (format prompt-val var
)))
726 (setq type
(list type
)))
728 ;; Use VAR's `variable-interactive' property
729 ;; as an interactive spec for prompting.
730 (call-interactively (list 'lambda
'(arg)
731 (list 'interactive prop
)
734 (widget-prompt-value type
740 (eval-minibuffer prompt
))))))
743 (read-string "Comment: " (get var
'variable-comment
)))
747 (defun customize-set-value (variable value
&optional comment
)
748 "Set VARIABLE to VALUE, and return VALUE. VALUE is a Lisp object.
750 If VARIABLE has a `variable-interactive' property, that is used as if
751 it were the arg to `interactive' (which see) to interactively read the value.
753 If VARIABLE has a `custom-type' property, it must be a widget and the
754 `:prompt-value' property of that widget will be used for reading the value.
756 If given a prefix (or a COMMENT argument), also prompt for a comment."
757 (interactive (custom-prompt-variable "Set variable: "
761 (cond ((string= comment
"")
762 (put variable
'variable-comment nil
))
764 (put variable
'variable-comment comment
)))
765 (set variable value
))
768 (defun customize-set-variable (variable value
&optional comment
)
769 "Set the default for VARIABLE to VALUE, and return VALUE.
770 VALUE is a Lisp object.
772 If VARIABLE has a `custom-set' property, that is used for setting
773 VARIABLE, otherwise `set-default' is used.
775 The `customized-value' property of the VARIABLE will be set to a list
776 with a quoted VALUE as its sole list member.
778 If VARIABLE has a `variable-interactive' property, that is used as if
779 it were the arg to `interactive' (which see) to interactively read the value.
781 If VARIABLE has a `custom-type' property, it must be a widget and the
782 `:prompt-value' property of that widget will be used for reading the value.
784 If given a prefix (or a COMMENT argument), also prompt for a comment."
785 (interactive (custom-prompt-variable "Set variable: "
786 "Set customized value for %s to: "
788 (custom-load-symbol variable
)
789 (funcall (or (get variable
'custom-set
) 'set-default
) variable value
)
790 (put variable
'customized-value
(list (custom-quote value
)))
791 (cond ((string= comment
"")
792 (put variable
'variable-comment nil
)
793 (put variable
'customized-variable-comment nil
))
795 (put variable
'variable-comment comment
)
796 (put variable
'customized-variable-comment comment
)))
800 (defun customize-save-variable (variable value
&optional comment
)
801 "Set the default for VARIABLE to VALUE, and save it for future sessions.
804 If VARIABLE has a `custom-set' property, that is used for setting
805 VARIABLE, otherwise `set-default' is used.
807 The `customized-value' property of the VARIABLE will be set to a list
808 with a quoted VALUE as its sole list member.
810 If VARIABLE has a `variable-interactive' property, that is used as if
811 it were the arg to `interactive' (which see) to interactively read the value.
813 If VARIABLE has a `custom-type' property, it must be a widget and the
814 `:prompt-value' property of that widget will be used for reading the value.
816 If given a prefix (or a COMMENT argument), also prompt for a comment."
817 (interactive (custom-prompt-variable "Set and save variable: "
818 "Set and save value for %s as: "
820 (funcall (or (get variable
'custom-set
) 'set-default
) variable value
)
821 (put variable
'saved-value
(list (custom-quote value
)))
822 (custom-push-theme 'theme-value variable
'user
'set
(list (custom-quote value
)))
823 (cond ((string= comment
"")
824 (put variable
'variable-comment nil
)
825 (put variable
'saved-variable-comment nil
))
827 (put variable
'variable-comment comment
)
828 (put variable
'saved-variable-comment comment
)))
834 "Select a customization buffer which you can use to set user options.
835 User options are structured into \"groups\".
836 Initially the top-level group `Emacs' and its immediate subgroups
837 are shown; the contents of those subgroups are initially hidden."
839 (customize-group 'emacs
))
842 (defun customize-mode (mode)
843 "Customize options related to the current major mode.
844 If a prefix \\[universal-argument] was given (or if the current major mode has no known group),
845 then prompt for the MODE to customize."
848 (let ((completion-regexp-list '("-mode\\'"))
849 (group (custom-group-of-mode major-mode
)))
850 (if (and group
(not current-prefix-arg
))
853 (completing-read (if group
854 (format "Major mode (default %s): " major-mode
)
857 'custom-group-of-mode
858 t nil nil
(if group
(symbol-name major-mode
))))))))
859 (customize-group (custom-group-of-mode mode
)))
863 (defun customize-group (group)
864 "Customize GROUP, which must be a customization group."
865 (interactive (list (let ((completion-ignore-case t
))
866 (completing-read "Customize group: (default emacs) "
869 (or (get symbol
'custom-loads
)
870 (get symbol
'custom-group
)))
872 (when (stringp group
)
873 (if (string-equal "" group
)
875 (setq group
(intern group
))))
876 (let ((name (format "*Customize Group: %s*"
877 (custom-unlispify-tag-name group
))))
878 (if (get-buffer name
)
880 (custom-buffer-create (list (list group
'custom-group
))
882 (concat " for group "
883 (custom-unlispify-tag-name group
))))))
886 (defun customize-group-other-window (group)
887 "Customize GROUP, which must be a customization group."
888 (interactive (list (let ((completion-ignore-case t
))
889 (completing-read "Customize group: (default emacs) "
892 (or (get symbol
'custom-loads
)
893 (get symbol
'custom-group
)))
895 (when (stringp group
)
896 (if (string-equal "" group
)
898 (setq group
(intern group
))))
899 (let ((name (format "*Customize Group: %s*"
900 (custom-unlispify-tag-name group
))))
901 (if (get-buffer name
)
902 (let ((window (selected-window))
903 ;; Copied from `custom-buffer-create-other-window'.
905 (special-display-buffer-names nil
)
906 (special-display-regexps nil
)
907 (same-window-buffer-names nil
)
908 (same-window-regexps nil
))
910 (select-window window
))
911 (custom-buffer-create-other-window
912 (list (list group
'custom-group
))
914 (concat " for group "
915 (custom-unlispify-tag-name group
))))))
918 (defalias 'customize-variable
'customize-option
)
921 (defun customize-option (symbol)
922 "Customize SYMBOL, which must be a user option variable."
923 (interactive (custom-variable-prompt))
924 (custom-buffer-create (list (list symbol
'custom-variable
))
925 (format "*Customize Option: %s*"
926 (custom-unlispify-tag-name symbol
))))
929 (defalias 'customize-variable-other-window
'customize-option-other-window
)
932 (defun customize-option-other-window (symbol)
933 "Customize SYMBOL, which must be a user option variable.
934 Show the buffer in another window, but don't select it."
935 (interactive (custom-variable-prompt))
936 (custom-buffer-create-other-window
937 (list (list symbol
'custom-variable
))
938 (format "*Customize Option: %s*" (custom-unlispify-tag-name symbol
))))
940 (defvar customize-changed-options-previous-release
"20.2"
941 "Version for `customize-changed-options' to refer back to by default.")
944 (defun customize-changed-options (since-version)
945 "Customize all user option variables changed in Emacs itself.
946 This includes new user option variables and faces, and new
947 customization groups, as well as older options and faces whose default
948 values have changed since the previous major Emacs release.
950 With argument SINCE-VERSION (a string), customize all user option
951 variables that were added (or their meanings were changed) since that
954 (interactive "sCustomize options changed, since version (default all versions): ")
955 (if (equal since-version
"")
956 (setq since-version nil
)
957 (unless (condition-case nil
958 (numberp (read since-version
))
960 (signal 'wrong-type-argument
(list 'numberp since-version
))))
961 (unless since-version
962 (setq since-version customize-changed-options-previous-release
))
964 ;; Load the information for versions since since-version. We use
965 ;; custom-load-symbol for this.
966 (put 'custom-versions-load-alist
'custom-loads nil
)
967 (dolist (elt custom-versions-load-alist
)
968 (if (customize-version-lessp since-version
(car elt
))
969 (dolist (load (cdr elt
))
970 (custom-add-load 'custom-versions-load-alist load
))))
971 (custom-load-symbol 'custom-versions-load-alist
)
972 (put 'custom-versions-load-alist
'custom-loads nil
)
977 (let ((version (get symbol
'custom-version
)))
979 (when (customize-version-lessp since-version version
)
980 (if (or (get symbol
'custom-group
)
981 (get symbol
'group-documentation
))
982 (push (list symbol
'custom-group
) found
))
983 (if (custom-variable-p symbol
)
984 (push (list symbol
'custom-variable
) found
))
985 (if (custom-facep symbol
)
986 (push (list symbol
'custom-face
) found
)))))))
988 (custom-buffer-create (custom-sort-items found t
'first
)
989 "*Customize Changed Options*")
990 (error "No user option defaults have been changed since Emacs %s"
993 (defun customize-version-lessp (version1 version2
)
994 ;; Why are the versions strings, and given that they are, why aren't
995 ;; they converted to numbers and compared as such here? -- fx
997 ;; In case someone made a mistake and left out the quotes
998 ;; in the :version value.
999 (if (numberp version2
)
1000 (setq version2
(prin1-to-string version2
)))
1001 (let (major1 major2 minor1 minor2
)
1002 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version1
)
1003 (setq major1
(read (or (match-string 1 version1
)
1005 (setq minor1
(read (or (match-string 3 version1
)
1007 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version2
)
1008 (setq major2
(read (or (match-string 1 version2
)
1010 (setq minor2
(read (or (match-string 3 version2
)
1012 (or (< major1 major2
)
1013 (and (= major1 major2
)
1014 (< minor1 minor2
)))))
1017 (defun customize-face (&optional face
)
1018 "Customize SYMBOL, which should be a face name or nil.
1019 If SYMBOL is nil, customize all faces.
1021 Interactively, when point is on text which has a face specified,
1022 suggest to customized that face, if it's customizable."
1024 (list (read-face-name "Customize face" "all faces" t
)))
1025 (if (member face
'(nil ""))
1026 (setq face
(face-list)))
1027 (if (and (listp face
) (null (cdr face
)))
1028 (setq face
(car face
)))
1030 (custom-buffer-create (custom-sort-items
1032 (list s
'custom-face
))
1035 "*Customize Faces*")
1036 (unless (facep face
)
1037 (error "Invalid face %S" face
))
1038 (custom-buffer-create (list (list face
'custom-face
))
1039 (format "*Customize Face: %s*"
1040 (custom-unlispify-tag-name face
)))))
1043 (defun customize-face-other-window (&optional face
)
1044 "Show customization buffer for face SYMBOL in other window.
1046 Interactively, when point is on text which has a face specified,
1047 suggest to customized that face, if it's customizable."
1049 (list (read-face-name "Customize face" "all faces" t
)))
1050 (if (member face
'(nil ""))
1051 (setq face
(face-list)))
1052 (if (and (listp face
) (null (cdr face
)))
1053 (setq face
(car face
)))
1055 (custom-buffer-create-other-window
1058 (list s
'custom-face
))
1061 "*Customize Faces*")
1062 (unless (facep face
)
1063 (error "Invalid face %S" face
))
1064 (custom-buffer-create-other-window
1065 (list (list face
'custom-face
))
1066 (format "*Customize Face: %s*"
1067 (custom-unlispify-tag-name face
)))))
1070 (defun customize-customized ()
1071 "Customize all user options set since the last save in this session."
1074 (mapatoms (lambda (symbol)
1075 (and (or (get symbol
'customized-face
)
1076 (get symbol
'customized-face-comment
))
1077 (custom-facep symbol
)
1078 (push (list symbol
'custom-face
) found
))
1079 (and (or (get symbol
'customized-value
)
1080 (get symbol
'customized-variable-comment
))
1082 (push (list symbol
'custom-variable
) found
))))
1084 (error "No customized user options")
1085 (custom-buffer-create (custom-sort-items found t nil
)
1086 "*Customize Customized*"))))
1089 (defun customize-saved ()
1090 "Customize all already saved user options."
1093 (mapatoms (lambda (symbol)
1094 (and (or (get symbol
'saved-face
)
1095 (get symbol
'saved-face-comment
))
1096 (custom-facep symbol
)
1097 (push (list symbol
'custom-face
) found
))
1098 (and (or (get symbol
'saved-value
)
1099 (get symbol
'saved-variable-comment
))
1101 (push (list symbol
'custom-variable
) found
))))
1103 (error "No saved user options")
1104 (custom-buffer-create (custom-sort-items found t nil
)
1105 "*Customize Saved*"))))
1108 (defun customize-apropos (regexp &optional all
)
1109 "Customize all user options matching REGEXP.
1110 If ALL is `options', include only options.
1111 If ALL is `faces', include only faces.
1112 If ALL is `groups', include only groups.
1113 If ALL is t (interactively, with prefix arg), include options which are not
1114 user-settable, as well as faces and groups."
1115 (interactive "sCustomize regexp: \nP")
1117 (mapatoms (lambda (symbol)
1118 (when (string-match regexp
(symbol-name symbol
))
1119 (when (and (not (memq all
'(faces options
)))
1120 (get symbol
'custom-group
))
1121 (push (list symbol
'custom-group
) found
))
1122 (when (and (not (memq all
'(options groups
)))
1123 (custom-facep symbol
))
1124 (push (list symbol
'custom-face
) found
))
1125 (when (and (not (memq all
'(groups faces
)))
1127 (or (get symbol
'saved-value
)
1128 (custom-variable-p symbol
)
1129 (if (memq all
'(nil options
))
1130 (user-variable-p symbol
)
1131 (get symbol
'variable-documentation
))))
1132 (push (list symbol
'custom-variable
) found
)))))
1134 (error "No matches")
1135 (custom-buffer-create (custom-sort-items found t
1136 custom-buffer-order-groups
)
1137 "*Customize Apropos*"))))
1140 (defun customize-apropos-options (regexp &optional arg
)
1141 "Customize all user options matching REGEXP.
1142 With prefix arg, include options which are not user-settable."
1143 (interactive "sCustomize regexp: \nP")
1144 (customize-apropos regexp
(or arg
'options
)))
1147 (defun customize-apropos-faces (regexp)
1148 "Customize all user faces matching REGEXP."
1149 (interactive "sCustomize regexp: \n")
1150 (customize-apropos regexp
'faces
))
1153 (defun customize-apropos-groups (regexp)
1154 "Customize all user groups matching REGEXP."
1155 (interactive "sCustomize regexp: \n")
1156 (customize-apropos regexp
'groups
))
1160 (defcustom custom-buffer-style
'links
1161 "Control the presentation style for customization buffers.
1162 The value should be a symbol, one of:
1164 brackets: groups nest within each other with big horizontal brackets.
1165 links: groups have links to subgroups."
1166 :type
'(radio (const brackets
)
1168 :group
'custom-buffer
)
1170 ;; If we pass BUFFER to `bury-buffer', the buffer isn't removed from
1172 (defun custom-bury-buffer (buffer)
1175 (defcustom custom-buffer-done-function
'custom-bury-buffer
1176 "*Function called to remove a Custom buffer when the user is done with it.
1177 Called with one argument, the buffer to remove."
1178 :type
'(choice (function-item :tag
"Bury buffer" custom-bury-buffer
)
1179 (function-item :tag
"Kill buffer" kill-buffer
)
1180 (function :tag
"Other"))
1182 :group
'custom-buffer
)
1184 (defcustom custom-buffer-indent
3
1185 "Number of spaces to indent nested groups."
1187 :group
'custom-buffer
)
1190 (defun custom-buffer-create (options &optional name description
)
1191 "Create a buffer containing OPTIONS.
1192 Optional NAME is the name of the buffer.
1193 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1194 SYMBOL is a customization option, and WIDGET is a widget for editing
1196 (unless name
(setq name
"*Customization*"))
1197 (kill-buffer (get-buffer-create name
))
1198 (pop-to-buffer (get-buffer-create name
))
1199 (custom-buffer-create-internal options description
))
1202 (defun custom-buffer-create-other-window (options &optional name description
)
1203 "Create a buffer containing OPTIONS.
1204 Optional NAME is the name of the buffer.
1205 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1206 SYMBOL is a customization option, and WIDGET is a widget for editing
1208 (unless name
(setq name
"*Customization*"))
1209 (kill-buffer (get-buffer-create name
))
1210 (let ((window (selected-window))
1212 (special-display-buffer-names nil
)
1213 (special-display-regexps nil
)
1214 (same-window-buffer-names nil
)
1215 (same-window-regexps nil
))
1216 (pop-to-buffer (get-buffer-create name
))
1217 (custom-buffer-create-internal options description
)
1218 (select-window window
)))
1220 (defcustom custom-reset-button-menu nil
1221 "If non-nil, only show a single reset button in customize buffers.
1222 This button will have a menu with all three reset operations."
1224 :group
'custom-buffer
)
1226 (defcustom custom-buffer-verbose-help t
1227 "If non-nil, include explanatory text in the customization buffer."
1229 :group
'custom-buffer
)
1231 (defun Custom-buffer-done (&rest ignore
)
1232 "Remove current buffer by calling `custom-buffer-done-function'."
1234 (funcall custom-buffer-done-function
(current-buffer)))
1236 (defcustom custom-raised-buttons
(not (equal (face-valid-attribute-values :box
)
1237 '(("unspecified" . unspecified
))))
1238 "If non-nil, indicate active buttons in a `raised-button' style.
1239 Otherwise use brackets."
1242 :group
'custom-buffer
)
1244 (defun custom-buffer-create-internal (options &optional description
)
1245 (message "Creating customization buffer...")
1247 (if custom-buffer-verbose-help
1249 (widget-insert "This is a customization buffer")
1251 (widget-insert description
))
1252 (widget-insert (format ".
1253 %s show active fields; type RET or click mouse-1
1254 on an active field to invoke its action. Editing an option value
1255 changes the text in the buffer; invoke the State button and
1256 choose the Set operation to set the option value.
1257 Invoke " (if custom-raised-buttons
1259 "Square brackets")))
1260 (widget-create 'info-link
1262 :help-echo
"Read the online help."
1263 "(emacs)Easy Customization")
1264 (widget-insert " for more information.\n\n")
1265 (message "Creating customization buttons...")
1266 (widget-insert "Operate on everything in this buffer:\n "))
1267 (widget-insert " "))
1268 (widget-create 'push-button
1269 :tag
"Set for Current Session"
1271 Make your editing in this buffer take effect for this session."
1272 :action
(lambda (widget &optional event
)
1275 (widget-create 'push-button
1276 :tag
"Save for Future Sessions"
1278 Make your editing in this buffer take effect for future Emacs sessions."
1279 :action
(lambda (widget &optional event
)
1281 (if custom-reset-button-menu
1284 (widget-create 'push-button
1286 :help-echo
"Show a menu with reset operations."
1287 :mouse-down-action
(lambda (&rest junk
) t
)
1288 :action
(lambda (widget &optional event
)
1289 (custom-reset event
))))
1290 (widget-insert "\n ")
1291 (widget-create 'push-button
1294 Reset all edited text in this buffer to reflect current values."
1295 :action
'Custom-reset-current
)
1297 (widget-create 'push-button
1298 :tag
"Reset to Saved"
1300 Reset all values in this buffer to their saved settings."
1301 :action
'Custom-reset-saved
)
1303 (widget-create 'push-button
1304 :tag
"Erase Customization"
1306 Un-customize all values in this buffer. They get their standard settings."
1307 :action
'Custom-reset-standard
))
1308 (if (not custom-buffer-verbose-help
)
1311 (widget-create 'info-link
1313 :help-echo
"Read the online help."
1314 "(emacs)Easy Customization")))
1316 (widget-create 'push-button
1319 (lambda (&rest ignore
)
1321 ((eq custom-buffer-done-function
1322 'custom-bury-buffer
)
1324 ((eq custom-buffer-done-function
'kill-buffer
)
1326 (t "Finish with this buffer")))
1327 :action
#'Custom-buffer-done
)
1328 (widget-insert "\n\n")
1329 (message "Creating customization items...")
1330 (buffer-disable-undo)
1331 (setq custom-options
1332 (if (= (length options
) 1)
1333 (mapcar (lambda (entry)
1334 (widget-create (nth 1 entry
)
1335 :documentation-shown t
1336 :custom-state
'unknown
1337 :tag
(custom-unlispify-tag-name
1339 :value
(nth 0 entry
)))
1342 (length (length options
)))
1343 (mapcar (lambda (entry)
1345 (message "Creating customization items ...%2d%%"
1346 (/ (* 100.0 count
) length
))
1347 (widget-create (nth 1 entry
)
1348 :tag
(custom-unlispify-tag-name
1350 :value
(nth 0 entry
))
1351 (setq count
(1+ count
))
1352 (unless (eq (preceding-char) ?
\n)
1353 (widget-insert "\n"))
1354 (widget-insert "\n")))
1356 (unless (eq (preceding-char) ?
\n)
1357 (widget-insert "\n"))
1358 (message "Creating customization items ...done")
1359 (unless (eq custom-buffer-style
'tree
)
1360 (mapc 'custom-magic-reset custom-options
))
1361 (message "Creating customization setup...")
1363 (buffer-enable-undo)
1364 (goto-char (point-min))
1365 (message "Creating customization buffer...done"))
1367 ;;; The Tree Browser.
1370 (defun customize-browse (&optional group
)
1371 "Create a tree browser for the customize hierarchy."
1374 (setq group
'emacs
))
1375 (let ((name "*Customize Browser*"))
1376 (kill-buffer (get-buffer-create name
))
1377 (pop-to-buffer (get-buffer-create name
)))
1380 Square brackets show active fields; type RET or click mouse-1
1381 on an active field to invoke its action.
1382 Invoke [+] below to expand a group, and [-] to collapse an expanded group.\n")
1383 (if custom-browse-only-groups
1385 Invoke the [Group] button below to edit that item in another window.\n\n")
1386 (widget-insert "Invoke the ")
1387 (widget-create 'item
1390 :tag-glyph
"folder")
1391 (widget-insert ", ")
1392 (widget-create 'item
1396 (widget-insert ", and ")
1397 (widget-create 'item
1400 :tag-glyph
"option")
1401 (widget-insert " buttons below to edit that
1402 item in another window.\n\n"))
1403 (let ((custom-buffer-style 'tree
))
1404 (widget-create 'custom-group
1406 :custom-state
'unknown
1407 :tag
(custom-unlispify-tag-name group
)
1410 (goto-char (point-min)))
1412 (define-widget 'custom-browse-visibility
'item
1413 "Control visibility of items in the customize tree browser."
1415 :action
'custom-browse-visibility-action
)
1417 (defun custom-browse-visibility-action (widget &rest ignore
)
1418 (let ((custom-buffer-style 'tree
))
1419 (custom-toggle-parent widget
)))
1421 (define-widget 'custom-browse-group-tag
'push-button
1422 "Show parent in other window when activated."
1425 :action
'custom-browse-group-tag-action
)
1427 (defun custom-browse-group-tag-action (widget &rest ignore
)
1428 (let ((parent (widget-get widget
:parent
)))
1429 (customize-group-other-window (widget-value parent
))))
1431 (define-widget 'custom-browse-variable-tag
'push-button
1432 "Show parent in other window when activated."
1435 :action
'custom-browse-variable-tag-action
)
1437 (defun custom-browse-variable-tag-action (widget &rest ignore
)
1438 (let ((parent (widget-get widget
:parent
)))
1439 (customize-variable-other-window (widget-value parent
))))
1441 (define-widget 'custom-browse-face-tag
'push-button
1442 "Show parent in other window when activated."
1445 :action
'custom-browse-face-tag-action
)
1447 (defun custom-browse-face-tag-action (widget &rest ignore
)
1448 (let ((parent (widget-get widget
:parent
)))
1449 (customize-face-other-window (widget-value parent
))))
1451 (defconst custom-browse-alist
'((" " "space")
1457 (defun custom-browse-insert-prefix (prefix)
1458 "Insert PREFIX. On XEmacs convert it to line graphics."
1459 ;; Fixme: do graphics.
1460 (if nil
; (string-match "XEmacs" emacs-version)
1463 (while (not (string-equal prefix
""))
1464 (let ((entry (substring prefix
0 3)))
1465 (setq prefix
(substring prefix
3))
1466 (let ((overlay (make-overlay (1- (point)) (point) nil t nil
))
1467 (name (nth 1 (assoc entry custom-browse-alist
))))
1468 (overlay-put overlay
'end-glyph
(widget-glyph-find name entry
))
1469 (overlay-put overlay
'start-open t
)
1470 (overlay-put overlay
'end-open t
)))))
1473 ;;; Modification of Basic Widgets.
1475 ;; We add extra properties to the basic widgets needed here. This is
1476 ;; fine, as long as we are careful to stay within out own namespace.
1478 ;; We want simple widgets to be displayed by default, but complex
1479 ;; widgets to be hidden.
1481 (widget-put (get 'item
'widget-type
) :custom-show t
)
1482 (widget-put (get 'editable-field
'widget-type
)
1483 :custom-show
(lambda (widget value
)
1484 (let ((pp (pp-to-string value
)))
1485 (cond ((string-match "\n" pp
)
1490 (widget-put (get 'menu-choice
'widget-type
) :custom-show t
)
1492 ;;; The `custom-manual' Widget.
1494 (define-widget 'custom-manual
'info-link
1495 "Link to the manual entry for this customization option."
1496 :help-echo
"Read the manual entry for this option."
1499 ;;; The `custom-magic' Widget.
1501 (defgroup custom-magic-faces nil
1502 "Faces used by the magic button."
1503 :group
'custom-faces
1504 :group
'custom-buffer
)
1506 (defface custom-invalid-face
'((((class color
))
1507 (:foreground
"yellow" :background
"red"))
1509 (:weight bold
:slant italic
:underline t
)))
1510 "Face used when the customize item is invalid."
1511 :group
'custom-magic-faces
)
1513 (defface custom-rogue-face
'((((class color
))
1514 (:foreground
"pink" :background
"black"))
1517 "Face used when the customize item is not defined for customization."
1518 :group
'custom-magic-faces
)
1520 (defface custom-modified-face
'((((class color
))
1521 (:foreground
"white" :background
"blue"))
1523 (:slant italic
:bold
)))
1524 "Face used when the customize item has been modified."
1525 :group
'custom-magic-faces
)
1527 (defface custom-set-face
'((((class color
))
1528 (:foreground
"blue" :background
"white"))
1531 "Face used when the customize item has been set."
1532 :group
'custom-magic-faces
)
1534 (defface custom-changed-face
'((((class color
))
1535 (:foreground
"white" :background
"blue"))
1538 "Face used when the customize item has been changed."
1539 :group
'custom-magic-faces
)
1541 (defface custom-saved-face
'((t (:underline t
)))
1542 "Face used when the customize item has been saved."
1543 :group
'custom-magic-faces
)
1545 (defconst custom-magic-alist
'((nil "#" underline
"\
1546 uninitialized, you should not see this.")
1547 (unknown "?" italic
"\
1548 unknown, you should not see this.")
1549 (hidden "-" default
"\
1550 hidden, invoke \"Show\" in the previous line to show." "\
1551 group now hidden, invoke \"Show\", above, to show contents.")
1552 (invalid "x" custom-invalid-face
"\
1553 the value displayed for this %c is invalid and cannot be set.")
1554 (modified "*" custom-modified-face
"\
1555 you have edited the value as text, but you have not set the %c." "\
1556 you have edited something in this group, but not set it.")
1557 (set "+" custom-set-face
"\
1558 you have set this %c, but not saved it for future sessions." "\
1559 something in this group has been set, but not saved.")
1560 (changed ":" custom-changed-face
"\
1561 this %c has been changed outside the customize buffer." "\
1562 something in this group has been changed outside customize.")
1563 (saved "!" custom-saved-face
"\
1564 this %c has been set and saved." "\
1565 something in this group has been set and saved.")
1566 (rogue "@" custom-rogue-face
"\
1567 this %c has not been changed with customize." "\
1568 something in this group is not prepared for customization.")
1569 (standard " " nil
"\
1570 this %c is unchanged from its standard setting." "\
1571 visible group members are all at standard settings."))
1572 "Alist of customize option states.
1573 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1575 STATE is one of the following symbols:
1578 For internal use, should never occur.
1580 For internal use, should never occur.
1582 This item is not being displayed.
1584 This item is modified, but has an invalid form.
1586 This item is modified, and has a valid form.
1588 This item has been set but not saved.
1590 The current value of this item has been changed temporarily.
1592 This item is marked for saving.
1594 This item has no customization information.
1596 This item is unchanged from the standard setting.
1598 MAGIC is a string used to present that state.
1600 FACE is a face used to present the state.
1602 ITEM-DESC is a string describing the state for options.
1604 GROUP-DESC is a string describing the state for groups. If this is
1605 left out, ITEM-DESC will be used.
1607 The string %c in either description will be replaced with the
1608 category of the item. These are `group'. `option', and `face'.
1610 The list should be sorted most significant first.")
1612 (defcustom custom-magic-show
'long
1613 "If non-nil, show textual description of the state.
1614 If `long', show a full-line description, not just one word."
1615 :type
'(choice (const :tag
"no" nil
)
1617 (other :tag
"short" short
))
1618 :group
'custom-buffer
)
1620 (defcustom custom-magic-show-hidden
'(option face
)
1621 "Control whether the State button is shown for hidden items.
1622 The value should be a list with the custom categories where the State
1623 button should be visible. Possible categories are `group', `option',
1625 :type
'(set (const group
) (const option
) (const face
))
1626 :group
'custom-buffer
)
1628 (defcustom custom-magic-show-button nil
1629 "Show a \"magic\" button indicating the state of each customization option."
1631 :group
'custom-buffer
)
1633 (define-widget 'custom-magic
'default
1634 "Show and manipulate state for a customization option."
1636 :action
'widget-parent-action
1639 :value-create
'custom-magic-value-create
1640 :value-delete
'widget-children-value-delete
)
1642 (defun widget-magic-mouse-down-action (widget &optional event
)
1643 ;; Non-nil unless hidden.
1644 (not (eq (widget-get (widget-get (widget-get widget
:parent
) :parent
)
1648 (defun custom-magic-value-create (widget)
1649 "Create compact status report for WIDGET."
1650 (let* ((parent (widget-get widget
:parent
))
1651 (state (widget-get parent
:custom-state
))
1652 (hidden (eq state
'hidden
))
1653 (entry (assq state custom-magic-alist
))
1654 (magic (nth 1 entry
))
1655 (face (nth 2 entry
))
1656 (category (widget-get parent
:custom-category
))
1657 (text (or (and (eq category
'group
)
1660 (form (widget-get parent
:custom-form
))
1662 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text
)
1663 (setq text
(concat (match-string 1 text
)
1664 (symbol-name category
)
1665 (match-string 2 text
))))
1666 (when (and custom-magic-show
1668 (memq category custom-magic-show-hidden
)))
1670 (when (and (eq category
'group
)
1671 (not (and (eq custom-buffer-style
'links
)
1672 (> (widget-get parent
:custom-level
) 1))))
1673 (insert-char ?\
(* custom-buffer-indent
1674 (widget-get parent
:custom-level
))))
1675 (push (widget-create-child-and-convert
1677 :help-echo
"Change the state of this item."
1678 :format
(if hidden
"%t" "%[%t%]")
1679 :button-prefix
'widget-push-button-prefix
1680 :button-suffix
'widget-push-button-suffix
1681 :mouse-down-action
'widget-magic-mouse-down-action
1685 (let ((start (point)))
1686 (if (eq custom-magic-show
'long
)
1688 (insert (symbol-name state
)))
1689 (cond ((eq form
'lisp
)
1691 ((eq form
'mismatch
)
1692 (insert " (mismatch)")))
1693 (put-text-property start
(point) 'face
'custom-state-face
))
1695 (when (and (eq category
'group
)
1696 (not (and (eq custom-buffer-style
'links
)
1697 (> (widget-get parent
:custom-level
) 1))))
1698 (insert-char ?\
(* custom-buffer-indent
1699 (widget-get parent
:custom-level
))))
1700 (when custom-magic-show-button
1701 (when custom-magic-show
1702 (let ((indent (widget-get parent
:indent
)))
1704 (insert-char ? indent
))))
1705 (push (widget-create-child-and-convert
1707 :mouse-down-action
'widget-magic-mouse-down-action
1711 :help-echo
"Change the state."
1712 :format
(if hidden
"%t" "%[%t%]")
1713 :tag
(if (memq form
'(lisp mismatch
))
1714 (concat "(" magic
")")
1715 (concat "[" magic
"]")))
1718 (widget-put widget
:children children
)))
1720 (defun custom-magic-reset (widget)
1721 "Redraw the :custom-magic property of WIDGET."
1722 (let ((magic (widget-get widget
:custom-magic
)))
1723 (widget-value-set magic
(widget-value magic
))))
1725 ;;; The `custom' Widget.
1727 (defface custom-button-face
1728 '((((type x w32 mac
) (class color
)) ; Like default modeline
1729 (:box
(:line-width
2 :style released-button
)
1730 :background
"lightgrey" :foreground
"black"))
1733 "Face used for buttons in customization buffers."
1735 :group
'custom-faces
)
1737 (defface custom-button-pressed-face
1738 '((((type x w32 mac
) (class color
))
1739 (:box
(:line-width
2 :style pressed-button
)
1740 :background
"lightgrey" :foreground
"black"))
1742 (:inverse-video t
)))
1743 "Face used for buttons in customization buffers."
1745 :group
'custom-faces
)
1747 (defface custom-documentation-face nil
1748 "Face used for documentation strings in customization buffers."
1749 :group
'custom-faces
)
1751 (defface custom-state-face
'((((class color
)
1753 (:foreground
"lime green"))
1756 (:foreground
"dark green"))
1758 "Face used for State descriptions in the customize buffer."
1759 :group
'custom-faces
)
1761 (define-widget 'custom
'default
1762 "Customize a user option."
1764 :convert-widget
'custom-convert-widget
1765 :notify
'custom-notify
1768 :custom-state
'hidden
1769 :documentation-property
'widget-subclass-responsibility
1770 :value-create
'widget-subclass-responsibility
1771 :value-delete
'widget-children-value-delete
1772 :value-get
'widget-value-value-get
1773 :validate
'widget-children-validate
1774 :match
(lambda (widget value
) (symbolp value
)))
1776 (defun custom-convert-widget (widget)
1777 "Initialize :value and :tag from :args in WIDGET."
1778 (let ((args (widget-get widget
:args
)))
1780 (widget-put widget
:value
(widget-apply widget
1781 :value-to-internal
(car args
)))
1782 (widget-put widget
:tag
(custom-unlispify-tag-name (car args
)))
1783 (widget-put widget
:args nil
)))
1786 (defun custom-notify (widget &rest args
)
1787 "Keep track of changes."
1788 (let ((state (widget-get widget
:custom-state
)))
1789 (unless (eq state
'modified
)
1790 (unless (memq state
'(nil unknown hidden
))
1791 (widget-put widget
:custom-state
'modified
))
1792 (custom-magic-reset widget
)
1793 (apply 'widget-default-notify widget args
))))
1795 (defun custom-redraw (widget)
1796 "Redraw WIDGET with current settings."
1797 (let ((line (count-lines (point-min) (point)))
1798 (column (current-column))
1800 (from (marker-position (widget-get widget
:from
)))
1801 (to (marker-position (widget-get widget
:to
))))
1803 (widget-value-set widget
(widget-value widget
))
1804 (custom-redraw-magic widget
))
1805 (when (and (>= pos from
) (<= pos to
))
1810 (goto-line (1+ line
)))
1811 (move-to-column column
))
1814 (defun custom-redraw-magic (widget)
1815 "Redraw WIDGET state with current settings."
1817 (let ((magic (widget-get widget
:custom-magic
)))
1819 (widget-value-set magic
(widget-value magic
))
1820 (when (setq widget
(widget-get widget
:group
))
1821 (custom-group-state-update widget
)))
1823 (setq widget nil
)))))
1826 (defun custom-show (widget value
)
1827 "Non-nil if WIDGET should be shown with VALUE by default."
1828 (let ((show (widget-get widget
:custom-show
)))
1834 (funcall show widget value
)))))
1836 (defun custom-load-widget (widget)
1837 "Load all dependencies for WIDGET."
1838 (custom-load-symbol (widget-value widget
)))
1840 (defun custom-unloaded-symbol-p (symbol)
1841 "Return non-nil if the dependencies of SYMBOL has not yet been loaded."
1843 (loads (get symbol
'custom-loads
))
1846 (setq load
(car loads
)
1848 (cond ((symbolp load
)
1849 (unless (featurep load
)
1851 ((assoc load load-history
))
1852 ((assoc (locate-library load
) load-history
)
1858 (defun custom-unloaded-widget-p (widget)
1859 "Return non-nil if the dependencies of WIDGET has not yet been loaded."
1860 (custom-unloaded-symbol-p (widget-value widget
)))
1862 (defun custom-toggle-hide (widget)
1863 "Toggle visibility of WIDGET."
1864 (custom-load-widget widget
)
1865 (let ((state (widget-get widget
:custom-state
)))
1866 (cond ((memq state
'(invalid modified
))
1867 (error "There are unset changes"))
1869 (widget-put widget
:custom-state
'unknown
))
1871 (widget-put widget
:documentation-shown nil
)
1872 (widget-put widget
:custom-state
'hidden
)))
1873 (custom-redraw widget
)
1876 (defun custom-toggle-parent (widget &rest ignore
)
1877 "Toggle visibility of parent of WIDGET."
1878 (custom-toggle-hide (widget-get widget
:parent
)))
1880 (defun custom-add-see-also (widget &optional prefix
)
1881 "Add `See also ...' to WIDGET if there are any links.
1882 Insert PREFIX first if non-nil."
1883 (let* ((symbol (widget-get widget
:value
))
1884 (links (get symbol
'custom-links
))
1885 (many (> (length links
) 2))
1886 (buttons (widget-get widget
:buttons
))
1887 (indent (widget-get widget
:indent
)))
1890 (insert-char ?\ indent
))
1893 (insert "See also ")
1895 (push (widget-create-child-and-convert widget
(car links
))
1897 (setq links
(cdr links
))
1906 (widget-put widget
:buttons buttons
))))
1908 (defun custom-add-parent-links (widget &optional initial-string
)
1909 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
1910 The value if non-nil if any parents were found.
1911 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
1912 (let ((name (widget-value widget
))
1913 (type (widget-type widget
))
1914 (buttons (widget-get widget
:buttons
))
1917 (insert (or initial-string
"Parent groups:"))
1918 (mapatoms (lambda (symbol)
1919 (let ((entry (assq name
(get symbol
'custom-group
))))
1920 (when (eq (nth 1 entry
) type
)
1922 (push (widget-create-child-and-convert
1923 widget
'custom-group-link
1924 :tag
(custom-unlispify-tag-name symbol
)
1928 (widget-put widget
:buttons buttons
)
1931 (delete-region start
(point)))
1934 ;;; The `custom-comment' Widget.
1936 ;; like the editable field
1937 (defface custom-comment-face
'((((class grayscale color
)
1939 (:background
"gray85"))
1940 (((class grayscale color
)
1942 (:background
"dim gray"))
1945 "Face used for comments on variables or faces"
1947 :group
'custom-faces
)
1949 ;; like font-lock-comment-face
1950 (defface custom-comment-tag-face
1951 '((((class color
) (background dark
)) (:foreground
"gray80"))
1952 (((class color
) (background light
)) (:foreground
"blue4"))
1953 (((class grayscale
) (background light
))
1954 (:foreground
"DimGray" :weight bold
:slant italic
))
1955 (((class grayscale
) (background dark
))
1956 (:foreground
"LightGray" :weight bold
:slant italic
))
1958 "Face used for variables or faces comment tags"
1959 :group
'custom-faces
)
1961 (define-widget 'custom-comment
'string
1964 :help-echo
"Edit a comment here."
1965 :sample-face
'custom-comment-tag-face
1966 :value-face
'custom-comment-face
1968 :create
'custom-comment-create
)
1970 (defun custom-comment-create (widget)
1971 (let* ((null-comment (equal "" (widget-value widget
))))
1972 (if (or (widget-get (widget-get widget
:parent
) :comment-shown
)
1974 (widget-default-create widget
)
1975 ;; `widget-default-delete' expects markers in these slots --
1976 ;; maybe it shouldn't.
1977 (widget-put widget
:from
(point-marker))
1978 (widget-put widget
:to
(point-marker)))))
1980 (defun custom-comment-hide (widget)
1981 (widget-put (widget-get widget
:parent
) :comment-shown nil
))
1983 ;; Those functions are for the menu. WIDGET is NOT the comment widget. It's
1984 ;; the global custom one
1985 (defun custom-comment-show (widget)
1986 (widget-put widget
:comment-shown t
)
1987 (custom-redraw widget
)
1990 (defun custom-comment-invisible-p (widget)
1991 (let ((val (widget-value (widget-get widget
:comment-widget
))))
1993 (not (widget-get widget
:comment-shown
)))))
1995 ;;; The `custom-variable' Widget.
1997 ;; When this was underlined blue, users confused it with a
1998 ;; Mosaic-style hyperlink...
1999 (defface custom-variable-tag-face
2002 (:foreground
"light blue" :weight bold
:height
1.2 :inherit variable-pitch
))
2005 (:foreground
"blue" :weight bold
:height
1.2 :inherit variable-pitch
))
2007 "Face used for unpushable variable tags."
2008 :group
'custom-faces
)
2010 (defface custom-variable-button-face
'((t (:underline t
:weight bold
)))
2011 "Face used for pushable variable tags."
2012 :group
'custom-faces
)
2014 (defcustom custom-variable-default-form
'edit
2015 "Default form of displaying variable values."
2016 :type
'(choice (const edit
)
2018 :group
'custom-buffer
2021 (define-widget 'custom-variable
'custom
2022 "Customize variable."
2024 :help-echo
"Set or reset this variable."
2025 :documentation-property
'variable-documentation
2026 :custom-category
'option
2028 :custom-menu
'custom-variable-menu-create
2029 :custom-form nil
; defaults to value of `custom-variable-default-form'
2030 :value-create
'custom-variable-value-create
2031 :action
'custom-variable-action
2032 :custom-set
'custom-variable-set
2033 :custom-save
'custom-variable-save
2034 :custom-reset-current
'custom-redraw
2035 :custom-reset-saved
'custom-variable-reset-saved
2036 :custom-reset-standard
'custom-variable-reset-standard
2037 :custom-standard-value
'custom-variable-standard-value
)
2039 (defun custom-variable-type (symbol)
2040 "Return a widget suitable for editing the value of SYMBOL.
2041 If SYMBOL has a `custom-type' property, use that.
2042 Otherwise, look up symbol in `custom-guess-type-alist'."
2043 (let* ((type (or (get symbol
'custom-type
)
2044 (and (not (get symbol
'standard-value
))
2045 (custom-guess-type symbol
))
2047 (options (get symbol
'custom-options
))
2048 (tmp (if (listp type
)
2049 (copy-sequence type
)
2052 (widget-put tmp
:options options
))
2055 (defun custom-variable-value-create (widget)
2056 "Here is where you edit the variable's value."
2057 (custom-load-widget widget
)
2058 (unless (widget-get widget
:custom-form
)
2059 (widget-put widget
:custom-form custom-variable-default-form
))
2060 (let* ((buttons (widget-get widget
:buttons
))
2061 (children (widget-get widget
:children
))
2062 (form (widget-get widget
:custom-form
))
2063 (state (widget-get widget
:custom-state
))
2064 (symbol (widget-get widget
:value
))
2065 (tag (widget-get widget
:tag
))
2066 (type (custom-variable-type symbol
))
2067 (conv (widget-convert type
))
2068 (get (or (get symbol
'custom-get
) 'default-value
))
2069 (prefix (widget-get widget
:custom-prefix
))
2070 (last (widget-get widget
:custom-last
))
2071 (value (if (default-boundp symbol
)
2072 (funcall get symbol
)
2073 (widget-get conv
:value
))))
2074 ;; If the widget is new, the child determines whether it is hidden.
2076 ((custom-show type value
)
2077 (setq state
'unknown
))
2079 (setq state
'hidden
)))
2080 ;; If we don't know the state, see if we need to edit it in lisp form.
2081 (when (eq state
'unknown
)
2082 (unless (widget-apply conv
:match value
)
2083 ;; (widget-apply (widget-convert type) :match value)
2084 (setq form
'mismatch
)))
2085 ;; Now we can create the child widget.
2086 (cond ((eq custom-buffer-style
'tree
)
2087 (insert prefix
(if last
" `--- " " |--- "))
2088 (push (widget-create-child-and-convert
2089 widget
'custom-browse-variable-tag
)
2091 (insert " " tag
"\n")
2092 (widget-put widget
:buttons buttons
))
2094 ;; Indicate hidden value.
2095 (push (widget-create-child-and-convert
2098 :sample-face
'custom-variable-tag-face
2102 (push (widget-create-child-and-convert
2104 :help-echo
"Show the value of this option."
2106 :action
'custom-toggle-parent
2109 ((memq form
'(lisp mismatch
))
2110 ;; In lisp mode edit the saved value when possible.
2111 (let* ((value (cond ((get symbol
'saved-value
)
2112 (car (get symbol
'saved-value
)))
2113 ((get symbol
'standard-value
)
2114 (car (get symbol
'standard-value
)))
2115 ((default-boundp symbol
)
2116 (custom-quote (funcall get symbol
)))
2118 (custom-quote (widget-get conv
:value
))))))
2119 (insert (symbol-name symbol
) ": ")
2120 (push (widget-create-child-and-convert
2122 :help-echo
"Hide the value of this option."
2125 :action
'custom-toggle-parent
2129 (push (widget-create-child-and-convert
2131 :button-face
'custom-variable-button-face
2133 :tag
(symbol-name symbol
)
2139 (let* ((format (widget-get type
:format
))
2140 tag-format value-format
)
2141 (unless (string-match ":" format
)
2142 (error "Bad format"))
2143 (setq tag-format
(substring format
0 (match-end 0)))
2144 (setq value-format
(substring format
(match-end 0)))
2145 (push (widget-create-child-and-convert
2148 :action
'custom-tag-action
2149 :help-echo
"Change value of this option."
2150 :mouse-down-action
'custom-tag-mouse-down-action
2151 :button-face
'custom-variable-button-face
2152 :sample-face
'custom-variable-tag-face
2156 (push (widget-create-child-and-convert
2158 :help-echo
"Hide the value of this option."
2161 :action
'custom-toggle-parent
2164 (push (widget-create-child-and-convert
2166 :format value-format
2169 (unless (eq custom-buffer-style
'tree
)
2170 (unless (eq (preceding-char) ?
\n)
2171 (widget-insert "\n"))
2172 ;; Create the magic button.
2173 (let ((magic (widget-create-child-and-convert
2174 widget
'custom-magic nil
)))
2175 (widget-put widget
:custom-magic magic
)
2176 (push magic buttons
))
2177 ;; ### NOTE: this is ugly!!!! I need to update the :buttons property
2178 ;; before the call to `widget-default-format-handler'. Otherwise, I
2179 ;; loose my current `buttons'. This function shouldn't be called like
2180 ;; this anyway. The doc string widget should be added like the others.
2182 (widget-put widget
:buttons buttons
)
2184 ;; Insert documentation.
2185 (widget-default-format-handler widget ?h
)
2187 ;; The comment field
2188 (unless (eq state
'hidden
)
2189 (let* ((comment (get symbol
'variable-comment
))
2191 (widget-create-child-and-convert
2192 widget
'custom-comment
2194 :value
(or comment
""))))
2195 (widget-put widget
:comment-widget comment-widget
)
2196 ;; Don't push it !!! Custom assumes that the first child is the
2198 (setq children
(append children
(list comment-widget
)))))
2199 ;; Update the rest of the properties properties.
2200 (widget-put widget
:custom-form form
)
2201 (widget-put widget
:children children
)
2202 ;; Now update the state.
2203 (if (eq state
'hidden
)
2204 (widget-put widget
:custom-state state
)
2205 (custom-variable-state-set widget
))
2207 (unless (eq state
'hidden
)
2208 (when (eq (widget-get widget
:custom-level
) 1)
2209 (custom-add-parent-links widget
))
2210 (custom-add-see-also widget
)))))
2212 (defun custom-tag-action (widget &rest args
)
2213 "Pass :action to first child of WIDGET's parent."
2214 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2217 (defun custom-tag-mouse-down-action (widget &rest args
)
2218 "Pass :mouse-down-action to first child of WIDGET's parent."
2219 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2220 :mouse-down-action args
))
2222 (defun custom-variable-state-set (widget)
2223 "Set the state of WIDGET."
2224 (let* ((symbol (widget-value widget
))
2225 (get (or (get symbol
'custom-get
) 'default-value
))
2226 (value (if (default-boundp symbol
)
2227 (funcall get symbol
)
2228 (widget-get widget
:value
)))
2229 (comment (get symbol
'variable-comment
))
2232 (state (cond ((progn (setq tmp
(get symbol
'customized-value
))
2234 (get symbol
'customized-variable-comment
))
2236 (if (condition-case nil
2237 (and (equal value
(eval (car tmp
)))
2238 (equal comment temp
))
2242 ((progn (setq tmp
(get symbol
'saved-value
))
2243 (setq temp
(get symbol
'saved-variable-comment
))
2245 (if (condition-case nil
2246 (and (equal value
(eval (car tmp
)))
2247 (equal comment temp
))
2251 ((setq tmp
(get symbol
'standard-value
))
2252 (if (condition-case nil
2253 (and (equal value
(eval (car tmp
)))
2254 (equal comment nil
))
2259 (widget-put widget
:custom-state state
)))
2261 (defun custom-variable-standard-value (widget)
2262 (get (widget-value widget
) 'standard-value
))
2264 (defvar custom-variable-menu
2265 '(("Set for Current Session" custom-variable-set
2267 (eq (widget-get widget
:custom-state
) 'modified
)))
2268 ("Save for Future Sessions" custom-variable-save
2270 (memq (widget-get widget
:custom-state
) '(modified set changed rogue
))))
2271 ("Reset to Current" custom-redraw
2273 (and (default-boundp (widget-value widget
))
2274 (memq (widget-get widget
:custom-state
) '(modified changed
)))))
2275 ("Reset to Saved" custom-variable-reset-saved
2277 (and (or (get (widget-value widget
) 'saved-value
)
2278 (get (widget-value widget
) 'saved-variable-comment
))
2279 (memq (widget-get widget
:custom-state
)
2280 '(modified set changed rogue
)))))
2281 ("Erase Customization" custom-variable-reset-standard
2283 (and (get (widget-value widget
) 'standard-value
)
2284 (memq (widget-get widget
:custom-state
)
2285 '(modified set changed saved rogue
)))))
2286 ("Use Backup Value" custom-variable-reset-backup
2288 (get (widget-value widget
) 'backup-value
)))
2289 ("---" ignore ignore
)
2290 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
2291 ("---" ignore ignore
)
2292 ("Don't show as Lisp expression" custom-variable-edit
2294 (eq (widget-get widget
:custom-form
) 'lisp
)))
2295 ("Show initial Lisp expression" custom-variable-edit-lisp
2297 (eq (widget-get widget
:custom-form
) 'edit
))))
2298 "Alist of actions for the `custom-variable' widget.
2299 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2300 the menu entry, ACTION is the function to call on the widget when the
2301 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2302 widget as an argument, and returns non-nil if ACTION is valid on that
2303 widget. If FILTER is nil, ACTION is always valid.")
2305 (defun custom-variable-action (widget &optional event
)
2306 "Show the menu for `custom-variable' WIDGET.
2307 Optional EVENT is the location for the menu."
2308 (if (eq (widget-get widget
:custom-state
) 'hidden
)
2309 (custom-toggle-hide widget
)
2310 (unless (eq (widget-get widget
:custom-state
) 'modified
)
2311 (custom-variable-state-set widget
))
2312 (custom-redraw-magic widget
)
2313 (let* ((completion-ignore-case t
)
2314 (answer (widget-choose (concat "Operation on "
2315 (custom-unlispify-tag-name
2316 (widget-get widget
:value
)))
2317 (custom-menu-filter custom-variable-menu
2321 (funcall answer widget
)))))
2323 (defun custom-variable-edit (widget)
2324 "Edit value of WIDGET."
2325 (widget-put widget
:custom-state
'unknown
)
2326 (widget-put widget
:custom-form
'edit
)
2327 (custom-redraw widget
))
2329 (defun custom-variable-edit-lisp (widget)
2330 "Edit the Lisp representation of the value of WIDGET."
2331 (widget-put widget
:custom-state
'unknown
)
2332 (widget-put widget
:custom-form
'lisp
)
2333 (custom-redraw widget
))
2335 (defun custom-variable-set (widget)
2336 "Set the current value for the variable being edited by WIDGET."
2337 (let* ((form (widget-get widget
:custom-form
))
2338 (state (widget-get widget
:custom-state
))
2339 (child (car (widget-get widget
:children
)))
2340 (symbol (widget-value widget
))
2341 (set (or (get symbol
'custom-set
) 'set-default
))
2342 (comment-widget (widget-get widget
:comment-widget
))
2343 (comment (widget-value comment-widget
))
2345 (cond ((eq state
'hidden
)
2346 (error "Cannot set hidden variable"))
2347 ((setq val
(widget-apply child
:validate
))
2348 (goto-char (widget-get val
:from
))
2349 (error "%s" (widget-get val
:error
)))
2350 ((memq form
'(lisp mismatch
))
2351 (when (equal comment
"")
2353 ;; Make the comment invisible by hand if it's empty
2354 (custom-comment-hide comment-widget
))
2355 (custom-variable-backup-value widget
)
2356 (funcall set symbol
(eval (setq val
(widget-value child
))))
2357 (put symbol
'customized-value
(list val
))
2358 (put symbol
'variable-comment comment
)
2359 (put symbol
'customized-variable-comment comment
))
2361 (when (equal comment
"")
2363 ;; Make the comment invisible by hand if it's empty
2364 (custom-comment-hide comment-widget
))
2365 (custom-variable-backup-value widget
)
2366 (funcall set symbol
(setq val
(widget-value child
)))
2367 (put symbol
'customized-value
(list (custom-quote val
)))
2368 (put symbol
'variable-comment comment
)
2369 (put symbol
'customized-variable-comment comment
)))
2370 (custom-variable-state-set widget
)
2371 (custom-redraw-magic widget
)))
2373 (defun custom-variable-save (widget)
2374 "Set and save the value for the variable being edited by WIDGET."
2375 (let* ((form (widget-get widget
:custom-form
))
2376 (state (widget-get widget
:custom-state
))
2377 (child (car (widget-get widget
:children
)))
2378 (symbol (widget-value widget
))
2379 (set (or (get symbol
'custom-set
) 'set-default
))
2380 (comment-widget (widget-get widget
:comment-widget
))
2381 (comment (widget-value comment-widget
))
2383 (cond ((eq state
'hidden
)
2384 (error "Cannot set hidden variable"))
2385 ((setq val
(widget-apply child
:validate
))
2386 (goto-char (widget-get val
:from
))
2387 (error "Saving %s: %s" symbol
(widget-get val
:error
)))
2388 ((memq form
'(lisp mismatch
))
2389 (when (equal comment
"")
2391 ;; Make the comment invisible by hand if it's empty
2392 (custom-comment-hide comment-widget
))
2393 (put symbol
'saved-value
(list (widget-value child
)))
2394 (custom-push-theme 'theme-value symbol
'user
2395 'set
(list (widget-value child
)))
2396 (funcall set symbol
(eval (widget-value child
)))
2397 (put symbol
'variable-comment comment
)
2398 (put symbol
'saved-variable-comment comment
))
2400 (when (equal comment
"")
2402 ;; Make the comment invisible by hand if it's empty
2403 (custom-comment-hide comment-widget
))
2404 (put symbol
'saved-value
2405 (list (custom-quote (widget-value child
))))
2406 (custom-push-theme 'theme-value symbol
'user
2407 'set
(list (custom-quote (widget-value
2409 (funcall set symbol
(widget-value child
))
2410 (put symbol
'variable-comment comment
)
2411 (put symbol
'saved-variable-comment comment
)))
2412 (put symbol
'customized-value nil
)
2413 (put symbol
'customized-variable-comment nil
)
2415 (custom-variable-state-set widget
)
2416 (custom-redraw-magic widget
)))
2418 (defun custom-variable-reset-saved (widget)
2419 "Restore the saved value for the variable being edited by WIDGET.
2420 The value that was current before this operation
2421 becomes the backup value, so you can get it again."
2422 (let* ((symbol (widget-value widget
))
2423 (set (or (get symbol
'custom-set
) 'set-default
))
2424 (comment-widget (widget-get widget
:comment-widget
))
2425 (value (get symbol
'saved-value
))
2426 (comment (get symbol
'saved-variable-comment
)))
2427 (cond ((or value comment
)
2428 (put symbol
'variable-comment comment
)
2429 (custom-variable-backup-value widget
)
2431 (funcall set symbol
(eval (car value
)))
2434 (error "No saved value for %s" symbol
)))
2435 (put symbol
'customized-value nil
)
2436 (put symbol
'customized-variable-comment nil
)
2437 (widget-put widget
:custom-state
'unknown
)
2438 ;; This call will possibly make the comment invisible
2439 (custom-redraw widget
)))
2441 (defun custom-variable-reset-standard (widget)
2442 "Restore the standard setting for the variable being edited by WIDGET.
2443 This operation eliminates any saved setting for the variable,
2444 restoring it to the state of a variable that has never been customized.
2445 The value that was current before this operation
2446 becomes the backup value, so you can get it again."
2447 (let* ((symbol (widget-value widget
))
2448 (set (or (get symbol
'custom-set
) 'set-default
))
2449 (comment-widget (widget-get widget
:comment-widget
)))
2450 (if (get symbol
'standard-value
)
2452 (custom-variable-backup-value widget
)
2453 (funcall set symbol
(eval (car (get symbol
'standard-value
)))))
2454 (error "No standard setting known for %S" symbol
))
2455 (put symbol
'variable-comment nil
)
2456 (put symbol
'customized-value nil
)
2457 (put symbol
'customized-variable-comment nil
)
2458 (when (or (get symbol
'saved-value
) (get symbol
'saved-variable-comment
))
2459 (put symbol
'saved-value nil
)
2460 (custom-push-theme 'theme-value symbol
'user
'reset
'standard
)
2461 ;; As a special optimizations we do not (explictly)
2462 ;; save resets to standard when no theme set the value.
2463 (if (null (cdr (get symbol
'theme-value
)))
2464 (put symbol
'theme-value nil
))
2465 (put symbol
'saved-variable-comment nil
)
2467 (widget-put widget
:custom-state
'unknown
)
2468 ;; This call will possibly make the comment invisible
2469 (custom-redraw widget
)))
2471 (defun custom-variable-backup-value (widget)
2472 "Back up the current value for WIDGET's variable.
2473 The backup value is kept in the car of the `backup-value' property."
2474 (let* ((symbol (widget-value widget
))
2475 (get (or (get symbol
'custom-get
) 'default-value
))
2476 (type (custom-variable-type symbol
))
2477 (conv (widget-convert type
))
2478 (value (if (default-boundp symbol
)
2479 (funcall get symbol
)
2480 (widget-get conv
:value
))))
2481 (put symbol
'backup-value
(list value
))))
2483 (defun custom-variable-reset-backup (widget)
2484 "Restore the backup value for the variable being edited by WIDGET.
2485 The value that was current before this operation
2486 becomes the backup value, so you can use this operation repeatedly
2487 to switch between two values."
2488 (let* ((symbol (widget-value widget
))
2489 (set (or (get symbol
'custom-set
) 'set-default
))
2490 (value (get symbol
'backup-value
))
2491 (comment-widget (widget-get widget
:comment-widget
))
2492 (comment (widget-value comment-widget
)))
2495 (custom-variable-backup-value widget
)
2497 (funcall set symbol
(car value
))
2499 (error "No backup value for %s" symbol
))
2500 (put symbol
'customized-value
(list (car value
)))
2501 (put symbol
'variable-comment comment
)
2502 (put symbol
'customized-variable-comment comment
)
2503 (custom-variable-state-set widget
)
2504 ;; This call will possibly make the comment invisible
2505 (custom-redraw widget
)))
2507 ;;; The `custom-face-edit' Widget.
2509 (define-widget 'custom-face-edit
'checklist
2510 "Edit face attributes."
2514 :button-args
'(:help-echo
"Control whether this attribute has any effect.")
2515 :value-to-internal
'custom-face-edit-fix-value
2516 :match
(lambda (widget value
)
2517 (widget-checklist-match widget
2518 (custom-face-edit-fix-value widget value
)))
2519 :convert-widget
'custom-face-edit-convert-widget
2520 :args
(mapcar (lambda (att)
2523 :sibling-args
(widget-get (nth 1 att
) :sibling-args
)
2524 (list 'const
:format
"" :value
(nth 0 att
))
2526 custom-face-attributes
))
2528 (defun custom-face-edit-fix-value (widget value
)
2529 "Ignoring WIDGET, convert :bold and :italic in VALUE to new form.
2530 Also change :reverse-video to :inverse-video."
2534 (let ((key (car value
))
2535 (val (car (cdr value
))))
2536 (cond ((eq key
:italic
)
2537 (push :slant result
)
2538 (push (if val
'italic
'normal
) result
))
2540 (push :weight result
)
2541 (push (if val
'bold
'normal
) result
))
2542 ((eq key
:reverse-video
)
2543 (push :inverse-video result
)
2547 (push val result
))))
2548 (setq value
(cdr (cdr value
))))
2549 (setq result
(nreverse result
))
2553 (defun custom-face-edit-convert-widget (widget)
2554 "Convert :args as widget types in WIDGET."
2557 :args
(mapcar (lambda (arg)
2559 :deactivate
'custom-face-edit-deactivate
2560 :activate
'custom-face-edit-activate
2561 :delete
'custom-face-edit-delete
))
2562 (widget-get widget
:args
)))
2565 (defun custom-face-edit-deactivate (widget)
2566 "Make face widget WIDGET inactive for user modifications."
2567 (unless (widget-get widget
:inactive
)
2568 (let ((tag (custom-face-edit-attribute-tag widget
))
2569 (from (copy-marker (widget-get widget
:from
)))
2570 (to (widget-get widget
:to
))
2571 (value (widget-value widget
))
2572 (inhibit-read-only t
)
2573 (inhibit-modification-hooks t
))
2576 (widget-default-delete widget
)
2577 (insert tag
": *\n")
2578 (widget-put widget
:inactive
2579 (cons value
(cons from
(- (point) from
))))))))
2581 (defun custom-face-edit-activate (widget)
2582 "Make face widget WIDGET inactive for user modifications."
2583 (let ((inactive (widget-get widget
:inactive
))
2584 (inhibit-read-only t
)
2585 (inhibit-modification-hooks t
))
2586 (when (consp inactive
)
2588 (goto-char (car (cdr inactive
)))
2589 (delete-region (point) (+ (point) (cdr (cdr inactive
))))
2590 (widget-put widget
:inactive nil
)
2591 (widget-apply widget
:create
)
2592 (widget-value-set widget
(car inactive
))
2595 (defun custom-face-edit-delete (widget)
2596 "Remove widget from the buffer."
2597 (let ((inactive (widget-get widget
:inactive
))
2598 (inhibit-read-only t
)
2599 (inhibit-modification-hooks t
))
2601 ;; Widget is alive, we don't have to do anything special
2602 (widget-default-delete widget
)
2603 ;; WIDGET is already deleted because we did so to inactivate it;
2604 ;; now just get rid of the label we put in its place.
2605 (delete-region (car (cdr inactive
))
2606 (+ (car (cdr inactive
)) (cdr (cdr inactive
))))
2607 (widget-put widget
:inactive nil
))))
2610 (defun custom-face-edit-attribute-tag (widget)
2611 "Returns the first :tag property in WIDGET or one of its children."
2612 (let ((tag (widget-get widget
:tag
)))
2613 (or (and (not (equal tag
"")) tag
)
2614 (let ((children (widget-get widget
:children
)))
2615 (while (and (null tag
) children
)
2616 (setq tag
(custom-face-edit-attribute-tag (pop children
))))
2619 ;;; The `custom-display' Widget.
2621 (define-widget 'custom-display
'menu-choice
2622 "Select a display type."
2625 :help-echo
"Specify frames where the face attributes should be used."
2626 :args
'((const :tag
"all" t
)
2630 :args
((group :sibling-args
(:help-echo
"\
2631 Only match the specified window systems.")
2632 (const :format
"Type: "
2634 (checklist :inline t
2637 :sibling-args
(:help-echo
"\
2638 The X11 Window System.")
2640 (const :format
"PM "
2641 :sibling-args
(:help-echo
"\
2642 OS/2 Presentation Manager.")
2644 (const :format
"W32 "
2645 :sibling-args
(:help-echo
"\
2648 (const :format
"MAC "
2649 :sibling-args
(:help-echo
"\
2652 (const :format
"DOS "
2653 :sibling-args
(:help-echo
"\
2656 (const :format
"TTY%n"
2657 :sibling-args
(:help-echo
"\
2658 Plain text terminals.")
2660 (group :sibling-args
(:help-echo
"\
2661 Only match the frames with the specified color support.")
2662 (const :format
"Class: "
2664 (checklist :inline t
2666 (const :format
"Color "
2667 :sibling-args
(:help-echo
"\
2668 Match color frames.")
2670 (const :format
"Grayscale "
2671 :sibling-args
(:help-echo
"\
2672 Match grayscale frames.")
2674 (const :format
"Monochrome%n"
2675 :sibling-args
(:help-echo
"\
2676 Match frames with no color support.")
2678 (group :sibling-args
(:help-echo
"\
2679 Only match frames with the specified intensity.")
2681 Background brightness: "
2683 (checklist :inline t
2685 (const :format
"Light "
2686 :sibling-args
(:help-echo
"\
2687 Match frames with light backgrounds.")
2689 (const :format
"Dark\n"
2690 :sibling-args
(:help-echo
"\
2691 Match frames with dark backgrounds.")
2693 (group :sibling-args
(:help-echo
"\
2694 Only match frames that support the specified face attributes.")
2695 (const :format
"Supports attributes:" supports
)
2696 (custom-face-edit :inline t
:format
"%n%v"))))))
2698 ;;; The `custom-face' Widget.
2700 (defface custom-face-tag-face
2701 `((t (:weight bold
:height
1.2 :inherit variable-pitch
)))
2702 "Face used for face tags."
2703 :group
'custom-faces
)
2705 (defcustom custom-face-default-form
'selected
2706 "Default form of displaying face definition."
2707 :type
'(choice (const all
)
2710 :group
'custom-buffer
2713 (define-widget 'custom-face
'custom
2715 :sample-face
'custom-face-tag-face
2716 :help-echo
"Set or reset this face."
2717 :documentation-property
#'face-doc-string
2718 :value-create
'custom-face-value-create
2719 :action
'custom-face-action
2720 :custom-category
'face
2721 :custom-form nil
; defaults to value of `custom-face-default-form'
2722 :custom-set
'custom-face-set
2723 :custom-save
'custom-face-save
2724 :custom-reset-current
'custom-redraw
2725 :custom-reset-saved
'custom-face-reset-saved
2726 :custom-reset-standard
'custom-face-reset-standard
2727 :custom-standard-value
'custom-face-standard-value
2728 :custom-menu
'custom-face-menu-create
)
2730 (define-widget 'custom-face-all
'editable-list
2731 "An editable list of display specifications and attributes."
2732 :entry-format
"%i %d %v"
2733 :insert-button-args
'(:help-echo
"Insert new display specification here.")
2734 :append-button-args
'(:help-echo
"Append new display specification here.")
2735 :delete-button-args
'(:help-echo
"Delete this display specification.")
2736 :args
'((group :format
"%v" custom-display custom-face-edit
)))
2738 (defconst custom-face-all
(widget-convert 'custom-face-all
)
2739 "Converted version of the `custom-face-all' widget.")
2741 (define-widget 'custom-display-unselected
'item
2742 "A display specification that doesn't match the selected display."
2743 :match
'custom-display-unselected-match
)
2745 (defun custom-display-unselected-match (widget value
)
2746 "Non-nil if VALUE is an unselected display specification."
2747 (not (face-spec-set-match-display value
(selected-frame))))
2749 (define-widget 'custom-face-selected
'group
2750 "Edit the attributes of the selected display in a face specification."
2751 :args
'((repeat :format
""
2753 (group custom-display-unselected sexp
))
2754 (group (sexp :format
"") custom-face-edit
)
2759 (defconst custom-face-selected
(widget-convert 'custom-face-selected
)
2760 "Converted version of the `custom-face-selected' widget.")
2762 (defun custom-filter-face-spec (spec filter-index
&optional default-filter
)
2763 "Return a canonicalized version of SPEC using.
2764 FILTER-INDEX is the index in the entry for each attribute in
2765 `custom-face-attributes' at which the appropriate filter function can be
2766 found, and DEFAULT-FILTER is the filter to apply for attributes that
2768 (mapcar (lambda (entry)
2769 ;; Filter a single face-spec entry
2770 (let ((tests (car entry
))
2772 ;; Handle both old- and new-style attribute syntax
2773 (if (listp (car (cdr entry
)))
2776 (filtered-attrs nil
))
2777 ;; Filter each face attribute
2778 (while unfiltered-attrs
2779 (let* ((attr (pop unfiltered-attrs
))
2780 (pre-filtered-value (pop unfiltered-attrs
))
2782 (or (nth filter-index
(assq attr custom-face-attributes
))
2786 (funcall filter pre-filtered-value
)
2787 pre-filtered-value
)))
2788 (push filtered-value filtered-attrs
)
2789 (push attr filtered-attrs
)))
2791 (list tests filtered-attrs
)))
2794 (defun custom-pre-filter-face-spec (spec)
2795 "Return SPEC changed as necessary for editing by the face customization widget.
2796 SPEC must be a full face spec."
2797 (custom-filter-face-spec spec
2))
2799 (defun custom-post-filter-face-spec (spec)
2800 "Return the customized SPEC in a form suitable for setting the face."
2801 (custom-filter-face-spec spec
3))
2803 (defun custom-face-value-create (widget)
2804 "Create a list of the display specifications for WIDGET."
2805 (let ((buttons (widget-get widget
:buttons
))
2807 (symbol (widget-get widget
:value
))
2808 (tag (widget-get widget
:tag
))
2809 (state (widget-get widget
:custom-state
))
2811 (is-last (widget-get widget
:custom-last
))
2812 (prefix (widget-get widget
:custom-prefix
)))
2814 (setq tag
(prin1-to-string symbol
)))
2815 (cond ((eq custom-buffer-style
'tree
)
2816 (insert prefix
(if is-last
" `--- " " |--- "))
2817 (push (widget-create-child-and-convert
2818 widget
'custom-browse-face-tag
)
2820 (insert " " tag
"\n")
2821 (widget-put widget
:buttons buttons
))
2825 (widget-specify-sample widget begin
(point))
2826 (if (eq custom-buffer-style
'face
)
2828 (if (string-match "face\\'" tag
)
2830 (insert " face: ")))
2832 (push (widget-create-child-and-convert widget
'item
2839 (push (widget-create-child-and-convert
2841 :help-echo
"Hide or show this face."
2844 :action
'custom-toggle-parent
2845 (not (eq state
'hidden
)))
2849 (let ((magic (widget-create-child-and-convert
2850 widget
'custom-magic nil
)))
2851 (widget-put widget
:custom-magic magic
)
2852 (push magic buttons
))
2854 (widget-put widget
:buttons buttons
)
2855 ;; Insert documentation.
2856 (widget-default-format-handler widget ?h
)
2857 ;; The comment field
2858 (unless (eq state
'hidden
)
2859 (let* ((comment (get symbol
'face-comment
))
2861 (widget-create-child-and-convert
2862 widget
'custom-comment
2864 :value
(or comment
""))))
2865 (widget-put widget
:comment-widget comment-widget
)
2866 (push comment-widget children
)))
2868 (unless (eq state
'hidden
)
2869 (when (eq (widget-get widget
:custom-level
) 1)
2870 (custom-add-parent-links widget
))
2871 (custom-add-see-also widget
))
2873 (unless (eq (preceding-char) ?
\n)
2875 (unless (eq state
'hidden
)
2876 (message "Creating face editor...")
2877 (custom-load-widget widget
)
2878 (unless (widget-get widget
:custom-form
)
2879 (widget-put widget
:custom-form custom-face-default-form
))
2880 (let* ((symbol (widget-value widget
))
2881 (spec (or (get symbol
'customized-face
)
2882 (get symbol
'saved-face
)
2883 (get symbol
'face-defface-spec
)
2884 ;; Attempt to construct it.
2885 (list (list t
(custom-face-attributes-get
2886 symbol
(selected-frame))))))
2887 (form (widget-get widget
:custom-form
))
2888 (indent (widget-get widget
:indent
))
2890 ;; If the user has changed this face in some other way,
2891 ;; edit it as the user has specified it.
2892 (if (not (face-spec-match-p symbol spec
(selected-frame)))
2893 (setq spec
(list (list t
(face-attr-construct symbol
(selected-frame))))))
2894 (setq spec
(custom-pre-filter-face-spec spec
))
2895 (setq edit
(widget-create-child-and-convert
2897 (cond ((and (eq form
'selected
)
2898 (widget-apply custom-face-selected
2900 (when indent
(insert-char ?\ indent
))
2901 'custom-face-selected
)
2902 ((and (not (eq form
'lisp
))
2903 (widget-apply custom-face-all
2907 (when indent
(insert-char ?\ indent
))
2910 (custom-face-state-set widget
)
2911 (push edit children
)
2912 (widget-put widget
:children children
))
2913 (message "Creating face editor...done"))))))
2915 (defvar custom-face-menu
2916 '(("Set for Current Session" custom-face-set
)
2917 ("Save for Future Sessions" custom-face-save-command
)
2918 ("Reset to Saved" custom-face-reset-saved
2920 (or (get (widget-value widget
) 'saved-face
)
2921 (get (widget-value widget
) 'saved-face-comment
))))
2922 ("Erase Customization" custom-face-reset-standard
2924 (get (widget-value widget
) 'face-defface-spec
)))
2925 ("---" ignore ignore
)
2926 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
2927 ("---" ignore ignore
)
2928 ("Show all display specs" custom-face-edit-all
2930 (not (eq (widget-get widget
:custom-form
) 'all
))))
2931 ("Just current attributes" custom-face-edit-selected
2933 (not (eq (widget-get widget
:custom-form
) 'selected
))))
2934 ("Show as Lisp expression" custom-face-edit-lisp
2936 (not (eq (widget-get widget
:custom-form
) 'lisp
)))))
2937 "Alist of actions for the `custom-face' widget.
2938 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2939 the menu entry, ACTION is the function to call on the widget when the
2940 menu is selected, and FILTER is a predicate which takes a `custom-face'
2941 widget as an argument, and returns non-nil if ACTION is valid on that
2942 widget. If FILTER is nil, ACTION is always valid.")
2944 (defun custom-face-edit-selected (widget)
2945 "Edit selected attributes of the value of WIDGET."
2946 (widget-put widget
:custom-state
'unknown
)
2947 (widget-put widget
:custom-form
'selected
)
2948 (custom-redraw widget
))
2950 (defun custom-face-edit-all (widget)
2951 "Edit all attributes of the value of WIDGET."
2952 (widget-put widget
:custom-state
'unknown
)
2953 (widget-put widget
:custom-form
'all
)
2954 (custom-redraw widget
))
2956 (defun custom-face-edit-lisp (widget)
2957 "Edit the Lisp representation of the value of WIDGET."
2958 (widget-put widget
:custom-state
'unknown
)
2959 (widget-put widget
:custom-form
'lisp
)
2960 (custom-redraw widget
))
2962 (defun custom-face-state-set (widget)
2963 "Set the state of WIDGET."
2964 (let* ((symbol (widget-value widget
))
2965 (comment (get symbol
'face-comment
))
2967 (widget-put widget
:custom-state
2969 (setq tmp
(get symbol
'customized-face
))
2970 (setq temp
(get symbol
'customized-face-comment
))
2972 (if (equal temp comment
)
2976 (setq tmp
(get symbol
'saved-face
))
2977 (setq temp
(get symbol
'saved-face-comment
))
2979 (if (equal temp comment
)
2982 ((get symbol
'face-defface-spec
)
2983 (if (equal comment nil
)
2989 (defun custom-face-action (widget &optional event
)
2990 "Show the menu for `custom-face' WIDGET.
2991 Optional EVENT is the location for the menu."
2992 (if (eq (widget-get widget
:custom-state
) 'hidden
)
2993 (custom-toggle-hide widget
)
2994 (let* ((completion-ignore-case t
)
2995 (symbol (widget-get widget
:value
))
2996 (answer (widget-choose (concat "Operation on "
2997 (custom-unlispify-tag-name symbol
))
2998 (custom-menu-filter custom-face-menu
3002 (funcall answer widget
)))))
3004 (defun custom-face-set (widget)
3005 "Make the face attributes in WIDGET take effect."
3006 (let* ((symbol (widget-value widget
))
3007 (child (car (widget-get widget
:children
)))
3008 (value (custom-post-filter-face-spec (widget-value child
)))
3009 (comment-widget (widget-get widget
:comment-widget
))
3010 (comment (widget-value comment-widget
)))
3011 (when (equal comment
"")
3013 ;; Make the comment invisible by hand if it's empty
3014 (custom-comment-hide comment-widget
))
3015 (put symbol
'customized-face value
)
3016 (if (face-spec-choose value
)
3017 (face-spec-set symbol value
)
3018 ;; face-set-spec ignores empty attribute lists, so just give it
3019 ;; something harmless instead.
3020 (face-spec-set symbol
'((t :foreground unspecified
))))
3021 (put symbol
'customized-face-comment comment
)
3022 (put symbol
'face-comment comment
)
3023 (custom-face-state-set widget
)
3024 (custom-redraw-magic widget
)))
3026 (defun custom-face-save-command (widget)
3027 "Save in `.emacs' the face attributes in WIDGET."
3028 (custom-face-save widget
)
3031 (defun custom-face-save (widget)
3032 "Prepare for saving WIDGET's face attributes, but don't write `.emacs'."
3033 (let* ((symbol (widget-value widget
))
3034 (child (car (widget-get widget
:children
)))
3035 (value (custom-post-filter-face-spec (widget-value child
)))
3036 (comment-widget (widget-get widget
:comment-widget
))
3037 (comment (widget-value comment-widget
)))
3038 (when (equal comment
"")
3040 ;; Make the comment invisible by hand if it's empty
3041 (custom-comment-hide comment-widget
))
3042 (if (face-spec-choose value
)
3043 (face-spec-set symbol value
)
3044 ;; face-set-spec ignores empty attribute lists, so just give it
3045 ;; something harmless instead.
3046 (face-spec-set symbol
'((t :foreground unspecified
))))
3047 (unless (eq (widget-get widget
:custom-state
) 'standard
)
3048 (put symbol
'saved-face value
))
3049 (custom-push-theme 'theme-face symbol
'user
'set value
)
3050 (put symbol
'customized-face nil
)
3051 (put symbol
'face-comment comment
)
3052 (put symbol
'customized-face-comment nil
)
3053 (put symbol
'saved-face-comment comment
)
3055 (custom-face-state-set widget
)
3056 (custom-redraw-magic widget
)))
3058 (defun custom-face-reset-saved (widget)
3059 "Restore WIDGET to the face's default attributes."
3060 (let* ((symbol (widget-value widget
))
3061 (child (car (widget-get widget
:children
)))
3062 (value (get symbol
'saved-face
))
3063 (comment (get symbol
'saved-face-comment
))
3064 (comment-widget (widget-get widget
:comment-widget
)))
3065 (unless (or value comment
)
3066 (error "No saved value for this face"))
3067 (put symbol
'customized-face nil
)
3068 (put symbol
'customized-face-comment nil
)
3069 (face-spec-set symbol value
)
3070 (put symbol
'face-comment comment
)
3071 (widget-value-set child value
)
3072 ;; This call manages the comment visibility
3073 (widget-value-set comment-widget
(or comment
""))
3074 (custom-face-state-set widget
)
3075 (custom-redraw-magic widget
)))
3077 (defun custom-face-standard-value (widget)
3078 (get (widget-value widget
) 'face-defface-spec
))
3080 (defun custom-face-reset-standard (widget)
3081 "Restore WIDGET to the face's standard settings.
3082 This operation eliminates any saved setting for the face,
3083 restoring it to the state of a face that has never been customized."
3084 (let* ((symbol (widget-value widget
))
3085 (child (car (widget-get widget
:children
)))
3086 (value (get symbol
'face-defface-spec
))
3087 (comment-widget (widget-get widget
:comment-widget
)))
3089 (error "No standard setting for this face"))
3090 (put symbol
'customized-face nil
)
3091 (put symbol
'customized-face-comment nil
)
3092 (when (or (get symbol
'saved-face
) (get symbol
'saved-face-comment
))
3093 (put symbol
'saved-face nil
)
3094 (custom-push-theme 'theme-face symbol
'user
'reset
'standard
)
3095 ;; Do not explictly save resets to standards without themes.
3096 (if (null (cdr (get symbol
'theme-face
)))
3097 (put symbol
'theme-face nil
))
3098 (put symbol
'saved-face-comment nil
)
3100 (face-spec-set symbol value
)
3101 (put symbol
'face-comment nil
)
3102 (widget-value-set child value
)
3103 ;; This call manages the comment visibility
3104 (widget-value-set comment-widget
"")
3105 (custom-face-state-set widget
)
3106 (custom-redraw-magic widget
)))
3108 ;;; The `face' Widget.
3110 (define-widget 'face
'default
3111 "Select and customize a face."
3112 :convert-widget
'widget-value-convert-widget
3113 :button-prefix
'widget-push-button-prefix
3114 :button-suffix
'widget-push-button-suffix
3115 :format
"%{%t%}: %[select face%] %v"
3118 :value-create
'widget-face-value-create
3119 :value-delete
'widget-face-value-delete
3120 :value-get
'widget-value-value-get
3121 :validate
'widget-children-validate
3122 :action
'widget-face-action
3123 :match
(lambda (widget value
) (symbolp value
)))
3125 (defun widget-face-value-create (widget)
3126 "Create a `custom-face' child."
3127 (let* ((symbol (widget-value widget
))
3128 (custom-buffer-style 'face
)
3129 (child (widget-create-child-and-convert
3133 (custom-magic-reset child
)
3134 (setq custom-options
(cons child custom-options
))
3135 (widget-put widget
:children
(list child
))))
3137 (defun widget-face-value-delete (widget)
3138 "Remove the child from the options."
3139 (let ((child (car (widget-get widget
:children
))))
3140 (setq custom-options
(delq child custom-options
))
3141 (widget-children-value-delete widget
)))
3143 (defvar face-history nil
3144 "History of entered face names.")
3146 (defun widget-face-action (widget &optional event
)
3147 "Prompt for a face."
3148 (let ((answer (completing-read "Face: "
3149 (mapcar (lambda (face)
3150 (list (symbol-name face
)))
3154 (unless (zerop (length answer
))
3155 (widget-value-set widget
(intern answer
))
3156 (widget-apply widget
:notify widget event
)
3159 ;;; The `hook' Widget.
3161 (define-widget 'hook
'list
3163 :value-to-internal
(lambda (widget value
)
3164 (if (and value
(symbolp value
))
3167 :match
(lambda (widget value
)
3169 (widget-group-match widget value
)))
3170 ;; Avoid adding undefined functions to the hook, especially for
3171 ;; things like `find-file-hook' or even more basic ones, to avoid
3173 :set
(lambda (symbol value
)
3176 (add-hook symbol elt
))))
3177 :convert-widget
'custom-hook-convert-widget
3180 (defun custom-hook-convert-widget (widget)
3181 ;; Handle `:options'.
3182 (let* ((options (widget-get widget
:options
))
3183 (other `(editable-list :inline t
3184 :entry-format
"%i %d%v"
3185 (function :format
" %v")))
3187 (list `(checklist :inline t
3188 ,@(mapcar (lambda (entry)
3189 `(function-item ,entry
))
3193 (widget-put widget
:args args
)
3196 ;;; The `custom-group-link' Widget.
3198 (define-widget 'custom-group-link
'link
3199 "Show parent in other window when activated."
3200 :help-echo
"Create customization buffer for this group."
3201 :action
'custom-group-link-action
)
3203 (defun custom-group-link-action (widget &rest ignore
)
3204 (customize-group (widget-value widget
)))
3206 ;;; The `custom-group' Widget.
3208 (defcustom custom-group-tag-faces nil
3209 ;; In XEmacs, this ought to play games with font size.
3210 ;; Fixme: make it do so in Emacs.
3211 "Face used for group tags.
3212 The first member is used for level 1 groups, the second for level 2,
3213 and so forth. The remaining group tags are shown with
3214 `custom-group-tag-face'."
3215 :type
'(repeat face
)
3216 :group
'custom-faces
)
3218 (defface custom-group-tag-face-1
3221 (:foreground
"pink" :weight bold
:height
1.2 :inherit variable-pitch
))
3224 (:foreground
"red" :weight bold
:height
1.2 :inherit variable-pitch
))
3226 "Face used for group tags."
3227 :group
'custom-faces
)
3229 (defface custom-group-tag-face
3232 (:foreground
"light blue" :weight bold
:height
1.2))
3235 (:foreground
"blue" :weight bold
:height
1.2))
3237 "Face used for low level group tags."
3238 :group
'custom-faces
)
3240 (define-widget 'custom-group
'custom
3243 :sample-face-get
'custom-group-sample-face-get
3244 :documentation-property
'group-documentation
3245 :help-echo
"Set or reset all members of this group."
3246 :value-create
'custom-group-value-create
3247 :action
'custom-group-action
3248 :custom-category
'group
3249 :custom-set
'custom-group-set
3250 :custom-save
'custom-group-save
3251 :custom-reset-current
'custom-group-reset-current
3252 :custom-reset-saved
'custom-group-reset-saved
3253 :custom-reset-standard
'custom-group-reset-standard
3254 :custom-menu
'custom-group-menu-create
)
3256 (defun custom-group-sample-face-get (widget)
3257 ;; Use :sample-face.
3258 (or (nth (1- (widget-get widget
:custom-level
)) custom-group-tag-faces
)
3259 'custom-group-tag-face
))
3261 (define-widget 'custom-group-visibility
'visibility
3262 "An indicator and manipulator for hidden group contents."
3263 :create
'custom-group-visibility-create
)
3265 (defun custom-group-visibility-create (widget)
3266 (let ((visible (widget-value widget
)))
3268 (insert "--------")))
3269 (widget-default-create widget
))
3271 (defun custom-group-members (symbol groups-only
)
3272 "Return SYMBOL's custom group members.
3273 If GROUPS-ONLY non-nil, return only those members that are groups."
3274 (if (not groups-only
)
3275 (get symbol
'custom-group
)
3277 (dolist (entry (get symbol
'custom-group
))
3278 (when (eq (nth 1 entry
) 'custom-group
)
3279 (push entry members
)))
3280 (nreverse members
))))
3282 (defun custom-group-value-create (widget)
3283 "Insert a customize group for WIDGET in the current buffer."
3284 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
3285 (custom-load-widget widget
))
3286 (let* ((state (widget-get widget
:custom-state
))
3287 (level (widget-get widget
:custom-level
))
3288 ;; (indent (widget-get widget :indent))
3289 (prefix (widget-get widget
:custom-prefix
))
3290 (buttons (widget-get widget
:buttons
))
3291 (tag (widget-get widget
:tag
))
3292 (symbol (widget-value widget
))
3293 (members (custom-group-members symbol
3294 (and (eq custom-buffer-style
'tree
)
3295 custom-browse-only-groups
))))
3296 (cond ((and (eq custom-buffer-style
'tree
)
3298 (or members
(custom-unloaded-widget-p widget
)))
3299 (custom-browse-insert-prefix prefix
)
3300 (push (widget-create-child-and-convert
3301 widget
'custom-browse-visibility
3302 ;; :tag-glyph "plus"
3306 ;; (widget-glyph-insert nil "-- " "horizontal")
3307 (push (widget-create-child-and-convert
3308 widget
'custom-browse-group-tag
)
3310 (insert " " tag
"\n")
3311 (widget-put widget
:buttons buttons
))
3312 ((and (eq custom-buffer-style
'tree
)
3313 (zerop (length members
)))
3314 (custom-browse-insert-prefix prefix
)
3316 ;; (widget-glyph-insert nil "[ ]" "empty")
3317 ;; (widget-glyph-insert nil "-- " "horizontal")
3318 (push (widget-create-child-and-convert
3319 widget
'custom-browse-group-tag
)
3321 (insert " " tag
"\n")
3322 (widget-put widget
:buttons buttons
))
3323 ((eq custom-buffer-style
'tree
)
3324 (custom-browse-insert-prefix prefix
)
3325 (if (zerop (length members
))
3327 (custom-browse-insert-prefix prefix
)
3329 ;; (widget-glyph-insert nil "[ ]" "empty")
3330 ;; (widget-glyph-insert nil "-- " "horizontal")
3331 (push (widget-create-child-and-convert
3332 widget
'custom-browse-group-tag
)
3334 (insert " " tag
"\n")
3335 (widget-put widget
:buttons buttons
))
3336 (push (widget-create-child-and-convert
3337 widget
'custom-browse-visibility
3338 ;; :tag-glyph "minus"
3342 ;; (widget-glyph-insert nil "-\\ " "top")
3343 (push (widget-create-child-and-convert
3344 widget
'custom-browse-group-tag
)
3346 (insert " " tag
"\n")
3347 (widget-put widget
:buttons buttons
)
3348 (message "Creating group...")
3349 (let* ((members (custom-sort-items members
3350 custom-browse-sort-alphabetically
3351 custom-browse-order-groups
))
3352 (prefixes (widget-get widget
:custom-prefixes
))
3353 (custom-prefix-list (custom-prefix-add symbol prefixes
))
3354 (extra-prefix (if (widget-get widget
:custom-last
)
3357 (prefix (concat prefix extra-prefix
))
3360 (setq entry
(car members
)
3361 members
(cdr members
))
3362 (push (widget-create-child-and-convert
3363 widget
(nth 1 entry
)
3365 :tag
(custom-unlispify-tag-name (nth 0 entry
))
3366 :custom-prefixes custom-prefix-list
3367 :custom-level
(1+ level
)
3368 :custom-last
(null members
)
3369 :value
(nth 0 entry
)
3370 :custom-prefix prefix
)
3372 (widget-put widget
:children
(reverse children
)))
3373 (message "Creating group...done")))
3376 ;; Create level indicator.
3377 (unless (eq custom-buffer-style
'links
)
3378 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3381 (let ((begin (point)))
3383 (widget-specify-sample widget begin
(point)))
3385 ;; Create link/visibility indicator.
3386 (if (eq custom-buffer-style
'links
)
3387 (push (widget-create-child-and-convert
3388 widget
'custom-group-link
3392 (push (widget-create-child-and-convert
3393 widget
'custom-group-visibility
3394 :help-echo
"Show members of this group."
3395 :action
'custom-toggle-parent
3396 (not (eq state
'hidden
)))
3399 ;; Create magic button.
3400 (let ((magic (widget-create-child-and-convert
3401 widget
'custom-magic nil
)))
3402 (widget-put widget
:custom-magic magic
)
3403 (push magic buttons
))
3405 (widget-put widget
:buttons buttons
)
3406 ;; Insert documentation.
3407 (if (and (eq custom-buffer-style
'links
) (> level
1))
3408 (widget-put widget
:documentation-indent
0))
3409 (widget-default-format-handler widget ?h
))
3412 ;; Add parent groups references above the group.
3413 (if t
;;; This should test that the buffer
3414 ;;; was made to display a group.
3416 (if (custom-add-parent-links widget
3417 "Go to parent group:")
3419 ;; Create level indicator.
3420 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3423 (let ((start (point)))
3425 (widget-specify-sample widget start
(point)))
3427 ;; Create visibility indicator.
3428 (unless (eq custom-buffer-style
'links
)
3430 (push (widget-create-child-and-convert
3432 :help-echo
"Hide members of this group."
3433 :action
'custom-toggle-parent
3434 (not (eq state
'hidden
)))
3437 ;; Create more dashes.
3438 ;; Use 76 instead of 75 to compensate for the temporary "<"
3439 ;; added by `widget-insert'.
3440 (insert-char ?-
(- 76 (current-column)
3441 (* custom-buffer-indent level
)))
3443 ;; Create magic button.
3444 (let ((magic (widget-create-child-and-convert
3445 widget
'custom-magic
3448 (widget-put widget
:custom-magic magic
)
3449 (push magic buttons
))
3451 (widget-put widget
:buttons buttons
)
3452 ;; Insert documentation.
3453 (widget-default-format-handler widget ?h
)
3455 (if nil
;;; This should test that the buffer
3456 ;;; was not made to display a group.
3458 (insert-char ?\ custom-buffer-indent
)
3459 (custom-add-parent-links widget
)))
3460 (custom-add-see-also widget
3461 (make-string (* custom-buffer-indent level
)
3464 (message "Creating group...")
3465 (let* ((members (custom-sort-items members
3466 custom-buffer-sort-alphabetically
3467 custom-buffer-order-groups
))
3468 (prefixes (widget-get widget
:custom-prefixes
))
3469 (custom-prefix-list (custom-prefix-add symbol prefixes
))
3470 (length (length members
))
3472 (children (mapcar (lambda (entry)
3473 (widget-insert "\n")
3475 Creating group members... %2d%%"
3476 (/ (* 100.0 count
) length
))
3477 (setq count
(1+ count
))
3479 (widget-create-child-and-convert
3480 widget
(nth 1 entry
)
3482 :tag
(custom-unlispify-tag-name
3484 :custom-prefixes custom-prefix-list
3485 :custom-level
(1+ level
)
3486 :value
(nth 0 entry
))
3487 (unless (eq (preceding-char) ?
\n)
3488 (widget-insert "\n"))))
3490 (message "Creating group magic...")
3491 (mapc 'custom-magic-reset children
)
3492 (message "Creating group state...")
3493 (widget-put widget
:children children
)
3494 (custom-group-state-update widget
)
3495 (message "Creating group... done"))
3498 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3499 (insert "\\- " (widget-get widget
:tag
) " group end ")
3500 (insert-char ?-
(- 75 (current-column) (* custom-buffer-indent level
)))
3503 (defvar custom-group-menu
3504 '(("Set for Current Session" custom-group-set
3506 (eq (widget-get widget
:custom-state
) 'modified
)))
3507 ("Save for Future Sessions" custom-group-save
3509 (memq (widget-get widget
:custom-state
) '(modified set
))))
3510 ("Reset to Current" custom-group-reset-current
3512 (memq (widget-get widget
:custom-state
) '(modified))))
3513 ("Reset to Saved" custom-group-reset-saved
3515 (memq (widget-get widget
:custom-state
) '(modified set
))))
3516 ("Reset to standard setting" custom-group-reset-standard
3518 (memq (widget-get widget
:custom-state
) '(modified set saved
)))))
3519 "Alist of actions for the `custom-group' widget.
3520 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3521 the menu entry, ACTION is the function to call on the widget when the
3522 menu is selected, and FILTER is a predicate which takes a `custom-group'
3523 widget as an argument, and returns non-nil if ACTION is valid on that
3524 widget. If FILTER is nil, ACTION is always valid.")
3526 (defun custom-group-action (widget &optional event
)
3527 "Show the menu for `custom-group' WIDGET.
3528 Optional EVENT is the location for the menu."
3529 (if (eq (widget-get widget
:custom-state
) 'hidden
)
3530 (custom-toggle-hide widget
)
3531 (let* ((completion-ignore-case t
)
3532 (answer (widget-choose (concat "Operation on "
3533 (custom-unlispify-tag-name
3534 (widget-get widget
:value
)))
3535 (custom-menu-filter custom-group-menu
3539 (funcall answer widget
)))))
3541 (defun custom-group-set (widget)
3542 "Set changes in all modified group members."
3543 (let ((children (widget-get widget
:children
)))
3544 (mapc (lambda (child)
3545 (when (eq (widget-get child
:custom-state
) 'modified
)
3546 (widget-apply child
:custom-set
)))
3549 (defun custom-group-save (widget)
3550 "Save all modified group members."
3551 (let ((children (widget-get widget
:children
)))
3552 (mapc (lambda (child)
3553 (when (memq (widget-get child
:custom-state
) '(modified set
))
3554 (widget-apply child
:custom-save
)))
3557 (defun custom-group-reset-current (widget)
3558 "Reset all modified group members."
3559 (let ((children (widget-get widget
:children
)))
3560 (mapc (lambda (child)
3561 (when (eq (widget-get child
:custom-state
) 'modified
)
3562 (widget-apply child
:custom-reset-current
)))
3565 (defun custom-group-reset-saved (widget)
3566 "Reset all modified or set group members."
3567 (let ((children (widget-get widget
:children
)))
3568 (mapc (lambda (child)
3569 (when (memq (widget-get child
:custom-state
) '(modified set
))
3570 (widget-apply child
:custom-reset-saved
)))
3573 (defun custom-group-reset-standard (widget)
3574 "Reset all modified, set, or saved group members."
3575 (let ((children (widget-get widget
:children
)))
3576 (mapc (lambda (child)
3577 (when (memq (widget-get child
:custom-state
)
3578 '(modified set saved
))
3579 (widget-apply child
:custom-reset-standard
)))
3582 (defun custom-group-state-update (widget)
3584 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
3585 (let* ((children (widget-get widget
:children
))
3586 (states (mapcar (lambda (child)
3587 (widget-get child
:custom-state
))
3589 (magics custom-magic-alist
)
3592 (let ((magic (car (car magics
))))
3593 (if (and (not (eq magic
'hidden
))
3594 (memq magic states
))
3597 (setq magics
(cdr magics
)))))
3598 (widget-put widget
:custom-state found
)))
3599 (custom-magic-reset widget
))
3601 ;;; The `custom-save-all' Function.
3603 (defcustom custom-file nil
3604 "File used for storing customization information.
3605 The default is nil, which means to use your init file
3606 as specified by `user-init-file'. If you specify some other file,
3607 you need to explicitly load that file for the settings to take effect.
3609 When you change this variable, look in the previous custom file
3610 \(usually your init file) for the forms `(custom-set-variables ...)'
3611 and `(custom-set-faces ...)', and copy them (whichever ones you find)
3612 to the new custom file. This will preserve your existing customizations."
3613 :type
'(choice (const :tag
"Your Emacs init file" nil
) file
)
3616 (defun custom-file ()
3617 "Return the file name for saving customizations."
3620 (let ((user-init-file user-init-file
)
3622 (if (eq system-type
'ms-dos
) "~/_emacs" "~/.emacs")))
3623 (when (null user-init-file
)
3624 (if (or (file-exists-p default-init-file
)
3625 (and (eq system-type
'windows-nt
)
3626 (file-exists-p "~/_emacs")))
3627 ;; Started with -q, i.e. the file containing
3628 ;; Custom settings hasn't been read. Saving
3629 ;; settings there would overwrite other settings.
3630 (error "Saving settings from \"emacs -q\" would overwrite existing customizations"))
3631 (setq user-init-file default-init-file
))
3634 (defun custom-save-delete (symbol)
3635 "Visit `custom-file' and delete all calls to SYMBOL from it.
3636 Leave point at the old location of the first such call,
3637 or (if there were none) at the end of the buffer."
3638 (let ((default-major-mode 'emacs-lisp-mode
))
3639 (set-buffer (find-file-noselect (custom-file))))
3640 (goto-char (point-min))
3641 ;; Skip all whitespace and comments.
3642 (while (forward-comment 1))
3644 (save-excursion (forward-sexp (buffer-size)))) ; Test for scan errors.
3647 (while t
;; We exit this loop only via throw.
3648 ;; Skip all whitespace and comments.
3649 (while (forward-comment 1))
3650 (let ((start (point))
3651 (sexp (condition-case nil
3652 (read (current-buffer))
3653 (end-of-file (throw 'found nil
)))))
3654 (when (and (listp sexp
)
3655 (eq (car sexp
) symbol
))
3656 (delete-region start
(point))
3658 (setq first
(point)))))))
3661 ;; Move in front of local variables, otherwise long Custom
3662 ;; entries would make them ineffective.
3663 (let ((pos (point-max))
3664 (case-fold-search t
))
3666 (goto-char (point-max))
3667 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
3669 (when (search-forward "Local Variables:" nil t
)
3670 (setq pos
(line-beginning-position))))
3673 (defun custom-save-variables ()
3674 "Save all customized variables in `custom-file'."
3676 (custom-save-delete 'custom-load-themes
)
3677 (custom-save-delete 'custom-reset-variables
)
3678 (custom-save-delete 'custom-set-variables
)
3679 (custom-save-loaded-themes)
3680 (custom-save-resets 'theme-value
'custom-reset-variables nil
)
3681 (let ((standard-output (current-buffer))
3682 (saved-list (make-list 1 0))
3684 ;; First create a sorted list of saved variables.
3687 (if (get symbol
'saved-value
)
3688 (nconc saved-list
(list symbol
)))))
3689 (setq saved-list
(sort (cdr saved-list
) 'string
<))
3692 (princ "(custom-set-variables
3693 ;; custom-set-variables was added by Custom.
3694 ;; If you edit it by hand, you could mess it up, so be careful.
3695 ;; Your init file should contain only one such instance.
3696 ;; If there is more than one, they won't work right.\n")
3697 (dolist (symbol saved-list
)
3698 (let ((spec (car-safe (get symbol
'theme-value
)))
3699 (value (get symbol
'saved-value
))
3700 (requests (get symbol
'custom-requests
))
3701 (now (not (or (custom-variable-p symbol
)
3702 (and (not (boundp symbol
))
3703 (not (eq (get symbol
'force-value
)
3705 (comment (get symbol
'saved-variable-comment
))
3707 ;; Check `requests'.
3708 (dolist (request requests
)
3709 (when (and (symbolp request
) (not (featurep request
)))
3710 (message "Unknown requested feature: %s" request
)
3711 (setq requests
(delq request requests
))))
3713 (eq (nth 0 spec
) 'user
)
3714 (eq (nth 1 spec
) 'set
))
3716 (and (null spec
) (get symbol
'saved-value
)))
3723 (when (or now requests comment
)
3726 (when (or requests comment
)
3736 (unless (looking-at "\n")
3739 (defun custom-save-faces ()
3740 "Save all customized faces in `custom-file'."
3742 (custom-save-delete 'custom-reset-faces
)
3743 (custom-save-delete 'custom-set-faces
)
3744 (custom-save-resets 'theme-face
'custom-reset-faces
'(default))
3745 (let ((standard-output (current-buffer))
3746 (saved-list (make-list 1 0))
3748 ;; First create a sorted list of saved faces.
3751 (if (get symbol
'saved-face
)
3752 (nconc saved-list
(list symbol
)))))
3753 (setq saved-list
(sort (cdr saved-list
) 'string
<))
3754 ;; The default face must be first, since it affects the others.
3755 (if (memq 'default saved-list
)
3756 (setq saved-list
(cons 'default
(delq 'default saved-list
))))
3759 (princ "(custom-set-faces
3760 ;; custom-set-faces was added by Custom.
3761 ;; If you edit it by hand, you could mess it up, so be careful.
3762 ;; Your init file should contain only one such instance.
3763 ;; If there is more than one, they won't work right.\n")
3764 (dolist (symbol saved-list
)
3765 (let ((spec (car-safe (get symbol
'theme-face
)))
3766 (value (get symbol
'saved-face
))
3767 (now (not (or (get symbol
'face-defface-spec
)
3768 (and (not (custom-facep symbol
))
3769 (not (get symbol
'force-face
))))))
3770 (comment (get symbol
'saved-face-comment
)))
3772 (eq (nth 0 spec
) 'user
)
3773 (eq (nth 1 spec
) 'set
))
3775 (and (null spec
) (get symbol
'saved-face
)))
3776 ;; Don't print default face here.
3783 (when (or now comment
)
3793 (unless (looking-at "\n")
3796 (defun custom-save-resets (property setter special
)
3797 (let (started-writing ignored-special
)
3798 ;; (custom-save-delete setter) Done by caller
3799 (let ((standard-output (current-buffer))
3800 (mapper `(lambda (object)
3801 (let ((spec (car-safe (get object
(quote ,property
)))))
3802 (when (and (not (memq object ignored-special
))
3803 (eq (nth 0 spec
) 'user
)
3804 (eq (nth 1 spec
) 'reset
))
3805 ;; Do not write reset statements unless necessary.
3806 (unless started-writing
3807 (setq started-writing t
)
3811 (princ (quote ,setter
))
3815 (prin1 (nth 3 spec
))
3817 (mapc mapper special
)
3818 (setq ignored-special special
)
3820 (when started-writing
3823 (defun custom-save-loaded-themes ()
3824 (let ((themes (reverse (get 'user
'theme-loads-themes
)))
3825 (standard-output (current-buffer)))
3827 (unless (bolp) (princ "\n"))
3828 (princ "(custom-load-themes")
3829 (mapc (lambda (theme)
3831 (prin1 theme
)) themes
)
3835 (defun customize-save-customized ()
3836 "Save all user options which have been set in this session."
3838 (mapatoms (lambda (symbol)
3839 (let ((face (get symbol
'customized-face
))
3840 (value (get symbol
'customized-value
))
3841 (face-comment (get symbol
'customized-face-comment
))
3843 (get symbol
'customized-variable-comment
)))
3845 (put symbol
'saved-face face
)
3846 (custom-push-theme 'theme-face symbol
'user
'set value
)
3847 (put symbol
'customized-face nil
))
3849 (put symbol
'saved-value value
)
3850 (custom-push-theme 'theme-value symbol
'user
'set value
)
3851 (put symbol
'customized-value nil
))
3852 (when variable-comment
3853 (put symbol
'saved-variable-comment variable-comment
)
3854 (put symbol
'customized-variable-comment nil
))
3856 (put symbol
'saved-face-comment face-comment
)
3857 (put symbol
'customized-face-comment nil
)))))
3858 ;; We really should update all custom buffers here.
3862 (defun custom-save-all ()
3863 "Save all customizations in `custom-file'."
3864 (let ((inhibit-read-only t
))
3865 (custom-save-variables)
3868 (let ((default-major-mode nil
))
3869 (set-buffer (find-file-noselect (custom-file))))
3870 (let ((file-precious-flag t
))
3873 ;;; The Customize Menu.
3877 (defcustom custom-menu-nesting
2
3878 "Maximum nesting in custom menus."
3880 :group
'custom-menu
)
3882 (defun custom-face-menu-create (widget symbol
)
3883 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
3884 (vector (custom-unlispify-menu-entry symbol
)
3885 `(customize-face ',symbol
)
3888 (defun custom-variable-menu-create (widget symbol
)
3889 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
3890 (let ((type (get symbol
'custom-type
)))
3891 (unless (listp type
)
3892 (setq type
(list type
)))
3893 (if (and type
(widget-get type
:custom-menu
))
3894 (widget-apply type
:custom-menu symbol
)
3895 (vector (custom-unlispify-menu-entry symbol
)
3896 `(customize-variable ',symbol
)
3899 ;; Add checkboxes to boolean variable entries.
3900 (widget-put (get 'boolean
'widget-type
)
3901 :custom-menu
(lambda (widget symbol
)
3902 (vector (custom-unlispify-menu-entry symbol
)
3903 `(customize-variable ',symbol
)
3905 ':selected symbol
)))
3907 (defun custom-group-menu-create (widget symbol
)
3908 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
3909 `( ,(custom-unlispify-menu-entry symbol t
)
3910 :filter
(lambda (&rest junk
)
3911 (let ((menu (custom-menu-create ',symbol
)))
3912 (if (consp menu
) (cdr menu
) menu
)))))
3915 (defun custom-menu-create (symbol)
3916 "Create menu for customization group SYMBOL.
3917 The menu is in a format applicable to `easy-menu-define'."
3918 (let* ((item (vector (custom-unlispify-menu-entry symbol
)
3919 `(customize-group ',symbol
)
3921 (if (and (or (not (boundp 'custom-menu-nesting
))
3922 (>= custom-menu-nesting
0))
3924 (custom-load-symbol symbol
)
3925 (< (length (get symbol
'custom-group
)) widget-menu-max-size
)))
3926 (let ((custom-prefix-list (custom-prefix-add symbol
3927 custom-prefix-list
))
3928 (members (custom-sort-items (get symbol
'custom-group
)
3929 custom-menu-sort-alphabetically
3930 custom-menu-order-groups
)))
3931 `(,(custom-unlispify-menu-entry symbol t
)
3934 ,@(mapcar (lambda (entry)
3935 (widget-apply (if (listp (nth 1 entry
))
3937 (list (nth 1 entry
)))
3938 :custom-menu
(nth 0 entry
)))
3943 (defun customize-menu-create (symbol &optional name
)
3944 "Return a customize menu for customization group SYMBOL.
3945 If optional NAME is given, use that as the name of the menu.
3946 Otherwise the menu will be named `Customize'.
3947 The format is suitable for use with `easy-menu-define'."
3949 (setq name
"Customize"))
3951 :filter
(lambda (&rest junk
)
3952 (let ((menu (custom-menu-create ',symbol
)))
3953 (if (consp menu
) (cdr menu
) menu
)))))
3955 ;;; The Custom Mode.
3957 (defvar custom-mode-map nil
3958 "Keymap for `custom-mode'.")
3960 (unless custom-mode-map
3961 ;; This keymap should be dense, but a dense keymap would prevent inheriting
3962 ;; "\r" bindings from the parent map.
3963 (setq custom-mode-map
(make-sparse-keymap))
3964 (set-keymap-parent custom-mode-map widget-keymap
)
3965 (suppress-keymap custom-mode-map
)
3966 (define-key custom-mode-map
" " 'scroll-up
)
3967 (define-key custom-mode-map
"\177" 'scroll-down
)
3968 (define-key custom-mode-map
"q" 'Custom-buffer-done
)
3969 (define-key custom-mode-map
"u" 'Custom-goto-parent
)
3970 (define-key custom-mode-map
"n" 'widget-forward
)
3971 (define-key custom-mode-map
"p" 'widget-backward
)
3972 (define-key custom-mode-map
[mouse-1
] 'Custom-move-and-invoke
))
3974 (defun Custom-move-and-invoke (event)
3975 "Move to where you click, and if it is an active field, invoke it."
3977 (mouse-set-point event
)
3978 (if (widget-event-point event
)
3979 (let* ((pos (widget-event-point event
))
3980 (button (get-char-property pos
'button
)))
3982 (widget-button-click event
)))))
3984 (easy-menu-define Custom-mode-menu
3986 "Menu used in customization buffers."
3988 ,(customize-menu-create 'customize
)
3989 ["Set" Custom-set t
]
3990 ["Save" Custom-save t
]
3991 ["Reset to Current" Custom-reset-current t
]
3992 ["Reset to Saved" Custom-reset-saved t
]
3993 ["Reset to Standard Settings" Custom-reset-standard t
]
3994 ["Info" (Info-goto-node "(emacs)Easy Customization") t
]))
3996 (defun Custom-goto-parent ()
3997 "Go to the parent group listed at the top of this buffer.
3998 If several parents are listed, go to the first of them."
4001 (goto-char (point-min))
4002 (if (search-forward "\nGo to parent group: " nil t
)
4003 (let* ((button (get-char-property (point) 'button
))
4004 (parent (downcase (widget-get button
:tag
))))
4005 (customize-group parent
)))))
4007 (defcustom custom-mode-hook nil
4008 "Hook called when entering Custom mode."
4010 :group
'custom-buffer
)
4012 (defun custom-state-buffer-message (widget)
4013 (if (eq (widget-get (widget-get widget
:parent
) :custom-state
) 'modified
)
4014 (message "To install your edits, invoke [State] and choose the Set operation")))
4016 (defun custom-mode ()
4017 "Major mode for editing customization buffers.
4019 The following commands are available:
4021 Move to next button or editable field. \\[widget-forward]
4022 Move to previous button or editable field. \\[widget-backward]
4023 \\<widget-field-keymap>\
4024 Complete content of editable text field. \\[widget-complete]
4025 \\<custom-mode-map>\
4026 Invoke button under the mouse pointer. \\[Custom-move-and-invoke]
4027 Invoke button under point. \\[widget-button-press]
4028 Set all modifications. \\[Custom-set]
4029 Make all modifications default. \\[Custom-save]
4030 Reset all modified options. \\[Custom-reset-current]
4031 Reset all modified or set options. \\[Custom-reset-saved]
4032 Reset all options. \\[Custom-reset-standard]
4034 Entry to this mode calls the value of `custom-mode-hook'
4035 if that value is non-nil."
4036 (kill-all-local-variables)
4037 (setq major-mode
'custom-mode
4039 (use-local-map custom-mode-map
)
4040 (easy-menu-add Custom-mode-menu
)
4041 (make-local-variable 'custom-options
)
4042 (make-local-variable 'widget-documentation-face
)
4043 (setq widget-documentation-face
'custom-documentation-face
)
4044 (make-local-variable 'widget-button-face
)
4045 (setq widget-button-face
'custom-button-face
)
4046 (set (make-local-variable 'widget-button-pressed-face
)
4047 'custom-button-pressed-face
)
4048 (set (make-local-variable 'widget-mouse-face
)
4049 'custom-button-pressed-face
) ; buttons `depress' when moused
4050 ;; When possible, use relief for buttons, not bracketing. This test
4051 ;; may not be optimal.
4052 (when custom-raised-buttons
4053 (set (make-local-variable 'widget-push-button-prefix
) "")
4054 (set (make-local-variable 'widget-push-button-suffix
) "")
4055 (set (make-local-variable 'widget-link-prefix
) "")
4056 (set (make-local-variable 'widget-link-suffix
) ""))
4057 (add-hook 'widget-edit-functions
'custom-state-buffer-message nil t
)
4058 (run-hooks 'custom-mode-hook
))
4060 (put 'custom-mode
'mode-class
'special
)
4063 'debug-ignored-errors
4064 "^No user options have changed defaults in recent Emacs versions$")
4070 ;;; cus-edit.el ends here