1 ;;; cus-edit.el --- Tools for customizating Emacs and Lisp packages.
3 ;; Copyright (C) 1996, 1997 Free Software Foundation, Inc.
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
6 ;; Keywords: help, faces
8 ;; X-URL: http://www.dina.kvl.dk/~abraham/custom/
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
29 ;; This file implements the code to create and edit customize buffers.
33 ;; No commands should have names starting with `custom-' because
34 ;; that interferes with completion. Use `customize-' for commands
35 ;; that the user will run with M-x, and `Custom-' for interactive commands.
42 (eval-when-compile (require 'cl))
52 (define-widget-keywords :custom-last :custom-prefix :custom-category
53 :custom-prefixes :custom-menu
55 :custom-magic :custom-state :custom-level :custom-form
56 :custom-set :custom-save :custom-reset-current :custom-reset-saved
57 :custom-reset-standard)
59 (put 'custom-define-hook 'custom-type 'hook)
60 (put 'custom-define-hook 'standard-value '(nil))
61 (custom-add-to-group 'customize 'custom-define-hook 'custom-variable)
63 ;;; Customization Groups.
66 "Customization of the One True Editor."
67 :link '(custom-manual "(emacs)Top"))
69 ;; Most of these groups are stolen from `finder.el',
71 "Basic text editing facilities."
75 "Abbreviation handling, typing shortcuts, macros."
79 (defgroup matching nil
80 "Various sorts of searching and matching."
83 (defgroup emulations nil
84 "Emulations of other editors."
91 (defgroup outlines nil
92 "Support for hierarchical outlining."
95 (defgroup external nil
96 "Interfacing to external utilities."
100 "Code related to the `bib' bibliography processor."
104 (defgroup processes nil
105 "Process, subshell, compilation, and job control support."
109 (defgroup convenience nil
110 "Convenience features for faster editing."
113 (defgroup programming nil
114 "Support for programming in other languages."
117 (defgroup languages nil
118 "Specialized modes for editing programming languages."
122 "Lisp support, including Emacs Lisp."
127 "Support for the C language and related languages."
135 "Support for object-oriented programming."
138 (defgroup applications nil
139 "Applications written in Emacs."
142 (defgroup calendar nil
143 "Calendar and time management support."
144 :group 'applications)
147 "Modes for electronic-mail handling."
148 :group 'applications)
151 "Support for netnews reading and posting."
152 :group 'applications)
155 "Games, jokes and amusements."
156 :group 'applications)
158 (defgroup development nil
159 "Support for further development of Emacs."
163 "Support for Emacs documentation."
166 (defgroup extensions nil
167 "Emacs Lisp language extensions."
170 (defgroup internal nil
171 "Code for Emacs internals, build process, defaults."
175 "Maintenance aids for the Emacs development group."
179 (defgroup environment nil
180 "Fitting Emacs with its environment."
184 "Communications, networking, remote access to files."
188 (defgroup hardware nil
189 "Support for interfacing with exotic hardware."
192 (defgroup terminals nil
193 "Support for terminal types."
197 "Front-ends/assistants for, or emulators of, UNIX features."
201 "Support code for vms."
205 "Internationalization and alternate character-set support."
210 "The X Window system."
214 "Support for Emacs frames and window systems."
218 "Support editing files of data."
222 "Support editing files."
230 "Code related to the TeX formatter."
234 "Support for multiple fonts."
237 (defgroup hypermedia nil
238 "Support for links between text or other media types."
242 "Support for on-line help systems."
246 "Code local to your site."
249 (defgroup customize '((widgets custom-group))
250 "Customization of the Customization support."
251 :link '(custom-manual "(custom)Top")
252 :link '(url-link :tag "Development Page"
253 "http://www.dina.kvl.dk/~abraham/custom/")
257 (defgroup custom-faces nil
258 "Faces used by customize."
262 (defgroup custom-browse nil
263 "Control customize browser."
267 (defgroup custom-buffer nil
268 "Control customize buffers."
272 (defgroup custom-menu nil
273 "Control customize menus."
277 (defgroup abbrev-mode nil
278 "Word abbreviations mode."
282 "Storage allocation and gc for GNU Emacs Lisp interpreter."
283 :tag "Storage Allocation"
287 "Undoing changes in buffers."
290 (defgroup modeline nil
291 "Content of the modeline."
295 "Indenting and filling text."
298 (defgroup editing-basics nil
299 "Most basic editing facilities."
302 (defgroup display nil
303 "How characters are displayed in buffers."
306 (defgroup execute nil
307 "Executing external commands."
310 (defgroup installation nil
311 "The Emacs installation."
319 "Internal Emacs limits."
323 "Debugging Emacs itself."
326 (defgroup minibuffer nil
327 "Controling the behaviour of the minibuffer."
330 (defgroup keyboard nil
331 "Input from the keyboard."
335 "Input from the mouse."
339 "Input from the menus."
342 (defgroup auto-save nil
343 "Preventing accidential loss of data."
346 (defgroup processes-basics nil
347 "Basic stuff dealing with processes."
351 "MULE Emacs internationalization."
354 (defgroup windows nil
355 "Windows within a frame."
360 (defun custom-last (x &optional n)
361 ;; Stolen from `cl.el'.
362 "Returns the last link in the list LIST.
363 With optional argument N, returns Nth-to-last link (default 1)."
366 (while (consp p) (incf m) (pop p))
368 (if (< n m) (nthcdr (- m n) x) x)))
369 (while (consp (cdr x)) (pop x))
372 (defun custom-quote (sexp)
373 "Quote SEXP iff it is not self quoting."
374 (if (or (memq sexp '(t nil))
376 (eq (aref (symbol-name sexp) 0) ?:))
378 (memq (car sexp) '(lambda)))
381 (and (fboundp 'characterp)
386 (defun custom-split-regexp-maybe (regexp)
387 "If REGEXP is a string, split it to a list at `\\|'.
388 You can get the original back with from the result with:
389 (mapconcat 'identity result \"\\|\")
391 IF REGEXP is not a string, return it unchanged."
395 (while (string-match "\\\\|" regexp start)
396 (setq all (cons (substring regexp start (match-beginning 0)) all)
397 start (match-end 0)))
398 (nreverse (cons (substring regexp start) all)))
401 (defun custom-variable-prompt ()
402 ;; Code stolen from `help.el'.
403 "Prompt for a variable, defaulting to the variable at point.
404 Return a list suitable for use in `interactive'."
405 (let ((v (variable-at-point))
406 (enable-recursive-minibuffers t)
408 (setq val (completing-read
410 (format "Customize option: (default %s) " v)
411 "Customize variable: ")
412 obarray (lambda (symbol)
414 (or (get symbol 'custom-type)
415 (user-variable-p symbol)))) t))
416 (list (if (equal val "")
417 (if (symbolp v) v nil)
420 (defun custom-menu-filter (menu widget)
421 "Convert MENU to the form used by `widget-choose'.
422 MENU should be in the same format as `custom-variable-menu'.
423 WIDGET is the widget to apply the filter entries of MENU on."
425 current name action filter)
427 (setq current (car menu)
429 action (nth 1 current)
430 filter (nth 2 current)
432 (if (or (null filter) (funcall filter widget))
433 (push (cons name action) result)
439 (defvar custom-prefix-list nil
440 "List of prefixes that should be ignored by `custom-unlispify'")
442 (defcustom custom-unlispify-menu-entries t
443 "Display menu entries as words instead of symbols if non nil."
447 (defcustom custom-unlispify-remove-prefixes nil
448 "Non-nil means remove group prefixes from option names in buffer."
452 (defun custom-unlispify-menu-entry (symbol &optional no-suffix)
453 "Convert symbol into a menu entry."
454 (cond ((not custom-unlispify-menu-entries)
455 (symbol-name symbol))
456 ((get symbol 'custom-tag)
458 (get symbol 'custom-tag)
459 (concat (get symbol 'custom-tag) "...")))
462 (set-buffer (get-buffer-create " *Custom-Work*"))
464 (princ symbol (current-buffer))
465 (goto-char (point-min))
466 (when (and (eq (get symbol 'custom-type) 'boolean)
467 (re-search-forward "-p\\'" nil t))
468 (replace-match "" t t)
469 (goto-char (point-min)))
470 (if custom-unlispify-remove-prefixes
471 (let ((prefixes custom-prefix-list)
474 (setq prefix (car prefixes))
475 (if (search-forward prefix (+ (point) (length prefix)) t)
478 (delete-region (point-min) (point)))
479 (setq prefixes (cdr prefixes))))))
480 (subst-char-in-region (point-min) (point-max) ?- ?\ t)
481 (capitalize-region (point-min) (point-max))
483 (goto-char (point-max))
487 (defcustom custom-unlispify-tag-names t
488 "Display tag names as words instead of symbols if non nil."
489 :group 'custom-buffer
492 (defun custom-unlispify-tag-name (symbol)
493 "Convert symbol into a menu entry."
494 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names))
495 (custom-unlispify-menu-entry symbol t)))
497 (defun custom-prefix-add (symbol prefixes)
498 ;; Addd SYMBOL to list of ignored PREFIXES.
499 (cons (or (get symbol 'custom-prefix)
500 (concat (symbol-name symbol) "-"))
505 (defcustom custom-guess-name-alist
510 ("-function\\'" function)
511 ("-functions\\'" (repeat function))
512 ("-list\\'" (repeat sexp))
513 ("-alist\\'" (repeat (cons sexp sexp))))
514 "Alist of (MATCH TYPE).
516 MATCH should be a regexp matching the name of a symbol, and TYPE should
517 be a widget suitable for editing the value of that symbol. The TYPE
518 of the first entry where MATCH matches the name of the symbol will be
521 This is used for guessing the type of variables not declared with
523 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
526 (defcustom custom-guess-doc-alist
527 '(("\\`\\*?Non-nil " boolean))
528 "Alist of (MATCH TYPE).
530 MATCH should be a regexp matching a documentation string, and TYPE
531 should be a widget suitable for editing the value of a variable with
532 that documentation string. The TYPE of the first entry where MATCH
533 matches the name of the symbol will be used.
535 This is used for guessing the type of variables not declared with
537 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
540 (defun custom-guess-type (symbol)
541 "Guess a widget suitable for editing the value of SYMBOL.
542 This is done by matching SYMBOL with `custom-guess-name-alist' and
543 if that fails, the doc string with `custom-guess-doc-alist'."
544 (let ((name (symbol-name symbol))
545 (names custom-guess-name-alist)
548 (setq current (car names)
550 (when (string-match (nth 0 current) name)
551 (setq found (nth 1 current)
554 (let ((doc (documentation-property symbol 'variable-documentation))
555 (docs custom-guess-doc-alist))
558 (setq current (car docs)
560 (when (string-match (nth 0 current) doc)
561 (setq found (nth 1 current)
567 (defcustom custom-browse-sort-alphabetically nil
568 "If non-nil, sort members of each customization group alphabetically."
570 :group 'custom-browse)
572 (defcustom custom-browse-order-groups nil
573 "If non-nil, order group members within each customization group.
574 If `first', order groups before non-groups.
575 If `last', order groups after non-groups."
576 :type '(choice (const first)
578 (const :tag "none" nil))
579 :group 'custom-browse)
581 (defcustom custom-browse-only-groups nil
582 "If non-nil, show group members only within each customization group."
584 :group 'custom-browse)
586 (defcustom custom-buffer-sort-alphabetically nil
587 "If non-nil, sort members of each customization group alphabetically."
589 :group 'custom-buffer)
591 (defcustom custom-buffer-order-groups 'last
592 "If non-nil, order group members within each customization group.
593 If `first', order groups before non-groups.
594 If `last', order groups after non-groups."
595 :type '(choice (const first)
597 (const :tag "none" nil))
598 :group 'custom-buffer)
600 (defcustom custom-menu-sort-alphabetically nil
601 "If non-nil, sort members of each customization group alphabetically."
605 (defcustom custom-menu-order-groups 'first
606 "If non-nil, order group members within each customization group.
607 If `first', order groups before non-groups.
608 If `last', order groups after non-groups."
609 :type '(choice (const first)
611 (const :tag "none" nil))
614 ;;;###autoload (add-hook 'same-window-regexps "\\`\\*Customiz.*\\*\\'")
616 (defun custom-sort-items (items sort-alphabetically order-groups)
617 "Return a sorted copy of ITEMS.
618 ITEMS should be a `custom-group' property.
619 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
620 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
621 groups after non-groups, if nil do not order groups at all."
622 (sort (copy-sequence items)
624 (let ((typea (nth 1 a)) (typeb (nth 1 b))
625 (namea (symbol-name (nth 0 a))) (nameb (symbol-name (nth 0 b))))
626 (cond ((not order-groups)
627 ;; Since we don't care about A and B order, maybe sort.
628 (when sort-alphabetically
629 (string-lessp namea nameb)))
630 ((eq typea 'custom-group)
631 ;; If B is also a group, maybe sort. Otherwise, order A and B.
632 (if (eq typeb 'custom-group)
633 (when sort-alphabetically
634 (string-lessp namea nameb))
635 (eq order-groups 'first)))
636 ((eq typeb 'custom-group)
637 ;; Since A cannot be a group, order A and B.
638 (eq order-groups 'last))
640 ;; Since A and B cannot be groups, sort.
641 (string-lessp namea nameb)))))))
643 ;;; Custom Mode Commands.
645 (defvar custom-options nil
646 "Customization widgets in the current buffer.")
649 "Set changes in all modified options."
651 (let ((children custom-options))
652 (mapcar (lambda (child)
653 (when (eq (widget-get child :custom-state) 'modified)
654 (widget-apply child :custom-set)))
657 (defun Custom-save ()
658 "Set all modified group members and save them."
660 (let ((children custom-options))
661 (mapcar (lambda (child)
662 (when (memq (widget-get child :custom-state) '(modified set))
663 (widget-apply child :custom-save)))
667 (defvar custom-reset-menu
668 '(("Current" . Custom-reset-current)
669 ("Saved" . Custom-reset-saved)
670 ("Standard Settings" . Custom-reset-standard))
671 "Alist of actions for the `Reset' button.
672 The key is a string containing the name of the action, the value is a
673 lisp function taking the widget as an element which will be called
674 when the action is chosen.")
676 (defun custom-reset (event)
677 "Select item from reset menu."
678 (let* ((completion-ignore-case t)
679 (answer (widget-choose "Reset to"
685 (defun Custom-reset-current (&rest ignore)
686 "Reset all modified group members to their current value."
688 (let ((children custom-options))
689 (mapcar (lambda (child)
690 (when (eq (widget-get child :custom-state) 'modified)
691 (widget-apply child :custom-reset-current)))
694 (defun Custom-reset-saved (&rest ignore)
695 "Reset all modified or set group members to their saved value."
697 (let ((children custom-options))
698 (mapcar (lambda (child)
699 (when (eq (widget-get child :custom-state) 'modified)
700 (widget-apply child :custom-reset-saved)))
703 (defun Custom-reset-standard (&rest ignore)
704 "Reset all modified, set, or saved group members to their standard settings."
706 (let ((children custom-options))
707 (mapcar (lambda (child)
708 (when (eq (widget-get child :custom-state) 'modified)
709 (widget-apply child :custom-reset-standard)))
712 ;;; The Customize Commands
714 (defun custom-prompt-variable (prompt-var prompt-val)
715 "Prompt for a variable and a value and return them as a list.
716 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
717 prompt for the value. The %s escape in PROMPT-VAL is replaced with
718 the name of the variable.
720 If the variable has a `variable-interactive' property, that is used as if
721 it were the arg to `interactive' (which see) to interactively read the value.
723 If the variable has a `custom-type' property, it must be a widget and the
724 `:prompt-value' property of that widget will be used for reading the value."
725 (let* ((var (read-variable prompt-var))
726 (minibuffer-help-form '(describe-variable var)))
728 (let ((prop (get var 'variable-interactive))
729 (type (get var 'custom-type))
730 (prompt (format prompt-val var)))
732 (setq type (list type)))
734 ;; Use VAR's `variable-interactive' property
735 ;; as an interactive spec for prompting.
736 (call-interactively (list 'lambda '(arg)
737 (list 'interactive prop)
740 (widget-prompt-value type
746 (eval-minibuffer prompt)))))))
749 (defun customize-set-value (var val)
750 "Set VARIABLE to VALUE. VALUE is a Lisp object.
752 If VARIABLE has a `variable-interactive' property, that is used as if
753 it were the arg to `interactive' (which see) to interactively read the value.
755 If VARIABLE has a `custom-type' property, it must be a widget and the
756 `:prompt-value' property of that widget will be used for reading the value."
757 (interactive (custom-prompt-variable "Set variable: "
758 "Set %s to value: "))
763 (defun customize-set-variable (var val)
764 "Set the default for VARIABLE to VALUE. VALUE is a Lisp object.
766 If VARIABLE has a `custom-set' property, that is used for setting
767 VARIABLE, otherwise `set-default' is used.
769 The `customized-value' property of the VARIABLE will be set to a list
770 with a quoted VALUE as its sole list member.
772 If VARIABLE has a `variable-interactive' property, that is used as if
773 it were the arg to `interactive' (which see) to interactively read the value.
775 If VARIABLE has a `custom-type' property, it must be a widget and the
776 `:prompt-value' property of that widget will be used for reading the value. "
777 (interactive (custom-prompt-variable "Set variable: "
778 "Set customized value for %s to: "))
779 (funcall (or (get var 'custom-set) 'set-default) var val)
780 (put var 'customized-value (list (custom-quote val))))
783 (defun customize-save-variable (var val)
784 "Set the default for VARIABLE to VALUE, and save it for future sessions.
785 If VARIABLE has a `custom-set' property, that is used for setting
786 VARIABLE, otherwise `set-default' is used.
788 The `customized-value' property of the VARIABLE will be set to a list
789 with a quoted VALUE as its sole list member.
791 If VARIABLE has a `variable-interactive' property, that is used as if
792 it were the arg to `interactive' (which see) to interactively read the value.
794 If VARIABLE has a `custom-type' property, it must be a widget and the
795 `:prompt-value' property of that widget will be used for reading the value. "
796 (interactive (custom-prompt-variable "Set and ave variable: "
797 "Set and save value for %s as: "))
798 (funcall (or (get var 'custom-set) 'set-default) var val)
799 (put var 'saved-value (list (custom-quote val)))
804 "Select a customization buffer which you can use to set user options.
805 User options are structured into \"groups\".
806 Initially the top-level group `Emacs' and its immediate subgroups
807 are shown; the contents of those subgroups are initially hidden."
809 (customize-group 'emacs))
812 (defun customize-group (group)
813 "Customize GROUP, which must be a customization group."
814 (interactive (list (let ((completion-ignore-case t))
815 (completing-read "Customize group: (default emacs) "
818 (or (get symbol 'custom-loads)
819 (get symbol 'custom-group)))
821 (when (stringp group)
822 (if (string-equal "" group)
824 (setq group (intern group))))
825 (or (get group 'custom-group)
826 (custom-load-symbol group))
827 (let ((name (format "*Customize Group: %s*"
828 (custom-unlispify-tag-name group))))
829 (if (get-buffer name)
831 (custom-buffer-create (list (list group 'custom-group))
833 (concat " for group "
834 (custom-unlispify-tag-name group))))))
837 (defun customize-group-other-window (group)
838 "Customize GROUP, which must be a customization group."
839 (interactive (list (let ((completion-ignore-case t))
840 (completing-read "Customize group: (default emacs) "
843 (or (get symbol 'custom-loads)
844 (get symbol 'custom-group)))
846 (when (stringp group)
847 (if (string-equal "" group)
849 (setq group (intern group))))
850 (or (get group 'custom-group)
851 (custom-load-symbol group))
852 (let ((name (format "*Customize Group: %s*"
853 (custom-unlispify-tag-name group))))
854 (if (get-buffer name)
855 (let ((window (selected-window)))
857 (select-window window))
858 (custom-buffer-create-other-window
859 (list (list group 'custom-group))
861 (concat " for group "
862 (custom-unlispify-tag-name group))))))
865 (defalias 'customize-variable 'customize-option)
868 (defun customize-option (symbol)
869 "Customize SYMBOL, which must be a user option variable."
870 (interactive (custom-variable-prompt))
871 ;; If we don't have SYMBOL's real definition loaded,
873 (unless (get symbol 'custom-type)
874 (let ((loaddefs-file (locate-library "loaddefs.el" t))
876 ;; See if it is autoloaded from some library.
879 (insert-file-contents loaddefs-file)
880 (when (re-search-forward (concat "^(defvar " (symbol-name symbol))
882 (search-backward "\n;;; Generated autoloads from ")
883 (goto-char (match-end 0))
884 (setq file (buffer-substring (point)
885 (progn (end-of-line) (point)))))))
886 ;; If it is, load that library.
888 (when (string-match "\\.el\\'" file)
889 (setq file (substring file 0 (match-beginning 0))))
891 (unless (get symbol 'custom-type)
892 (error "Variable %s cannot be customized" symbol))
893 (custom-buffer-create (list (list symbol 'custom-variable))
894 (format "*Customize Option: %s*"
895 (custom-unlispify-tag-name symbol))))
897 (defvar customize-changed-options-previous-release "20.2"
898 "Version for `customize-changed-options' to refer back to by default.")
901 (defun customize-changed-options (since-version)
902 "Customize all user option variables changed in Emacs itself.
903 This includes new user option variables and faces, and new
904 customization groups, as well as older options and faces whose default
905 values have changed since the previous major Emacs release.
907 With argument SINCE-VERSION (a string), customize all user option
908 variables that were added (or their meanings were changed) since that
911 (interactive "sCustomize options changed, since version (default all versions): ")
912 (if (equal since-version "")
913 (setq since-version nil))
914 (unless since-version
915 (setq since-version customize-changed-options-previous-release))
918 (mapatoms (lambda (symbol)
919 (and (or (boundp symbol)
920 ;; For variables not yet loaded.
921 (get symbol 'standard-value)
922 ;; For groups the previous test fails, this one
923 ;; could be used to determine if symbol is a
924 ;; group. Is there a better way for this?
925 (get symbol 'group-documentation))
926 (let ((version (get symbol 'custom-version)))
928 (or (null since-version)
929 (customize-version-lessp since-version version))
930 (if (member version versions)
932 ;;; Collect all versions that we use.
933 (push version versions))))
935 ;; We have to set the right thing here,
936 ;; depending if we have a group or a
938 (if (get symbol 'group-documentation)
939 (cons (list symbol 'custom-group) found)
940 (cons (list symbol 'custom-variable) found))))))
942 (error "No user option defaults have been changed since Emacs %s"
947 (cdr (assoc (car versions) custom-versions-load-alist)))
949 (setq versions (cdr versions)))
950 (put 'custom-versions-load-alist 'custom-loads
951 ;; Get all the files that correspond to element from the
952 ;; VERSIONS list. This could use some simplification.
953 (apply 'nconc flist)))
954 ;; Because we set all the files needed to be loaded as a
955 ;; `custom-loads' property to `custom-versions-load-alist' this
956 ;; call will actually load them.
957 (custom-load-symbol 'custom-versions-load-alist)
959 (put 'custom-versions-load-alist 'custom-loads nil)
960 (custom-buffer-create (custom-sort-items found t 'first)
961 "*Customize Changed Options*"))))
963 (defun customize-version-lessp (version1 version2)
964 ;; In case someone made a mistake and left out the quotes
965 ;; in the :version value.
966 (if (numberp version2)
967 (setq version2 (prin1-to-string version2)))
968 (let (major1 major2 minor1 minor2)
969 (string-match "\\([0-9]+\\)[.]\\([0-9]+\\)" version1)
970 (setq major1 (read (match-string 1 version1)))
971 (setq minor1 (read (match-string 2 version1)))
972 (string-match "\\([0-9]+\\)[.]\\([0-9]+\\)" version2)
973 (setq major2 (read (match-string 1 version2)))
974 (setq minor2 (read (match-string 2 version2)))
975 (or (< major1 major2)
976 (and (= major1 major2)
977 (< minor1 minor2)))))
980 (defalias 'customize-variable-other-window 'customize-option-other-window)
983 (defun customize-option-other-window (symbol)
984 "Customize SYMBOL, which must be a user option variable.
985 Show the buffer in another window, but don't select it."
986 (interactive (custom-variable-prompt))
987 (custom-buffer-create-other-window
988 (list (list symbol 'custom-variable))
989 (format "*Customize Option: %s*" (custom-unlispify-tag-name symbol))))
992 (defun customize-face (&optional symbol)
993 "Customize SYMBOL, which should be a face name or nil.
994 If SYMBOL is nil, customize all faces."
995 (interactive (list (completing-read "Customize face: (default all) "
996 obarray 'custom-facep)))
997 (if (or (null symbol) (and (stringp symbol) (zerop (length symbol))))
998 (custom-buffer-create (custom-sort-items
999 (mapcar (lambda (symbol)
1000 (list symbol 'custom-face))
1003 "*Customize Faces*")
1004 (when (stringp symbol)
1005 (setq symbol (intern symbol)))
1006 (unless (symbolp symbol)
1007 (error "Should be a symbol %S" symbol))
1008 (custom-buffer-create (list (list symbol 'custom-face))
1009 (format "*Customize Face: %s*"
1010 (custom-unlispify-tag-name symbol)))))
1013 (defun customize-face-other-window (&optional symbol)
1014 "Show customization buffer for FACE in other window."
1015 (interactive (list (completing-read "Customize face: "
1016 obarray 'custom-facep)))
1017 (if (or (null symbol) (and (stringp symbol) (zerop (length symbol))))
1019 (if (stringp symbol)
1020 (setq symbol (intern symbol)))
1021 (unless (symbolp symbol)
1022 (error "Should be a symbol %S" symbol))
1023 (custom-buffer-create-other-window
1024 (list (list symbol 'custom-face))
1025 (format "*Customize Face: %s*" (custom-unlispify-tag-name symbol)))))
1028 (defun customize-customized ()
1029 "Customize all user options set since the last save in this session."
1032 (mapatoms (lambda (symbol)
1033 (and (get symbol 'customized-face)
1034 (custom-facep symbol)
1035 (push (list symbol 'custom-face) found))
1036 (and (get symbol 'customized-value)
1038 (push (list symbol 'custom-variable) found))))
1040 (error "No customized user options")
1041 (custom-buffer-create (custom-sort-items found t nil)
1042 "*Customize Customized*"))))
1045 (defun customize-saved ()
1046 "Customize all already saved user options."
1049 (mapatoms (lambda (symbol)
1050 (and (get symbol 'saved-face)
1051 (custom-facep symbol)
1052 (push (list symbol 'custom-face) found))
1053 (and (get symbol 'saved-value)
1055 (push (list symbol 'custom-variable) found))))
1057 (error "No saved user options")
1058 (custom-buffer-create (custom-sort-items found t nil)
1059 "*Customize Saved*"))))
1062 (defun customize-apropos (regexp &optional all)
1063 "Customize all user options matching REGEXP.
1064 If ALL is `options', include only options.
1065 If ALL is `faces', include only faces.
1066 If ALL is `groups', include only groups.
1067 If ALL is t (interactively, with prefix arg), include options which are not
1068 user-settable, as well as faces and groups."
1069 (interactive "sCustomize regexp: \nP")
1071 (mapatoms (lambda (symbol)
1072 (when (string-match regexp (symbol-name symbol))
1073 (when (and (not (memq all '(faces options)))
1074 (get symbol 'custom-group))
1075 (push (list symbol 'custom-group) found))
1076 (when (and (not (memq all '(options groups)))
1077 (custom-facep symbol))
1078 (push (list symbol 'custom-face) found))
1079 (when (and (not (memq all '(groups faces)))
1081 (or (get symbol 'saved-value)
1082 (get symbol 'standard-value)
1083 (if (memq all '(nil options))
1084 (user-variable-p symbol)
1085 (get symbol 'variable-documentation))))
1086 (push (list symbol 'custom-variable) found)))))
1088 (error "No matches")
1089 (custom-buffer-create (custom-sort-items found t
1090 custom-buffer-order-groups)
1091 "*Customize Apropos*"))))
1094 (defun customize-apropos-options (regexp &optional arg)
1095 "Customize all user options matching REGEXP.
1096 With prefix arg, include options which are not user-settable."
1097 (interactive "sCustomize regexp: \nP")
1098 (customize-apropos regexp (or arg 'options)))
1101 (defun customize-apropos-faces (regexp)
1102 "Customize all user faces matching REGEXP."
1103 (interactive "sCustomize regexp: \n")
1104 (customize-apropos regexp 'faces))
1107 (defun customize-apropos-groups (regexp)
1108 "Customize all user groups matching REGEXP."
1109 (interactive "sCustomize regexp: \n")
1110 (customize-apropos regexp 'groups))
1114 (defcustom custom-buffer-style 'links
1115 "Control the presentation style for customization buffers.
1116 The value should be a symbol, one of:
1118 brackets: groups nest within each other with big horizontal brackets.
1119 links: groups have links to subgroups."
1120 :type '(radio (const brackets)
1122 :group 'custom-buffer)
1124 (defcustom custom-buffer-indent 3
1125 "Number of spaces to indent nested groups."
1127 :group 'custom-buffer)
1130 (defun custom-buffer-create (options &optional name description)
1131 "Create a buffer containing OPTIONS.
1132 Optional NAME is the name of the buffer.
1133 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1134 SYMBOL is a customization option, and WIDGET is a widget for editing
1136 (unless name (setq name "*Customization*"))
1137 (kill-buffer (get-buffer-create name))
1138 (pop-to-buffer (get-buffer-create name))
1139 (custom-buffer-create-internal options description))
1142 (defun custom-buffer-create-other-window (options &optional name description)
1143 "Create a buffer containing OPTIONS.
1144 Optional NAME is the name of the buffer.
1145 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1146 SYMBOL is a customization option, and WIDGET is a widget for editing
1148 (unless name (setq name "*Customization*"))
1149 (kill-buffer (get-buffer-create name))
1150 (let ((window (selected-window))
1152 (special-display-buffer-names nil)
1153 (special-display-regexps nil)
1154 (same-window-buffer-names nil)
1155 (same-window-regexps nil))
1156 (pop-to-buffer (get-buffer-create name))
1157 (custom-buffer-create-internal options description)
1158 (select-window window)))
1160 (defcustom custom-reset-button-menu nil
1161 "If non-nil, only show a single reset button in customize buffers.
1162 This button will have a menu with all three reset operations."
1164 :group 'custom-buffer)
1166 (defun custom-buffer-create-internal (options &optional description)
1167 (message "Creating customization buffer...")
1169 (widget-insert "This is a customization buffer")
1171 (widget-insert description))
1173 Square brackets show active fields; type RET or click mouse-1
1174 on an active field to invoke its action. Editing an option value
1175 changes the text in the buffer; invoke the State button and
1176 choose the Set operation to set the option value.
1178 (widget-create 'info-link
1180 :help-echo "Read the online help."
1181 "(emacs)Easy Customization")
1182 (widget-insert " for more information.\n\n")
1183 (message "Creating customization buttons...")
1184 (widget-insert "Operate on everything in this buffer:\n ")
1185 (widget-create 'push-button
1186 :tag "Set for Current Session"
1188 Make your editing in this buffer take effect for this session."
1189 :action (lambda (widget &optional event)
1192 (widget-create 'push-button
1193 :tag "Save for Future Sessions"
1195 Make your editing in this buffer take effect for future Emacs sessions."
1196 :action (lambda (widget &optional event)
1198 (if custom-reset-button-menu
1201 (widget-create 'push-button
1203 :help-echo "Show a menu with reset operations."
1204 :mouse-down-action (lambda (&rest junk) t)
1205 :action (lambda (widget &optional event)
1206 (custom-reset event))))
1207 (widget-insert "\n ")
1208 (widget-create 'push-button
1211 Reset all edited text in this buffer to reflect current values."
1212 :action 'Custom-reset-current)
1214 (widget-create 'push-button
1215 :tag "Reset to Saved"
1217 Reset all values in this buffer to their saved settings."
1218 :action 'Custom-reset-saved)
1220 (widget-create 'push-button
1221 :tag "Reset to Standard"
1223 Reset all values in this buffer to their standard settings."
1224 :action 'Custom-reset-standard))
1226 (widget-create 'push-button
1228 :help-echo "Bury the buffer."
1229 :action (lambda (widget &optional event)
1231 (widget-insert "\n\n")
1232 (message "Creating customization items...")
1233 (setq custom-options
1234 (if (= (length options) 1)
1235 (mapcar (lambda (entry)
1236 (widget-create (nth 1 entry)
1237 :documentation-shown t
1238 :custom-state 'unknown
1239 :tag (custom-unlispify-tag-name
1241 :value (nth 0 entry)))
1244 (length (length options)))
1245 (mapcar (lambda (entry)
1247 (message "Creating customization items ...%2d%%"
1248 (/ (* 100.0 count) length))
1249 (widget-create (nth 1 entry)
1250 :tag (custom-unlispify-tag-name
1252 :value (nth 0 entry))
1253 (setq count (1+ count))
1254 (unless (eq (preceding-char) ?\n)
1255 (widget-insert "\n"))
1256 (widget-insert "\n")))
1258 (unless (eq (preceding-char) ?\n)
1259 (widget-insert "\n"))
1260 (message "Creating customization items ...%2d%%done" 100)
1261 (unless (eq custom-buffer-style 'tree)
1262 (mapcar 'custom-magic-reset custom-options))
1263 (message "Creating customization setup...")
1265 (goto-char (point-min))
1266 (message "Creating customization buffer...done"))
1268 ;;; The Tree Browser.
1271 (defun customize-browse (&optional group)
1272 "Create a tree browser for the customize hierarchy."
1275 (setq group 'emacs))
1276 (let ((name "*Customize Browser*"))
1277 (kill-buffer (get-buffer-create name))
1278 (pop-to-buffer (get-buffer-create name)))
1281 Square brackets show active fields; type RET or click mouse-1
1282 on an active field to invoke its action.
1283 Invoke [+] below to expand a group, and [-] to collapse an expanded group.\n")
1284 (if custom-browse-only-groups
1286 Invoke the [Group] button below to edit that item in another window.\n\n")
1287 (widget-insert "Invoke the ")
1288 (widget-create 'item
1291 :tag-glyph "folder")
1292 (widget-insert ", ")
1293 (widget-create 'item
1297 (widget-insert ", and ")
1298 (widget-create 'item
1301 :tag-glyph "option")
1302 (widget-insert " buttons below to edit that
1303 item in another window.\n\n"))
1304 (let ((custom-buffer-style 'tree))
1305 (widget-create 'custom-group
1307 :custom-state 'unknown
1308 :tag (custom-unlispify-tag-name group)
1310 (goto-char (point-min)))
1312 (define-widget 'custom-browse-visibility 'item
1313 "Control visibility of items in the customize tree browser."
1315 :action 'custom-browse-visibility-action)
1317 (defun custom-browse-visibility-action (widget &rest ignore)
1318 (let ((custom-buffer-style 'tree))
1319 (custom-toggle-parent widget)))
1321 (define-widget 'custom-browse-group-tag 'push-button
1322 "Show parent in other window when activated."
1325 :action 'custom-browse-group-tag-action)
1327 (defun custom-browse-group-tag-action (widget &rest ignore)
1328 (let ((parent (widget-get widget :parent)))
1329 (customize-group-other-window (widget-value parent))))
1331 (define-widget 'custom-browse-variable-tag 'push-button
1332 "Show parent in other window when activated."
1335 :action 'custom-browse-variable-tag-action)
1337 (defun custom-browse-variable-tag-action (widget &rest ignore)
1338 (let ((parent (widget-get widget :parent)))
1339 (customize-variable-other-window (widget-value parent))))
1341 (define-widget 'custom-browse-face-tag 'push-button
1342 "Show parent in other window when activated."
1345 :action 'custom-browse-face-tag-action)
1347 (defun custom-browse-face-tag-action (widget &rest ignore)
1348 (let ((parent (widget-get widget :parent)))
1349 (customize-face-other-window (widget-value parent))))
1351 (defconst custom-browse-alist '((" " "space")
1357 (defun custom-browse-insert-prefix (prefix)
1358 "Insert PREFIX. On XEmacs convert it to line graphics."
1359 (if nil ; (string-match "XEmacs" emacs-version)
1362 (while (not (string-equal prefix ""))
1363 (let ((entry (substring prefix 0 3)))
1364 (setq prefix (substring prefix 3))
1365 (let ((overlay (make-overlay (1- (point)) (point) nil t nil))
1366 (name (nth 1 (assoc entry custom-browse-alist))))
1367 (overlay-put overlay 'end-glyph (widget-glyph-find name entry))
1368 (overlay-put overlay 'start-open t)
1369 (overlay-put overlay 'end-open t)))))
1372 ;;; Modification of Basic Widgets.
1374 ;; We add extra properties to the basic widgets needed here. This is
1375 ;; fine, as long as we are careful to stay within out own namespace.
1377 ;; We want simple widgets to be displayed by default, but complex
1378 ;; widgets to be hidden.
1380 (widget-put (get 'item 'widget-type) :custom-show t)
1381 (widget-put (get 'editable-field 'widget-type)
1382 :custom-show (lambda (widget value)
1383 (let ((pp (pp-to-string value)))
1384 (cond ((string-match "\n" pp)
1389 (widget-put (get 'menu-choice 'widget-type) :custom-show t)
1391 ;;; The `custom-manual' Widget.
1393 (define-widget 'custom-manual 'info-link
1394 "Link to the manual entry for this customization option."
1395 :help-echo "Read the manual entry for this option."
1398 ;;; The `custom-magic' Widget.
1400 (defgroup custom-magic-faces nil
1401 "Faces used by the magic button."
1402 :group 'custom-faces
1403 :group 'custom-buffer)
1405 (defface custom-invalid-face '((((class color))
1406 (:foreground "yellow" :background "red"))
1408 (:bold t :italic t :underline t)))
1409 "Face used when the customize item is invalid."
1410 :group 'custom-magic-faces)
1412 (defface custom-rogue-face '((((class color))
1413 (:foreground "pink" :background "black"))
1416 "Face used when the customize item is not defined for customization."
1417 :group 'custom-magic-faces)
1419 (defface custom-modified-face '((((class color))
1420 (:foreground "white" :background "blue"))
1423 "Face used when the customize item has been modified."
1424 :group 'custom-magic-faces)
1426 (defface custom-set-face '((((class color))
1427 (:foreground "blue" :background "white"))
1430 "Face used when the customize item has been set."
1431 :group 'custom-magic-faces)
1433 (defface custom-changed-face '((((class color))
1434 (:foreground "white" :background "blue"))
1437 "Face used when the customize item has been changed."
1438 :group 'custom-magic-faces)
1440 (defface custom-saved-face '((t (:underline t)))
1441 "Face used when the customize item has been saved."
1442 :group 'custom-magic-faces)
1444 (defconst custom-magic-alist '((nil "#" underline "\
1445 uninitialized, you should not see this.")
1446 (unknown "?" italic "\
1447 unknown, you should not see this.")
1448 (hidden "-" default "\
1449 hidden, invoke \"Show\" in the previous line to show." "\
1450 group now hidden, invoke \"Show\", above, to show contents.")
1451 (invalid "x" custom-invalid-face "\
1452 the value displayed for this %c is invalid and cannot be set.")
1453 (modified "*" custom-modified-face "\
1454 you have edited the value as text, but you have not set the %c." "\
1455 you have edited something in this group, but not set it.")
1456 (set "+" custom-set-face "\
1457 you have set this %c, but not saved it for future sessions." "\
1458 something in this group has been set, but not saved.")
1459 (changed ":" custom-changed-face "\
1460 this %c has been changed outside the customize buffer." "\
1461 something in this group has been changed outside customize.")
1462 (saved "!" custom-saved-face "\
1463 this %c has been set and saved." "\
1464 something in this group has been set and saved.")
1465 (rogue "@" custom-rogue-face "\
1466 this %c has not been changed with customize." "\
1467 something in this group is not prepared for customization.")
1468 (standard " " nil "\
1469 this %c is unchanged from its standard setting." "\
1470 visible group members are all at standard settings."))
1471 "Alist of customize option states.
1472 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1474 STATE is one of the following symbols:
1477 For internal use, should never occur.
1479 For internal use, should never occur.
1481 This item is not being displayed.
1483 This item is modified, but has an invalid form.
1485 This item is modified, and has a valid form.
1487 This item has been set but not saved.
1489 The current value of this item has been changed temporarily.
1491 This item is marked for saving.
1493 This item has no customization information.
1495 This item is unchanged from the standard setting.
1497 MAGIC is a string used to present that state.
1499 FACE is a face used to present the state.
1501 ITEM-DESC is a string describing the state for options.
1503 GROUP-DESC is a string describing the state for groups. If this is
1504 left out, ITEM-DESC will be used.
1506 The string %c in either description will be replaced with the
1507 category of the item. These are `group'. `option', and `face'.
1509 The list should be sorted most significant first.")
1511 (defcustom custom-magic-show 'long
1512 "If non-nil, show textual description of the state.
1513 If `long', show a full-line description, not just one word."
1514 :type '(choice (const :tag "no" nil)
1516 (other :tag "short" short))
1517 :group 'custom-buffer)
1519 (defcustom custom-magic-show-hidden '(option face)
1520 "Control whether the State button is shown for hidden items.
1521 The value should be a list with the custom categories where the State
1522 button should be visible. Possible categories are `group', `option',
1524 :type '(set (const group) (const option) (const face))
1525 :group 'custom-buffer)
1527 (defcustom custom-magic-show-button nil
1528 "Show a \"magic\" button indicating the state of each customization option."
1530 :group 'custom-buffer)
1532 (define-widget 'custom-magic 'default
1533 "Show and manipulate state for a customization option."
1535 :action 'widget-parent-action
1538 :value-create 'custom-magic-value-create
1539 :value-delete 'widget-children-value-delete)
1541 (defun widget-magic-mouse-down-action (widget &optional event)
1542 ;; Non-nil unless hidden.
1543 (not (eq (widget-get (widget-get (widget-get widget :parent) :parent)
1547 (defun custom-magic-value-create (widget)
1548 ;; Create compact status report for WIDGET.
1549 (let* ((parent (widget-get widget :parent))
1550 (state (widget-get parent :custom-state))
1551 (hidden (eq state 'hidden))
1552 (entry (assq state custom-magic-alist))
1553 (magic (nth 1 entry))
1554 (face (nth 2 entry))
1555 (category (widget-get parent :custom-category))
1556 (text (or (and (eq category 'group)
1559 (form (widget-get parent :custom-form))
1561 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text)
1562 (setq text (concat (match-string 1 text)
1563 (symbol-name category)
1564 (match-string 2 text))))
1565 (when (and custom-magic-show
1567 (memq category custom-magic-show-hidden)))
1569 (when (and (eq category 'group)
1570 (not (and (eq custom-buffer-style 'links)
1571 (> (widget-get parent :custom-level) 1))))
1572 (insert-char ?\ (* custom-buffer-indent
1573 (widget-get parent :custom-level))))
1574 (push (widget-create-child-and-convert
1576 :help-echo "Change the state of this item."
1577 :format (if hidden "%t" "%[%t%]")
1578 :button-prefix 'widget-push-button-prefix
1579 :button-suffix 'widget-push-button-suffix
1580 :mouse-down-action 'widget-magic-mouse-down-action
1584 (let ((start (point)))
1585 (if (eq custom-magic-show 'long)
1587 (insert (symbol-name state)))
1588 (cond ((eq form 'lisp)
1590 ((eq form 'mismatch)
1591 (insert " (mismatch)")))
1592 (put-text-property start (point) 'face 'custom-state-face))
1594 (when (and (eq category 'group)
1595 (not (and (eq custom-buffer-style 'links)
1596 (> (widget-get parent :custom-level) 1))))
1597 (insert-char ?\ (* custom-buffer-indent
1598 (widget-get parent :custom-level))))
1599 (when custom-magic-show-button
1600 (when custom-magic-show
1601 (let ((indent (widget-get parent :indent)))
1603 (insert-char ? indent))))
1604 (push (widget-create-child-and-convert
1606 :mouse-down-action 'widget-magic-mouse-down-action
1610 :help-echo "Change the state."
1611 :format (if hidden "%t" "%[%t%]")
1612 :tag (if (memq form '(lisp mismatch))
1613 (concat "(" magic ")")
1614 (concat "[" magic "]")))
1617 (widget-put widget :children children)))
1619 (defun custom-magic-reset (widget)
1620 "Redraw the :custom-magic property of WIDGET."
1621 (let ((magic (widget-get widget :custom-magic)))
1622 (widget-value-set magic (widget-value magic))))
1624 ;;; The `custom' Widget.
1626 (defface custom-button-face nil
1627 "Face used for buttons in customization buffers."
1628 :group 'custom-faces)
1630 (defface custom-documentation-face nil
1631 "Face used for documentation strings in customization buffers."
1632 :group 'custom-faces)
1634 (defface custom-state-face '((((class color)
1636 (:foreground "lime green"))
1639 (:foreground "dark green"))
1641 "Face used for State descriptions in the customize buffer."
1642 :group 'custom-faces)
1644 (define-widget 'custom 'default
1645 "Customize a user option."
1647 :convert-widget 'custom-convert-widget
1648 :notify 'custom-notify
1651 :custom-state 'hidden
1652 :documentation-property 'widget-subclass-responsibility
1653 :value-create 'widget-subclass-responsibility
1654 :value-delete 'widget-children-value-delete
1655 :value-get 'widget-value-value-get
1656 :validate 'widget-children-validate
1657 :match (lambda (widget value) (symbolp value)))
1659 (defun custom-convert-widget (widget)
1660 ;; Initialize :value and :tag from :args in WIDGET.
1661 (let ((args (widget-get widget :args)))
1663 (widget-put widget :value (widget-apply widget
1664 :value-to-internal (car args)))
1665 (widget-put widget :tag (custom-unlispify-tag-name (car args)))
1666 (widget-put widget :args nil)))
1669 (defun custom-notify (widget &rest args)
1670 "Keep track of changes."
1671 (let ((state (widget-get widget :custom-state)))
1672 (unless (eq state 'modified)
1673 (unless (memq state '(nil unknown hidden))
1674 (widget-put widget :custom-state 'modified))
1675 (custom-magic-reset widget)
1676 (apply 'widget-default-notify widget args))))
1678 (defun custom-redraw (widget)
1679 "Redraw WIDGET with current settings."
1680 (let ((line (count-lines (point-min) (point)))
1681 (column (current-column))
1683 (from (marker-position (widget-get widget :from)))
1684 (to (marker-position (widget-get widget :to))))
1686 (widget-value-set widget (widget-value widget))
1687 (custom-redraw-magic widget))
1688 (when (and (>= pos from) (<= pos to))
1693 (goto-line (1+ line)))
1694 (move-to-column column))
1697 (defun custom-redraw-magic (widget)
1698 "Redraw WIDGET state with current settings."
1700 (let ((magic (widget-get widget :custom-magic)))
1702 (widget-value-set magic (widget-value magic))
1703 (when (setq widget (widget-get widget :group))
1704 (custom-group-state-update widget)))
1706 (setq widget nil)))))
1709 (defun custom-show (widget value)
1710 "Non-nil if WIDGET should be shown with VALUE by default."
1711 (let ((show (widget-get widget :custom-show)))
1717 (funcall show widget value)))))
1719 (defvar custom-load-recursion nil
1720 "Hack to avoid recursive dependencies.")
1722 (defun custom-load-symbol (symbol)
1723 "Load all dependencies for SYMBOL."
1724 (unless custom-load-recursion
1725 (let ((custom-load-recursion t)
1726 (loads (get symbol 'custom-loads))
1729 (setq load (car loads)
1731 (cond ((symbolp load)
1735 ;; Don't reload a file already loaded.
1736 ((and (boundp 'preloaded-file-list)
1737 (member load preloaded-file-list)))
1738 ((assoc load load-history))
1739 ((assoc (locate-library load) load-history))
1742 ;; Without this, we would load cus-edit recursively.
1743 ;; We are still loading it when we call this,
1744 ;; and it is not in load-history yet.
1745 (or (equal load "cus-edit")
1746 (load-library load))
1749 (defun custom-load-widget (widget)
1750 "Load all dependencies for WIDGET."
1751 (custom-load-symbol (widget-value widget)))
1753 (defun custom-unloaded-symbol-p (symbol)
1754 "Return non-nil if the dependencies of SYMBOL has not yet been loaded."
1756 (loads (get symbol 'custom-loads))
1759 (setq load (car loads)
1761 (cond ((symbolp load)
1762 (unless (featurep load)
1764 ((assoc load load-history))
1765 ((assoc (locate-library load) load-history)
1771 (defun custom-unloaded-widget-p (widget)
1772 "Return non-nil if the dependencies of WIDGET has not yet been loaded."
1773 (custom-unloaded-symbol-p (widget-value widget)))
1775 (defun custom-toggle-hide (widget)
1776 "Toggle visibility of WIDGET."
1777 (custom-load-widget widget)
1778 (let ((state (widget-get widget :custom-state)))
1779 (cond ((memq state '(invalid modified))
1780 (error "There are unset changes"))
1782 (widget-put widget :custom-state 'unknown))
1784 (widget-put widget :documentation-shown nil)
1785 (widget-put widget :custom-state 'hidden)))
1786 (custom-redraw widget)
1789 (defun custom-toggle-parent (widget &rest ignore)
1790 "Toggle visibility of parent of WIDGET."
1791 (custom-toggle-hide (widget-get widget :parent)))
1793 (defun custom-add-see-also (widget &optional prefix)
1794 "Add `See also ...' to WIDGET if there are any links.
1795 Insert PREFIX first if non-nil."
1796 (let* ((symbol (widget-get widget :value))
1797 (links (get symbol 'custom-links))
1798 (many (> (length links) 2))
1799 (buttons (widget-get widget :buttons))
1800 (indent (widget-get widget :indent)))
1803 (insert-char ?\ indent))
1806 (insert "See also ")
1808 (push (widget-create-child-and-convert widget (car links))
1810 (setq links (cdr links))
1819 (widget-put widget :buttons buttons))))
1821 (defun custom-add-parent-links (widget &optional initial-string)
1822 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
1823 The value if non-nil if any parents were found.
1824 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
1825 (let ((name (widget-value widget))
1826 (type (widget-type widget))
1827 (buttons (widget-get widget :buttons))
1830 (insert (or initial-string "Parent groups:"))
1831 (mapatoms (lambda (symbol)
1832 (let ((entry (assq name (get symbol 'custom-group))))
1833 (when (eq (nth 1 entry) type)
1835 (push (widget-create-child-and-convert
1836 widget 'custom-group-link
1837 :tag (custom-unlispify-tag-name symbol)
1841 (widget-put widget :buttons buttons)
1844 (delete-region start (point)))
1847 ;;; The `custom-variable' Widget.
1849 (defface custom-variable-tag-face '((((class color)
1851 (:foreground "light blue" :underline t))
1854 (:foreground "blue" :underline t))
1856 "Face used for unpushable variable tags."
1857 :group 'custom-faces)
1859 (defface custom-variable-button-face '((t (:underline t :bold t)))
1860 "Face used for pushable variable tags."
1861 :group 'custom-faces)
1863 (defcustom custom-variable-default-form 'edit
1864 "Default form of displaying variable values."
1865 :type '(choice (const edit)
1867 :group 'custom-buffer
1870 (define-widget 'custom-variable 'custom
1871 "Customize variable."
1873 :help-echo "Set or reset this variable."
1874 :documentation-property 'variable-documentation
1875 :custom-category 'option
1877 :custom-menu 'custom-variable-menu-create
1878 :custom-form nil ; defaults to value of `custom-variable-default-form'
1879 :value-create 'custom-variable-value-create
1880 :action 'custom-variable-action
1881 :custom-set 'custom-variable-set
1882 :custom-save 'custom-variable-save
1883 :custom-reset-current 'custom-redraw
1884 :custom-reset-saved 'custom-variable-reset-saved
1885 :custom-reset-standard 'custom-variable-reset-standard)
1887 (defun custom-variable-type (symbol)
1888 "Return a widget suitable for editing the value of SYMBOL.
1889 If SYMBOL has a `custom-type' property, use that.
1890 Otherwise, look up symbol in `custom-guess-type-alist'."
1891 (let* ((type (or (get symbol 'custom-type)
1892 (and (not (get symbol 'standard-value))
1893 (custom-guess-type symbol))
1895 (options (get symbol 'custom-options))
1896 (tmp (if (listp type)
1897 (copy-sequence type)
1900 (widget-put tmp :options options))
1903 (defun custom-variable-value-create (widget)
1904 "Here is where you edit the variables value."
1905 (custom-load-widget widget)
1906 (unless (widget-get widget :custom-form)
1907 (widget-put widget :custom-form custom-variable-default-form))
1908 (let* ((buttons (widget-get widget :buttons))
1909 (children (widget-get widget :children))
1910 (form (widget-get widget :custom-form))
1911 (state (widget-get widget :custom-state))
1912 (symbol (widget-get widget :value))
1913 (tag (widget-get widget :tag))
1914 (type (custom-variable-type symbol))
1915 (conv (widget-convert type))
1916 (get (or (get symbol 'custom-get) 'default-value))
1917 (prefix (widget-get widget :custom-prefix))
1918 (last (widget-get widget :custom-last))
1919 (value (if (default-boundp symbol)
1920 (funcall get symbol)
1921 (widget-get conv :value))))
1922 ;; If the widget is new, the child determine whether it is hidden.
1924 ((custom-show type value)
1925 (setq state 'unknown))
1927 (setq state 'hidden)))
1928 ;; If we don't know the state, see if we need to edit it in lisp form.
1929 (when (eq state 'unknown)
1930 (unless (widget-apply conv :match value)
1931 ;; (widget-apply (widget-convert type) :match value)
1932 (setq form 'mismatch)))
1933 ;; Now we can create the child widget.
1934 (cond ((eq custom-buffer-style 'tree)
1935 (insert prefix (if last " `--- " " |--- "))
1936 (push (widget-create-child-and-convert
1937 widget 'custom-browse-variable-tag)
1939 (insert " " tag "\n")
1940 (widget-put widget :buttons buttons))
1942 ;; Indicate hidden value.
1943 (push (widget-create-child-and-convert
1946 :sample-face 'custom-variable-tag-face
1950 (push (widget-create-child-and-convert
1952 :help-echo "Show the value of this option."
1953 :action 'custom-toggle-parent
1956 ((memq form '(lisp mismatch))
1957 ;; In lisp mode edit the saved value when possible.
1958 (let* ((value (cond ((get symbol 'saved-value)
1959 (car (get symbol 'saved-value)))
1960 ((get symbol 'standard-value)
1961 (car (get symbol 'standard-value)))
1962 ((default-boundp symbol)
1963 (custom-quote (funcall get symbol)))
1965 (custom-quote (widget-get conv :value))))))
1966 (insert (symbol-name symbol) ": ")
1967 (push (widget-create-child-and-convert
1969 :help-echo "Hide the value of this option."
1970 :action 'custom-toggle-parent
1974 (push (widget-create-child-and-convert
1976 :button-face 'custom-variable-button-face
1978 :tag (symbol-name symbol)
1984 (let* ((format (widget-get type :format))
1985 tag-format value-format)
1986 (unless (string-match ":" format)
1987 (error "Bad format"))
1988 (setq tag-format (substring format 0 (match-end 0)))
1989 (setq value-format (substring format (match-end 0)))
1990 (push (widget-create-child-and-convert
1993 :action 'custom-tag-action
1994 :help-echo "Change value of this option."
1995 :mouse-down-action 'custom-tag-mouse-down-action
1996 :button-face 'custom-variable-button-face
1997 :sample-face 'custom-variable-tag-face
2001 (push (widget-create-child-and-convert
2003 :help-echo "Hide the value of this option."
2004 :action 'custom-toggle-parent
2007 (push (widget-create-child-and-convert
2009 :format value-format
2012 (unless (eq custom-buffer-style 'tree)
2013 ;; Now update the state.
2014 (unless (eq (preceding-char) ?\n)
2015 (widget-insert "\n"))
2016 (if (eq state 'hidden)
2017 (widget-put widget :custom-state state)
2018 (custom-variable-state-set widget))
2019 ;; Create the magic button.
2020 (let ((magic (widget-create-child-and-convert
2021 widget 'custom-magic nil)))
2022 (widget-put widget :custom-magic magic)
2023 (push magic buttons))
2024 ;; Update properties.
2025 (widget-put widget :custom-form form)
2026 (widget-put widget :buttons buttons)
2027 (widget-put widget :children children)
2028 ;; Insert documentation.
2029 (widget-default-format-handler widget ?h)
2031 (unless (eq state 'hidden)
2032 (when (eq (widget-get widget :custom-level) 1)
2033 (custom-add-parent-links widget))
2034 (custom-add-see-also widget)))))
2036 (defun custom-tag-action (widget &rest args)
2037 "Pass :action to first child of WIDGET's parent."
2038 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
2041 (defun custom-tag-mouse-down-action (widget &rest args)
2042 "Pass :mouse-down-action to first child of WIDGET's parent."
2043 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
2044 :mouse-down-action args))
2046 (defun custom-variable-state-set (widget)
2047 "Set the state of WIDGET."
2048 (let* ((symbol (widget-value widget))
2049 (get (or (get symbol 'custom-get) 'default-value))
2050 (value (if (default-boundp symbol)
2051 (funcall get symbol)
2052 (widget-get widget :value)))
2054 (state (cond ((setq tmp (get symbol 'customized-value))
2055 (if (condition-case nil
2056 (equal value (eval (car tmp)))
2060 ((setq tmp (get symbol 'saved-value))
2061 (if (condition-case nil
2062 (equal value (eval (car tmp)))
2066 ((setq tmp (get symbol 'standard-value))
2067 (if (condition-case nil
2068 (equal value (eval (car tmp)))
2073 (widget-put widget :custom-state state)))
2075 (defvar custom-variable-menu
2076 '(("Set for Current Session" custom-variable-set
2078 (eq (widget-get widget :custom-state) 'modified)))
2079 ("Save for Future Sessions" custom-variable-save
2081 (memq (widget-get widget :custom-state) '(modified set changed rogue))))
2082 ("Reset to Current" custom-redraw
2084 (and (default-boundp (widget-value widget))
2085 (memq (widget-get widget :custom-state) '(modified changed)))))
2086 ("Reset to Saved" custom-variable-reset-saved
2088 (and (get (widget-value widget) 'saved-value)
2089 (memq (widget-get widget :custom-state)
2090 '(modified set changed rogue)))))
2091 ("Reset to Standard Settings" custom-variable-reset-standard
2093 (and (get (widget-value widget) 'standard-value)
2094 (memq (widget-get widget :custom-state)
2095 '(modified set changed saved rogue)))))
2096 ("---" ignore ignore)
2097 ("Don't show as Lisp expression" custom-variable-edit
2099 (eq (widget-get widget :custom-form) 'lisp)))
2100 ("Show initial Lisp expression" custom-variable-edit-lisp
2102 (eq (widget-get widget :custom-form) 'edit))))
2103 "Alist of actions for the `custom-variable' widget.
2104 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2105 the menu entry, ACTION is the function to call on the widget when the
2106 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2107 widget as an argument, and returns non-nil if ACTION is valid on that
2108 widget. If FILTER is nil, ACTION is always valid.")
2110 (defun custom-variable-action (widget &optional event)
2111 "Show the menu for `custom-variable' WIDGET.
2112 Optional EVENT is the location for the menu."
2113 (if (eq (widget-get widget :custom-state) 'hidden)
2114 (custom-toggle-hide widget)
2115 (unless (eq (widget-get widget :custom-state) 'modified)
2116 (custom-variable-state-set widget))
2117 (custom-redraw-magic widget)
2118 (let* ((completion-ignore-case t)
2119 (answer (widget-choose (concat "Operation on "
2120 (custom-unlispify-tag-name
2121 (widget-get widget :value)))
2122 (custom-menu-filter custom-variable-menu
2126 (funcall answer widget)))))
2128 (defun custom-variable-edit (widget)
2129 "Edit value of WIDGET."
2130 (widget-put widget :custom-state 'unknown)
2131 (widget-put widget :custom-form 'edit)
2132 (custom-redraw widget))
2134 (defun custom-variable-edit-lisp (widget)
2135 "Edit the lisp representation of the value of WIDGET."
2136 (widget-put widget :custom-state 'unknown)
2137 (widget-put widget :custom-form 'lisp)
2138 (custom-redraw widget))
2140 (defun custom-variable-set (widget)
2141 "Set the current value for the variable being edited by WIDGET."
2142 (let* ((form (widget-get widget :custom-form))
2143 (state (widget-get widget :custom-state))
2144 (child (car (widget-get widget :children)))
2145 (symbol (widget-value widget))
2146 (set (or (get symbol 'custom-set) 'set-default))
2148 (cond ((eq state 'hidden)
2149 (error "Cannot set hidden variable"))
2150 ((setq val (widget-apply child :validate))
2151 (goto-char (widget-get val :from))
2152 (error "%s" (widget-get val :error)))
2153 ((memq form '(lisp mismatch))
2154 (funcall set symbol (eval (setq val (widget-value child))))
2155 (put symbol 'customized-value (list val)))
2157 (funcall set symbol (setq val (widget-value child)))
2158 (put symbol 'customized-value (list (custom-quote val)))))
2159 (custom-variable-state-set widget)
2160 (custom-redraw-magic widget)))
2162 (defun custom-variable-save (widget)
2163 "Set and save the value for the variable being edited by WIDGET."
2164 (let* ((form (widget-get widget :custom-form))
2165 (state (widget-get widget :custom-state))
2166 (child (car (widget-get widget :children)))
2167 (symbol (widget-value widget))
2168 (set (or (get symbol 'custom-set) 'set-default))
2170 (cond ((eq state 'hidden)
2171 (error "Cannot set hidden variable"))
2172 ((setq val (widget-apply child :validate))
2173 (goto-char (widget-get val :from))
2174 (error "%s" (widget-get val :error)))
2175 ((memq form '(lisp mismatch))
2176 (put symbol 'saved-value (list (widget-value child)))
2177 (funcall set symbol (eval (widget-value child))))
2180 'saved-value (list (custom-quote (widget-value
2182 (funcall set symbol (widget-value child))))
2183 (put symbol 'customized-value nil)
2185 (custom-variable-state-set widget)
2186 (custom-redraw-magic widget)))
2188 (defun custom-variable-reset-saved (widget)
2189 "Restore the saved value for the variable being edited by WIDGET."
2190 (let* ((symbol (widget-value widget))
2191 (set (or (get symbol 'custom-set) 'set-default)))
2192 (if (get symbol 'saved-value)
2194 (funcall set symbol (eval (car (get symbol 'saved-value))))
2196 (error "No saved value for %s" symbol))
2197 (put symbol 'customized-value nil)
2198 (widget-put widget :custom-state 'unknown)
2199 (custom-redraw widget)))
2201 (defun custom-variable-reset-standard (widget)
2202 "Restore the standard setting for the variable being edited by WIDGET."
2203 (let* ((symbol (widget-value widget))
2204 (set (or (get symbol 'custom-set) 'set-default)))
2205 (if (get symbol 'standard-value)
2206 (funcall set symbol (eval (car (get symbol 'standard-value))))
2207 (error "No standard setting known for %S" symbol))
2208 (put symbol 'customized-value nil)
2209 (when (get symbol 'saved-value)
2210 (put symbol 'saved-value nil)
2212 (widget-put widget :custom-state 'unknown)
2213 (custom-redraw widget)))
2215 ;;; The `custom-face-edit' Widget.
2217 (define-widget 'custom-face-edit 'checklist
2218 "Edit face attributes."
2222 :button-args '(:help-echo "Control whether this attribute have any effect.")
2223 :args (mapcar (lambda (att)
2226 :sibling-args (widget-get (nth 1 att) :sibling-args)
2227 (list 'const :format "" :value (nth 0 att))
2229 custom-face-attributes))
2231 ;;; The `custom-display' Widget.
2233 (define-widget 'custom-display 'menu-choice
2234 "Select a display type."
2237 :help-echo "Specify frames where the face attributes should be used."
2238 :args '((const :tag "all" t)
2242 :args ((group :sibling-args (:help-echo "\
2243 Only match the specified window systems.")
2244 (const :format "Type: "
2246 (checklist :inline t
2249 :sibling-args (:help-echo "\
2250 The X11 Window System.")
2252 (const :format "PM "
2253 :sibling-args (:help-echo "\
2254 OS/2 Presentation Manager.")
2256 (const :format "W32 "
2257 :sibling-args (:help-echo "\
2260 (const :format "DOS "
2261 :sibling-args (:help-echo "\
2264 (const :format "TTY%n"
2265 :sibling-args (:help-echo "\
2266 Plain text terminals.")
2268 (group :sibling-args (:help-echo "\
2269 Only match the frames with the specified color support.")
2270 (const :format "Class: "
2272 (checklist :inline t
2274 (const :format "Color "
2275 :sibling-args (:help-echo "\
2276 Match color frames.")
2278 (const :format "Grayscale "
2279 :sibling-args (:help-echo "\
2280 Match grayscale frames.")
2282 (const :format "Monochrome%n"
2283 :sibling-args (:help-echo "\
2284 Match frames with no color support.")
2286 (group :sibling-args (:help-echo "\
2287 Only match frames with the specified intensity.")
2289 Background brightness: "
2291 (checklist :inline t
2293 (const :format "Light "
2294 :sibling-args (:help-echo "\
2295 Match frames with light backgrounds.")
2297 (const :format "Dark\n"
2298 :sibling-args (:help-echo "\
2299 Match frames with dark backgrounds.")
2302 ;;; The `custom-face' Widget.
2304 (defface custom-face-tag-face '((t (:underline t)))
2305 "Face used for face tags."
2306 :group 'custom-faces)
2308 (defcustom custom-face-default-form 'selected
2309 "Default form of displaying face definition."
2310 :type '(choice (const all)
2313 :group 'custom-buffer
2316 (define-widget 'custom-face 'custom
2318 :sample-face 'custom-face-tag-face
2319 :help-echo "Set or reset this face."
2320 :documentation-property '(lambda (face)
2321 (face-doc-string face))
2322 :value-create 'custom-face-value-create
2323 :action 'custom-face-action
2324 :custom-category 'face
2325 :custom-form nil ; defaults to value of `custom-face-default-form'
2326 :custom-set 'custom-face-set
2327 :custom-save 'custom-face-save
2328 :custom-reset-current 'custom-redraw
2329 :custom-reset-saved 'custom-face-reset-saved
2330 :custom-reset-standard 'custom-face-reset-standard
2331 :custom-menu 'custom-face-menu-create)
2333 (define-widget 'custom-face-all 'editable-list
2334 "An editable list of display specifications and attributes."
2335 :entry-format "%i %d %v"
2336 :insert-button-args '(:help-echo "Insert new display specification here.")
2337 :append-button-args '(:help-echo "Append new display specification here.")
2338 :delete-button-args '(:help-echo "Delete this display specification.")
2339 :args '((group :format "%v" custom-display custom-face-edit)))
2341 (defconst custom-face-all (widget-convert 'custom-face-all)
2342 "Converted version of the `custom-face-all' widget.")
2344 (define-widget 'custom-display-unselected 'item
2345 "A display specification that doesn't match the selected display."
2346 :match 'custom-display-unselected-match)
2348 (defun custom-display-unselected-match (widget value)
2349 "Non-nil if VALUE is an unselected display specification."
2350 (not (face-spec-set-match-display value (selected-frame))))
2352 (define-widget 'custom-face-selected 'group
2353 "Edit the attributes of the selected display in a face specification."
2354 :args '((repeat :format ""
2356 (group custom-display-unselected sexp))
2357 (group (sexp :format "") custom-face-edit)
2362 (defconst custom-face-selected (widget-convert 'custom-face-selected)
2363 "Converted version of the `custom-face-selected' widget.")
2365 (defun custom-face-value-create (widget)
2366 "Create a list of the display specifications for WIDGET."
2367 (let ((buttons (widget-get widget :buttons))
2368 (symbol (widget-get widget :value))
2369 (tag (widget-get widget :tag))
2370 (state (widget-get widget :custom-state))
2372 (is-last (widget-get widget :custom-last))
2373 (prefix (widget-get widget :custom-prefix)))
2375 (setq tag (prin1-to-string symbol)))
2376 (cond ((eq custom-buffer-style 'tree)
2377 (insert prefix (if is-last " `--- " " |--- "))
2378 (push (widget-create-child-and-convert
2379 widget 'custom-browse-face-tag)
2381 (insert " " tag "\n")
2382 (widget-put widget :buttons buttons))
2386 (if (eq custom-buffer-style 'face)
2388 (widget-specify-sample widget begin (point))
2391 (and (string-match "XEmacs" emacs-version)
2392 ;; XEmacs cannot display uninitialized faces.
2393 (not (custom-facep symbol))
2394 (copy-face 'custom-face-empty symbol))
2395 (push (widget-create-child-and-convert widget 'item
2402 (push (widget-create-child-and-convert
2404 :help-echo "Hide or show this face."
2405 :action 'custom-toggle-parent
2406 (not (eq state 'hidden)))
2410 (let ((magic (widget-create-child-and-convert
2411 widget 'custom-magic nil)))
2412 (widget-put widget :custom-magic magic)
2413 (push magic buttons))
2415 (widget-put widget :buttons buttons)
2416 ;; Insert documentation.
2417 (widget-default-format-handler widget ?h)
2419 (unless (eq state 'hidden)
2420 (when (eq (widget-get widget :custom-level) 1)
2421 (custom-add-parent-links widget))
2422 (custom-add-see-also widget))
2424 (unless (eq (preceding-char) ?\n)
2426 (unless (eq state 'hidden)
2427 (message "Creating face editor...")
2428 (custom-load-widget widget)
2429 (unless (widget-get widget :custom-form)
2430 (widget-put widget :custom-form custom-face-default-form))
2431 (let* ((symbol (widget-value widget))
2432 (spec (or (get symbol 'saved-face)
2433 (get symbol 'face-defface-spec)
2434 ;; Attempt to construct it.
2435 (list (list t (custom-face-attributes-get
2436 symbol (selected-frame))))))
2437 (form (widget-get widget :custom-form))
2438 (indent (widget-get widget :indent))
2440 ;; If the user has changed this face in some other way,
2441 ;; edit it as the user has specified it.
2442 (if (not (face-spec-match-p symbol spec (selected-frame)))
2443 (setq spec (list (list t (face-attr-construct symbol (selected-frame))))))
2444 (setq edit (widget-create-child-and-convert
2446 (cond ((and (eq form 'selected)
2447 (widget-apply custom-face-selected
2449 (when indent (insert-char ?\ indent))
2450 'custom-face-selected)
2451 ((and (not (eq form 'lisp))
2452 (widget-apply custom-face-all
2456 (when indent (insert-char ?\ indent))
2459 (custom-face-state-set widget)
2460 (widget-put widget :children (list edit)))
2461 (message "Creating face editor...done"))))))
2463 (defvar custom-face-menu
2464 '(("Set for Current Session" custom-face-set)
2465 ("Save for Future Sessions" custom-face-save-command)
2466 ("Reset to Saved" custom-face-reset-saved
2468 (get (widget-value widget) 'saved-face)))
2469 ("Reset to Standard Setting" custom-face-reset-standard
2471 (get (widget-value widget) 'face-defface-spec)))
2472 ("---" ignore ignore)
2473 ("Show all display specs" custom-face-edit-all
2475 (not (eq (widget-get widget :custom-form) 'all))))
2476 ("Just current attributes" custom-face-edit-selected
2478 (not (eq (widget-get widget :custom-form) 'selected))))
2479 ("Show as Lisp expression" custom-face-edit-lisp
2481 (not (eq (widget-get widget :custom-form) 'lisp)))))
2482 "Alist of actions for the `custom-face' widget.
2483 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2484 the menu entry, ACTION is the function to call on the widget when the
2485 menu is selected, and FILTER is a predicate which takes a `custom-face'
2486 widget as an argument, and returns non-nil if ACTION is valid on that
2487 widget. If FILTER is nil, ACTION is always valid.")
2489 (defun custom-face-edit-selected (widget)
2490 "Edit selected attributes of the value of WIDGET."
2491 (widget-put widget :custom-state 'unknown)
2492 (widget-put widget :custom-form 'selected)
2493 (custom-redraw widget))
2495 (defun custom-face-edit-all (widget)
2496 "Edit all attributes of the value of WIDGET."
2497 (widget-put widget :custom-state 'unknown)
2498 (widget-put widget :custom-form 'all)
2499 (custom-redraw widget))
2501 (defun custom-face-edit-lisp (widget)
2502 "Edit the lisp representation of the value of WIDGET."
2503 (widget-put widget :custom-state 'unknown)
2504 (widget-put widget :custom-form 'lisp)
2505 (custom-redraw widget))
2507 (defun custom-face-state-set (widget)
2508 "Set the state of WIDGET."
2509 (let ((symbol (widget-value widget)))
2510 (widget-put widget :custom-state (cond ((get symbol 'customized-face)
2512 ((get symbol 'saved-face)
2514 ((get symbol 'face-defface-spec)
2519 (defun custom-face-action (widget &optional event)
2520 "Show the menu for `custom-face' WIDGET.
2521 Optional EVENT is the location for the menu."
2522 (if (eq (widget-get widget :custom-state) 'hidden)
2523 (custom-toggle-hide widget)
2524 (let* ((completion-ignore-case t)
2525 (symbol (widget-get widget :value))
2526 (answer (widget-choose (concat "Operation on "
2527 (custom-unlispify-tag-name symbol))
2528 (custom-menu-filter custom-face-menu
2532 (funcall answer widget)))))
2534 (defun custom-face-set (widget)
2535 "Make the face attributes in WIDGET take effect."
2536 (let* ((symbol (widget-value widget))
2537 (child (car (widget-get widget :children)))
2538 (value (widget-value child)))
2539 (put symbol 'customized-face value)
2540 (face-spec-set symbol value)
2541 (custom-face-state-set widget)
2542 (custom-redraw-magic widget)))
2544 (defun custom-face-save-command (widget)
2545 "Save in `.emacs' the face attributes in WIDGET."
2546 (custom-face-save widget)
2549 (defun custom-face-save (widget)
2550 "Prepare for saving WIDGET's face attributes, but don't write `.emacs'."
2551 (let* ((symbol (widget-value widget))
2552 (child (car (widget-get widget :children)))
2553 (value (widget-value child)))
2554 (face-spec-set symbol value)
2555 (put symbol 'saved-face value)
2556 (put symbol 'customized-face nil)
2558 (custom-face-state-set widget)
2559 (custom-redraw-magic widget)))
2561 (defun custom-face-reset-saved (widget)
2562 "Restore WIDGET to the face's default attributes."
2563 (let* ((symbol (widget-value widget))
2564 (child (car (widget-get widget :children)))
2565 (value (get symbol 'saved-face)))
2567 (error "No saved value for this face"))
2568 (put symbol 'customized-face nil)
2569 (face-spec-set symbol value)
2570 (widget-value-set child value)
2571 (custom-face-state-set widget)
2572 (custom-redraw-magic widget)))
2574 (defun custom-face-reset-standard (widget)
2575 "Restore WIDGET to the face's standard settings."
2576 (let* ((symbol (widget-value widget))
2577 (child (car (widget-get widget :children)))
2578 (value (get symbol 'face-defface-spec)))
2580 (error "No standard setting for this face"))
2581 (put symbol 'customized-face nil)
2582 (when (get symbol 'saved-face)
2583 (put symbol 'saved-face nil)
2585 (face-spec-set symbol value)
2586 (widget-value-set child value)
2587 (custom-face-state-set widget)
2588 (custom-redraw-magic widget)))
2590 ;;; The `face' Widget.
2592 (define-widget 'face 'default
2593 "Select and customize a face."
2594 :convert-widget 'widget-value-convert-widget
2595 :button-prefix 'widget-push-button-prefix
2596 :button-suffix 'widget-push-button-suffix
2597 :format "%t: %[select face%] %v"
2600 :value-create 'widget-face-value-create
2601 :value-delete 'widget-face-value-delete
2602 :value-get 'widget-value-value-get
2603 :validate 'widget-children-validate
2604 :action 'widget-face-action
2605 :match '(lambda (widget value) (symbolp value)))
2607 (defun widget-face-value-create (widget)
2608 ;; Create a `custom-face' child.
2609 (let* ((symbol (widget-value widget))
2610 (custom-buffer-style 'face)
2611 (child (widget-create-child-and-convert
2615 (custom-magic-reset child)
2616 (setq custom-options (cons child custom-options))
2617 (widget-put widget :children (list child))))
2619 (defun widget-face-value-delete (widget)
2620 ;; Remove the child from the options.
2621 (let ((child (car (widget-get widget :children))))
2622 (setq custom-options (delq child custom-options))
2623 (widget-children-value-delete widget)))
2625 (defvar face-history nil
2626 "History of entered face names.")
2628 (defun widget-face-action (widget &optional event)
2629 "Prompt for a face."
2630 (let ((answer (completing-read "Face: "
2631 (mapcar (lambda (face)
2632 (list (symbol-name face)))
2636 (unless (zerop (length answer))
2637 (widget-value-set widget (intern answer))
2638 (widget-apply widget :notify widget event)
2641 ;;; The `hook' Widget.
2643 (define-widget 'hook 'list
2645 :value-to-internal (lambda (widget value)
2646 (if (and value (symbolp value))
2649 :match (lambda (widget value)
2651 (widget-group-match widget value)))
2652 :convert-widget 'custom-hook-convert-widget
2655 (defun custom-hook-convert-widget (widget)
2656 ;; Handle `:custom-options'.
2657 (let* ((options (widget-get widget :options))
2658 (other `(editable-list :inline t
2659 :entry-format "%i %d%v"
2660 (function :format " %v")))
2662 (list `(checklist :inline t
2663 ,@(mapcar (lambda (entry)
2664 `(function-item ,entry))
2668 (widget-put widget :args args)
2671 ;;; The `custom-group-link' Widget.
2673 (define-widget 'custom-group-link 'link
2674 "Show parent in other window when activated."
2675 :help-echo "Create customization buffer for this group."
2676 :action 'custom-group-link-action)
2678 (defun custom-group-link-action (widget &rest ignore)
2679 (customize-group (widget-value widget)))
2681 ;;; The `custom-group' Widget.
2683 (defcustom custom-group-tag-faces nil
2684 ;; In XEmacs, this ought to play games with font size.
2685 "Face used for group tags.
2686 The first member is used for level 1 groups, the second for level 2,
2687 and so forth. The remaining group tags are shown with
2688 `custom-group-tag-face'."
2689 :type '(repeat face)
2690 :group 'custom-faces)
2692 (defface custom-group-tag-face-1 '((((class color)
2694 (:foreground "pink" :underline t))
2697 (:foreground "red" :underline t))
2699 "Face used for group tags.")
2701 (defface custom-group-tag-face '((((class color)
2703 (:foreground "light blue" :underline t))
2706 (:foreground "blue" :underline t))
2708 "Face used for low level group tags."
2709 :group 'custom-faces)
2711 (define-widget 'custom-group 'custom
2714 :sample-face-get 'custom-group-sample-face-get
2715 :documentation-property 'group-documentation
2716 :help-echo "Set or reset all members of this group."
2717 :value-create 'custom-group-value-create
2718 :action 'custom-group-action
2719 :custom-category 'group
2720 :custom-set 'custom-group-set
2721 :custom-save 'custom-group-save
2722 :custom-reset-current 'custom-group-reset-current
2723 :custom-reset-saved 'custom-group-reset-saved
2724 :custom-reset-standard 'custom-group-reset-standard
2725 :custom-menu 'custom-group-menu-create)
2727 (defun custom-group-sample-face-get (widget)
2728 ;; Use :sample-face.
2729 (or (nth (1- (widget-get widget :custom-level)) custom-group-tag-faces)
2730 'custom-group-tag-face))
2732 (define-widget 'custom-group-visibility 'visibility
2733 "An indicator and manipulator for hidden group contents."
2734 :create 'custom-group-visibility-create)
2736 (defun custom-group-visibility-create (widget)
2737 (let ((visible (widget-value widget)))
2739 (insert "--------")))
2740 (widget-default-create widget))
2742 (defun custom-group-members (symbol groups-only)
2743 "Return SYMBOL's custom group members.
2744 If GROUPS-ONLY non-nil, return only those members that are groups."
2745 (if (not groups-only)
2746 (get symbol 'custom-group)
2748 (dolist (entry (get symbol 'custom-group))
2749 (when (eq (nth 1 entry) 'custom-group)
2750 (push entry members)))
2751 (nreverse members))))
2753 (defun custom-group-value-create (widget)
2754 "Insert a customize group for WIDGET in the current buffer."
2755 (let* ((state (widget-get widget :custom-state))
2756 (level (widget-get widget :custom-level))
2757 ;; (indent (widget-get widget :indent))
2758 (prefix (widget-get widget :custom-prefix))
2759 (buttons (widget-get widget :buttons))
2760 (tag (widget-get widget :tag))
2761 (symbol (widget-value widget))
2762 (members (custom-group-members symbol
2763 (and (eq custom-buffer-style 'tree)
2764 custom-browse-only-groups))))
2765 (cond ((and (eq custom-buffer-style 'tree)
2767 (or members (custom-unloaded-widget-p widget)))
2768 (custom-browse-insert-prefix prefix)
2769 (push (widget-create-child-and-convert
2770 widget 'custom-browse-visibility
2771 ;; :tag-glyph "plus"
2775 ;; (widget-glyph-insert nil "-- " "horizontal")
2776 (push (widget-create-child-and-convert
2777 widget 'custom-browse-group-tag)
2779 (insert " " tag "\n")
2780 (widget-put widget :buttons buttons))
2781 ((and (eq custom-buffer-style 'tree)
2782 (zerop (length members)))
2783 (custom-browse-insert-prefix prefix)
2785 ;; (widget-glyph-insert nil "[ ]" "empty")
2786 ;; (widget-glyph-insert nil "-- " "horizontal")
2787 (push (widget-create-child-and-convert
2788 widget 'custom-browse-group-tag)
2790 (insert " " tag "\n")
2791 (widget-put widget :buttons buttons))
2792 ((eq custom-buffer-style 'tree)
2793 (custom-browse-insert-prefix prefix)
2794 (custom-load-widget widget)
2795 (if (zerop (length members))
2797 (custom-browse-insert-prefix prefix)
2799 ;; (widget-glyph-insert nil "[ ]" "empty")
2800 ;; (widget-glyph-insert nil "-- " "horizontal")
2801 (push (widget-create-child-and-convert
2802 widget 'custom-browse-group-tag)
2804 (insert " " tag "\n")
2805 (widget-put widget :buttons buttons))
2806 (push (widget-create-child-and-convert
2807 widget 'custom-browse-visibility
2808 ;; :tag-glyph "minus"
2812 ;; (widget-glyph-insert nil "-\\ " "top")
2813 (push (widget-create-child-and-convert
2814 widget 'custom-browse-group-tag)
2816 (insert " " tag "\n")
2817 (widget-put widget :buttons buttons)
2818 (message "Creating group...")
2819 (let* ((members (custom-sort-items members
2820 custom-browse-sort-alphabetically
2821 custom-browse-order-groups))
2822 (prefixes (widget-get widget :custom-prefixes))
2823 (custom-prefix-list (custom-prefix-add symbol prefixes))
2824 (extra-prefix (if (widget-get widget :custom-last)
2827 (prefix (concat prefix extra-prefix))
2830 (setq entry (car members)
2831 members (cdr members))
2832 (push (widget-create-child-and-convert
2833 widget (nth 1 entry)
2835 :tag (custom-unlispify-tag-name (nth 0 entry))
2836 :custom-prefixes custom-prefix-list
2837 :custom-level (1+ level)
2838 :custom-last (null members)
2839 :value (nth 0 entry)
2840 :custom-prefix prefix)
2842 (widget-put widget :children (reverse children)))
2843 (message "Creating group...done")))
2846 ;; Create level indicator.
2847 (unless (eq custom-buffer-style 'links)
2848 (insert-char ?\ (* custom-buffer-indent (1- level)))
2851 (let ((begin (point)))
2853 (widget-specify-sample widget begin (point)))
2855 ;; Create link/visibility indicator.
2856 (if (eq custom-buffer-style 'links)
2857 (push (widget-create-child-and-convert
2858 widget 'custom-group-link
2862 (push (widget-create-child-and-convert
2863 widget 'custom-group-visibility
2864 :help-echo "Show members of this group."
2865 :action 'custom-toggle-parent
2866 (not (eq state 'hidden)))
2869 ;; Create magic button.
2870 (let ((magic (widget-create-child-and-convert
2871 widget 'custom-magic nil)))
2872 (widget-put widget :custom-magic magic)
2873 (push magic buttons))
2875 (widget-put widget :buttons buttons)
2876 ;; Insert documentation.
2877 (if (and (eq custom-buffer-style 'links) (> level 1))
2878 (widget-put widget :documentation-indent 0))
2879 (widget-default-format-handler widget ?h))
2882 ;; Add parent groups references above the group.
2883 (if t ;;; This should test that the buffer
2884 ;;; was made to display a group.
2886 (if (custom-add-parent-links widget
2887 "Go to parent group:")
2889 ;; Create level indicator.
2890 (insert-char ?\ (* custom-buffer-indent (1- level)))
2893 (let ((start (point)))
2895 (widget-specify-sample widget start (point)))
2897 ;; Create visibility indicator.
2898 (unless (eq custom-buffer-style 'links)
2900 (push (widget-create-child-and-convert
2902 :help-echo "Hide members of this group."
2903 :action 'custom-toggle-parent
2904 (not (eq state 'hidden)))
2907 ;; Create more dashes.
2908 ;; Use 76 instead of 75 to compensate for the temporary "<"
2909 ;; added by `widget-insert'.
2910 (insert-char ?- (- 76 (current-column)
2911 (* custom-buffer-indent level)))
2913 ;; Create magic button.
2914 (let ((magic (widget-create-child-and-convert
2915 widget 'custom-magic
2918 (widget-put widget :custom-magic magic)
2919 (push magic buttons))
2921 (widget-put widget :buttons buttons)
2922 ;; Insert documentation.
2923 (widget-default-format-handler widget ?h)
2925 (if nil ;;; This should test that the buffer
2926 ;;; was not made to display a group.
2928 (insert-char ?\ custom-buffer-indent)
2929 (custom-add-parent-links widget)))
2930 (custom-add-see-also widget
2931 (make-string (* custom-buffer-indent level)
2934 (message "Creating group...")
2935 (custom-load-widget widget)
2936 (let* ((members (custom-sort-items members
2937 custom-buffer-sort-alphabetically
2938 custom-buffer-order-groups))
2939 (prefixes (widget-get widget :custom-prefixes))
2940 (custom-prefix-list (custom-prefix-add symbol prefixes))
2941 (length (length members))
2943 (children (mapcar (lambda (entry)
2944 (widget-insert "\n")
2946 Creating group members... %2d%%"
2947 (/ (* 100.0 count) length))
2948 (setq count (1+ count))
2950 (widget-create-child-and-convert
2951 widget (nth 1 entry)
2953 :tag (custom-unlispify-tag-name
2955 :custom-prefixes custom-prefix-list
2956 :custom-level (1+ level)
2957 :value (nth 0 entry))
2958 (unless (eq (preceding-char) ?\n)
2959 (widget-insert "\n"))))
2961 (message "Creating group magic...")
2962 (mapcar 'custom-magic-reset children)
2963 (message "Creating group state...")
2964 (widget-put widget :children children)
2965 (custom-group-state-update widget)
2966 (message "Creating group... done"))
2969 (insert-char ?\ (* custom-buffer-indent (1- level)))
2970 (insert "\\- " (widget-get widget :tag) " group end ")
2971 (insert-char ?- (- 75 (current-column) (* custom-buffer-indent level)))
2974 (defvar custom-group-menu
2975 '(("Set for Current Session" custom-group-set
2977 (eq (widget-get widget :custom-state) 'modified)))
2978 ("Save for Future Sessions" custom-group-save
2980 (memq (widget-get widget :custom-state) '(modified set))))
2981 ("Reset to Current" custom-group-reset-current
2983 (memq (widget-get widget :custom-state) '(modified))))
2984 ("Reset to Saved" custom-group-reset-saved
2986 (memq (widget-get widget :custom-state) '(modified set))))
2987 ("Reset to standard setting" custom-group-reset-standard
2989 (memq (widget-get widget :custom-state) '(modified set saved)))))
2990 "Alist of actions for the `custom-group' widget.
2991 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2992 the menu entry, ACTION is the function to call on the widget when the
2993 menu is selected, and FILTER is a predicate which takes a `custom-group'
2994 widget as an argument, and returns non-nil if ACTION is valid on that
2995 widget. If FILTER is nil, ACTION is always valid.")
2997 (defun custom-group-action (widget &optional event)
2998 "Show the menu for `custom-group' WIDGET.
2999 Optional EVENT is the location for the menu."
3000 (if (eq (widget-get widget :custom-state) 'hidden)
3001 (custom-toggle-hide widget)
3002 (let* ((completion-ignore-case t)
3003 (answer (widget-choose (concat "Operation on "
3004 (custom-unlispify-tag-name
3005 (widget-get widget :value)))
3006 (custom-menu-filter custom-group-menu
3010 (funcall answer widget)))))
3012 (defun custom-group-set (widget)
3013 "Set changes in all modified group members."
3014 (let ((children (widget-get widget :children)))
3015 (mapcar (lambda (child)
3016 (when (eq (widget-get child :custom-state) 'modified)
3017 (widget-apply child :custom-set)))
3020 (defun custom-group-save (widget)
3021 "Save all modified group members."
3022 (let ((children (widget-get widget :children)))
3023 (mapcar (lambda (child)
3024 (when (memq (widget-get child :custom-state) '(modified set))
3025 (widget-apply child :custom-save)))
3028 (defun custom-group-reset-current (widget)
3029 "Reset all modified group members."
3030 (let ((children (widget-get widget :children)))
3031 (mapcar (lambda (child)
3032 (when (eq (widget-get child :custom-state) 'modified)
3033 (widget-apply child :custom-reset-current)))
3036 (defun custom-group-reset-saved (widget)
3037 "Reset all modified or set group members."
3038 (let ((children (widget-get widget :children)))
3039 (mapcar (lambda (child)
3040 (when (memq (widget-get child :custom-state) '(modified set))
3041 (widget-apply child :custom-reset-saved)))
3044 (defun custom-group-reset-standard (widget)
3045 "Reset all modified, set, or saved group members."
3046 (let ((children (widget-get widget :children)))
3047 (mapcar (lambda (child)
3048 (when (memq (widget-get child :custom-state)
3049 '(modified set saved))
3050 (widget-apply child :custom-reset-standard)))
3053 (defun custom-group-state-update (widget)
3055 (unless (eq (widget-get widget :custom-state) 'hidden)
3056 (let* ((children (widget-get widget :children))
3057 (states (mapcar (lambda (child)
3058 (widget-get child :custom-state))
3060 (magics custom-magic-alist)
3063 (let ((magic (car (car magics))))
3064 (if (and (not (eq magic 'hidden))
3065 (memq magic states))
3068 (setq magics (cdr magics)))))
3069 (widget-put widget :custom-state found)))
3070 (custom-magic-reset widget))
3072 ;;; The `custom-save-all' Function.
3074 (defcustom custom-file nil
3075 "File used for storing customization information.
3076 The default is nil, which means to use your init file
3077 as specified by `user-init-file'. If you specify some other file,
3078 you need to explicitly load that file for the settings to take effect."
3079 :type '(choice (const :tag "Your Emacs init file" nil) file)
3082 (defun custom-file ()
3083 "Return the file name for saving customizations."
3087 (read-file-name "File for customizations: "
3088 "~/" nil nil ".emacs"))))
3090 (defun custom-save-delete (symbol)
3091 "Delete the call to SYMBOL from `custom-file'.
3092 Leave point at the location of the call, or after the last expression."
3093 (let ((default-major-mode))
3094 (set-buffer (find-file-noselect (custom-file))))
3095 (goto-char (point-min))
3098 (let ((sexp (condition-case nil
3099 (read (current-buffer))
3100 (end-of-file (throw 'found nil)))))
3101 (when (and (listp sexp)
3102 (eq (car sexp) symbol))
3103 (delete-region (save-excursion
3107 (throw 'found nil))))))
3109 (defun custom-save-variables ()
3110 "Save all customized variables in `custom-file'."
3112 (custom-save-delete 'custom-set-variables)
3113 (let ((standard-output (current-buffer)))
3116 (princ "(custom-set-variables")
3117 (mapatoms (lambda (symbol)
3118 (let ((value (get symbol 'saved-value))
3119 (requests (get symbol 'custom-requests))
3120 (now (not (or (get symbol 'standard-value)
3121 (and (not (boundp symbol))
3122 (not (get symbol 'force-value)))))))
3139 (unless (looking-at "\n")
3142 (defun custom-save-faces ()
3143 "Save all customized faces in `custom-file'."
3145 (custom-save-delete 'custom-set-faces)
3146 (let ((standard-output (current-buffer)))
3149 (princ "(custom-set-faces")
3150 (let ((value (get 'default 'saved-face)))
3151 ;; The default face must be first, since it affects the others.
3153 (princ "\n '(default ")
3155 (if (or (get 'default 'face-defface-spec)
3156 (and (not (custom-facep 'default))
3157 (not (get 'default 'force-face))))
3160 (mapatoms (lambda (symbol)
3161 (let ((value (get symbol 'saved-face)))
3162 (when (and (not (eq symbol 'default))
3163 ;; Don't print default face here.
3169 (if (or (get symbol 'face-defface-spec)
3170 (and (not (custom-facep symbol))
3171 (not (get symbol 'force-face))))
3175 (unless (looking-at "\n")
3179 (defun customize-save-customized ()
3180 "Save all user options which have been set in this session."
3182 (mapatoms (lambda (symbol)
3183 (let ((face (get symbol 'customized-face))
3184 (value (get symbol 'customized-value)))
3186 (put symbol 'saved-face face)
3187 (put symbol 'customized-face nil))
3189 (put symbol 'saved-value value)
3190 (put symbol 'customized-value nil)))))
3191 ;; We really should update all custom buffers here.
3195 (defun custom-save-all ()
3196 "Save all customizations in `custom-file'."
3197 (let ((inhibit-read-only t))
3198 (custom-save-variables)
3201 (let ((default-major-mode nil))
3202 (set-buffer (find-file-noselect (custom-file))))
3205 ;;; The Customize Menu.
3209 (defcustom custom-menu-nesting 2
3210 "Maximum nesting in custom menus."
3212 :group 'custom-menu)
3214 (defun custom-face-menu-create (widget symbol)
3215 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
3216 (vector (custom-unlispify-menu-entry symbol)
3217 `(customize-face ',symbol)
3220 (defun custom-variable-menu-create (widget symbol)
3221 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
3222 (let ((type (get symbol 'custom-type)))
3223 (unless (listp type)
3224 (setq type (list type)))
3225 (if (and type (widget-get type :custom-menu))
3226 (widget-apply type :custom-menu symbol)
3227 (vector (custom-unlispify-menu-entry symbol)
3228 `(customize-variable ',symbol)
3231 ;; Add checkboxes to boolean variable entries.
3232 (widget-put (get 'boolean 'widget-type)
3233 :custom-menu (lambda (widget symbol)
3234 (vector (custom-unlispify-menu-entry symbol)
3235 `(customize-variable ',symbol)
3237 ':selected symbol)))
3239 (if (string-match "XEmacs" emacs-version)
3240 ;; XEmacs can create menus dynamically.
3241 (defun custom-group-menu-create (widget symbol)
3242 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
3243 `( ,(custom-unlispify-menu-entry symbol t)
3244 :filter (lambda (&rest junk)
3245 (cdr (custom-menu-create ',symbol)))))
3247 (defun custom-group-menu-create (widget symbol)
3248 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
3249 ;; Limit the nesting.
3250 (let ((custom-menu-nesting (1- custom-menu-nesting)))
3251 (custom-menu-create symbol))))
3254 (defun custom-menu-create (symbol)
3255 "Create menu for customization group SYMBOL.
3256 The menu is in a format applicable to `easy-menu-define'."
3257 (let* ((item (vector (custom-unlispify-menu-entry symbol)
3258 `(customize-group ',symbol)
3260 (if (and (or (not (boundp 'custom-menu-nesting))
3261 (>= custom-menu-nesting 0))
3262 (< (length (get symbol 'custom-group)) widget-menu-max-size))
3263 (let ((custom-prefix-list (custom-prefix-add symbol
3264 custom-prefix-list))
3265 (members (custom-sort-items (get symbol 'custom-group)
3266 custom-menu-sort-alphabetically
3267 custom-menu-order-groups)))
3268 (custom-load-symbol symbol)
3269 `(,(custom-unlispify-menu-entry symbol t)
3272 ,@(mapcar (lambda (entry)
3273 (widget-apply (if (listp (nth 1 entry))
3275 (list (nth 1 entry)))
3276 :custom-menu (nth 0 entry)))
3281 (defun customize-menu-create (symbol &optional name)
3282 "Return a customize menu for customization group SYMBOL.
3283 If optional NAME is given, use that as the name of the menu.
3284 Otherwise the menu will be named `Customize'.
3285 The format is suitable for use with `easy-menu-define'."
3287 (setq name "Customize"))
3288 (if (string-match "XEmacs" emacs-version)
3289 ;; We can delay it under XEmacs.
3291 :filter (lambda (&rest junk)
3292 (cdr (custom-menu-create ',symbol))))
3293 ;; But we must create it now under Emacs.
3294 (cons name (cdr (custom-menu-create symbol)))))
3296 ;;; The Custom Mode.
3298 (defvar custom-mode-map nil
3299 "Keymap for `custom-mode'.")
3301 (unless custom-mode-map
3302 (setq custom-mode-map (make-sparse-keymap))
3303 (set-keymap-parent custom-mode-map widget-keymap)
3304 (suppress-keymap custom-mode-map)
3305 (define-key custom-mode-map " " 'scroll-up)
3306 (define-key custom-mode-map "\177" 'scroll-down)
3307 (define-key custom-mode-map "q" 'bury-buffer)
3308 (define-key custom-mode-map "u" 'Custom-goto-parent)
3309 (define-key custom-mode-map "n" 'widget-forward)
3310 (define-key custom-mode-map "p" 'widget-backward)
3311 (define-key custom-mode-map [mouse-1] 'Custom-move-and-invoke))
3313 (defun Custom-move-and-invoke (event)
3314 "Move to where you click, and if it is an active field, invoke it."
3316 (mouse-set-point event)
3317 (if (widget-event-point event)
3318 (let* ((pos (widget-event-point event))
3319 (button (get-char-property pos 'button)))
3321 (widget-button-click event)))))
3323 (easy-menu-define Custom-mode-menu
3325 "Menu used in customization buffers."
3327 ,(customize-menu-create 'customize)
3328 ["Set" Custom-set t]
3329 ["Save" Custom-save t]
3330 ["Reset to Current" Custom-reset-current t]
3331 ["Reset to Saved" Custom-reset-saved t]
3332 ["Reset to Standard Settings" Custom-reset-standard t]
3333 ["Info" (Info-goto-node "(custom)The Customization Buffer") t]))
3335 (defun Custom-goto-parent ()
3336 "Go to the parent group listed at the top of this buffer.
3337 If several parents are listed, go to the first of them."
3340 (goto-char (point-min))
3341 (if (search-forward "\nGo to parent group: " nil t)
3342 (let* ((button (get-char-property (point) 'button))
3343 (parent (downcase (widget-get button :tag))))
3344 (customize-group parent)))))
3346 (defcustom custom-mode-hook nil
3347 "Hook called when entering custom-mode."
3349 :group 'custom-buffer )
3351 (defun custom-state-buffer-message (widget)
3352 (if (eq (widget-get (widget-get widget :parent) :custom-state) 'modified)
3353 (message "To install your edits, invoke [State] and choose the Set operation")))
3355 (defun custom-mode ()
3356 "Major mode for editing customization buffers.
3358 The following commands are available:
3360 Move to next button or editable field. \\[widget-forward]
3361 Move to previous button or editable field. \\[widget-backward]
3362 \\<widget-field-keymap>\
3363 Complete content of editable text field. \\[widget-complete]
3364 \\<custom-mode-map>\
3365 Invoke button under the mouse pointer. \\[Custom-move-and-invoke]
3366 Invoke button under point. \\[widget-button-press]
3367 Set all modifications. \\[Custom-set]
3368 Make all modifications default. \\[Custom-save]
3369 Reset all modified options. \\[Custom-reset-current]
3370 Reset all modified or set options. \\[Custom-reset-saved]
3371 Reset all options. \\[Custom-reset-standard]
3373 Entry to this mode calls the value of `custom-mode-hook'
3374 if that value is non-nil."
3375 (kill-all-local-variables)
3376 (setq major-mode 'custom-mode
3378 (use-local-map custom-mode-map)
3379 (easy-menu-add Custom-mode-menu)
3380 (make-local-variable 'custom-options)
3381 (make-local-variable 'widget-documentation-face)
3382 (setq widget-documentation-face 'custom-documentation-face)
3383 (make-local-variable 'widget-button-face)
3384 (setq widget-button-face 'custom-button-face)
3385 (make-local-hook 'widget-edit-functions)
3386 (add-hook 'widget-edit-functions 'custom-state-buffer-message nil t)
3387 (run-hooks 'custom-mode-hook))
3393 ;; cus-edit.el ends here