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 programming nil
110 "Support for programming in other languages."
113 (defgroup languages nil
114 "Specialized modes for editing programming languages."
118 "Lisp support, including Emacs Lisp."
123 "Support for the C language and related languages."
131 "Support for object-oriented programming."
134 (defgroup applications nil
135 "Applications written in Emacs."
138 (defgroup calendar nil
139 "Calendar and time management support."
140 :group 'applications)
143 "Modes for electronic-mail handling."
144 :group 'applications)
147 "Support for netnews reading and posting."
148 :group 'applications)
151 "Games, jokes and amusements."
152 :group 'applications)
154 (defgroup development nil
155 "Support for further development of Emacs."
159 "Support for Emacs documentation."
162 (defgroup extensions nil
163 "Emacs Lisp language extensions."
166 (defgroup internal nil
167 "Code for Emacs internals, build process, defaults."
171 "Maintenance aids for the Emacs development group."
175 (defgroup environment nil
176 "Fitting Emacs with its environment."
180 "Communications, networking, remote access to files."
184 (defgroup hardware nil
185 "Support for interfacing with exotic hardware."
188 (defgroup terminals nil
189 "Support for terminal types."
193 "Front-ends/assistants for, or emulators of, UNIX features."
197 "Support code for vms."
201 "Internationalization and alternate character-set support."
206 "The X Window system."
210 "Support for Emacs frames and window systems."
214 "Support editing files of data."
218 "Support editing files."
226 "Code related to the TeX formatter."
230 "Support for multiple fonts."
233 (defgroup hypermedia nil
234 "Support for links between text or other media types."
238 "Support for on-line help systems."
242 "Code local to your site."
245 (defgroup customize '((widgets custom-group))
246 "Customization of the Customization support."
247 :link '(custom-manual "(custom)Top")
248 :link '(url-link :tag "Development Page"
249 "http://www.dina.kvl.dk/~abraham/custom/")
253 (defgroup custom-faces nil
254 "Faces used by customize."
258 (defgroup custom-browse nil
259 "Control customize browser."
263 (defgroup custom-buffer nil
264 "Control customize buffers."
268 (defgroup custom-menu nil
269 "Control customize menus."
273 (defgroup abbrev-mode nil
274 "Word abbreviations mode."
278 "Storage allocation and gc for GNU Emacs Lisp interpreter."
279 :tag "Storage Allocation"
283 "Undoing changes in buffers."
286 (defgroup modeline nil
287 "Content of the modeline."
291 "Indenting and filling text."
294 (defgroup editing-basics nil
295 "Most basic editing facilities."
298 (defgroup display nil
299 "How characters are displayed in buffers."
302 (defgroup execute nil
303 "Executing external commands."
306 (defgroup installation nil
307 "The Emacs installation."
315 "Internal Emacs limits."
319 "Debugging Emacs itself."
322 (defgroup minibuffer nil
323 "Controling the behaviour of the minibuffer."
326 (defgroup keyboard nil
327 "Input from the keyboard."
331 "Input from the mouse."
335 "Input from the menus."
338 (defgroup auto-save nil
339 "Preventing accidential loss of data."
342 (defgroup processes-basics nil
343 "Basic stuff dealing with processes."
347 "MULE Emacs internationalization."
350 (defgroup windows nil
351 "Windows within a frame."
356 (defun custom-last (x &optional n)
357 ;; Stolen from `cl.el'.
358 "Returns the last link in the list LIST.
359 With optional argument N, returns Nth-to-last link (default 1)."
362 (while (consp p) (incf m) (pop p))
364 (if (< n m) (nthcdr (- m n) x) x)))
365 (while (consp (cdr x)) (pop x))
368 (defun custom-quote (sexp)
369 "Quote SEXP iff it is not self quoting."
370 (if (or (memq sexp '(t nil))
372 (eq (aref (symbol-name sexp) 0) ?:))
374 (memq (car sexp) '(lambda)))
377 (and (fboundp 'characterp)
382 (defun custom-split-regexp-maybe (regexp)
383 "If REGEXP is a string, split it to a list at `\\|'.
384 You can get the original back with from the result with:
385 (mapconcat 'identity result \"\\|\")
387 IF REGEXP is not a string, return it unchanged."
391 (while (string-match "\\\\|" regexp start)
392 (setq all (cons (substring regexp start (match-beginning 0)) all)
393 start (match-end 0)))
394 (nreverse (cons (substring regexp start) all)))
397 (defun custom-variable-prompt ()
398 ;; Code stolen from `help.el'.
399 "Prompt for a variable, defaulting to the variable at point.
400 Return a list suitable for use in `interactive'."
401 (let ((v (variable-at-point))
402 (enable-recursive-minibuffers t)
404 (setq val (completing-read
406 (format "Customize option: (default %s) " v)
407 "Customize variable: ")
408 obarray (lambda (symbol)
410 (or (get symbol 'custom-type)
411 (user-variable-p symbol)))) t))
412 (list (if (equal val "")
413 (if (symbolp v) v nil)
416 (defun custom-menu-filter (menu widget)
417 "Convert MENU to the form used by `widget-choose'.
418 MENU should be in the same format as `custom-variable-menu'.
419 WIDGET is the widget to apply the filter entries of MENU on."
421 current name action filter)
423 (setq current (car menu)
425 action (nth 1 current)
426 filter (nth 2 current)
428 (if (or (null filter) (funcall filter widget))
429 (push (cons name action) result)
435 (defvar custom-prefix-list nil
436 "List of prefixes that should be ignored by `custom-unlispify'")
438 (defcustom custom-unlispify-menu-entries t
439 "Display menu entries as words instead of symbols if non nil."
443 (defcustom custom-unlispify-remove-prefixes nil
444 "Non-nil means remove group prefixes from option names in buffer."
448 (defun custom-unlispify-menu-entry (symbol &optional no-suffix)
449 "Convert symbol into a menu entry."
450 (cond ((not custom-unlispify-menu-entries)
451 (symbol-name symbol))
452 ((get symbol 'custom-tag)
454 (get symbol 'custom-tag)
455 (concat (get symbol 'custom-tag) "...")))
458 (set-buffer (get-buffer-create " *Custom-Work*"))
460 (princ symbol (current-buffer))
461 (goto-char (point-min))
462 (when (and (eq (get symbol 'custom-type) 'boolean)
463 (re-search-forward "-p\\'" nil t))
464 (replace-match "" t t)
465 (goto-char (point-min)))
466 (if custom-unlispify-remove-prefixes
467 (let ((prefixes custom-prefix-list)
470 (setq prefix (car prefixes))
471 (if (search-forward prefix (+ (point) (length prefix)) t)
474 (delete-region (point-min) (point)))
475 (setq prefixes (cdr prefixes))))))
476 (subst-char-in-region (point-min) (point-max) ?- ?\ t)
477 (capitalize-region (point-min) (point-max))
479 (goto-char (point-max))
483 (defcustom custom-unlispify-tag-names t
484 "Display tag names as words instead of symbols if non nil."
485 :group 'custom-buffer
488 (defun custom-unlispify-tag-name (symbol)
489 "Convert symbol into a menu entry."
490 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names))
491 (custom-unlispify-menu-entry symbol t)))
493 (defun custom-prefix-add (symbol prefixes)
494 ;; Addd SYMBOL to list of ignored PREFIXES.
495 (cons (or (get symbol 'custom-prefix)
496 (concat (symbol-name symbol) "-"))
501 (defcustom custom-guess-name-alist
506 ("-function\\'" function)
507 ("-functions\\'" (repeat function))
508 ("-list\\'" (repeat sexp))
509 ("-alist\\'" (repeat (cons sexp sexp))))
510 "Alist of (MATCH TYPE).
512 MATCH should be a regexp matching the name of a symbol, and TYPE should
513 be a widget suitable for editing the value of that symbol. The TYPE
514 of the first entry where MATCH matches the name of the symbol will be
517 This is used for guessing the type of variables not declared with
519 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
522 (defcustom custom-guess-doc-alist
523 '(("\\`\\*?Non-nil " boolean))
524 "Alist of (MATCH TYPE).
526 MATCH should be a regexp matching a documentation string, and TYPE
527 should be a widget suitable for editing the value of a variable with
528 that documentation string. The TYPE of the first entry where MATCH
529 matches the name of the symbol will be used.
531 This is used for guessing the type of variables not declared with
533 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
536 (defun custom-guess-type (symbol)
537 "Guess a widget suitable for editing the value of SYMBOL.
538 This is done by matching SYMBOL with `custom-guess-name-alist' and
539 if that fails, the doc string with `custom-guess-doc-alist'."
540 (let ((name (symbol-name symbol))
541 (names custom-guess-name-alist)
544 (setq current (car names)
546 (when (string-match (nth 0 current) name)
547 (setq found (nth 1 current)
550 (let ((doc (documentation-property symbol 'variable-documentation))
551 (docs custom-guess-doc-alist))
554 (setq current (car docs)
556 (when (string-match (nth 0 current) doc)
557 (setq found (nth 1 current)
563 (defcustom custom-browse-sort-alphabetically nil
564 "If non-nil, sort members of each customization group alphabetically."
566 :group 'custom-browse)
568 (defcustom custom-browse-order-groups nil
569 "If non-nil, order group members within each customization group.
570 If `first', order groups before non-groups.
571 If `last', order groups after non-groups."
572 :type '(choice (const first)
574 (const :tag "none" nil))
575 :group 'custom-browse)
577 (defcustom custom-browse-only-groups nil
578 "If non-nil, show group members only within each customization group."
580 :group 'custom-browse)
582 (defcustom custom-buffer-sort-alphabetically nil
583 "If non-nil, sort members of each customization group alphabetically."
585 :group 'custom-buffer)
587 (defcustom custom-buffer-order-groups 'last
588 "If non-nil, order group members within each customization group.
589 If `first', order groups before non-groups.
590 If `last', order groups after non-groups."
591 :type '(choice (const first)
593 (const :tag "none" nil))
594 :group 'custom-buffer)
596 (defcustom custom-menu-sort-alphabetically nil
597 "If non-nil, sort members of each customization group alphabetically."
601 (defcustom custom-menu-order-groups 'first
602 "If non-nil, order group members within each customization group.
603 If `first', order groups before non-groups.
604 If `last', order groups after non-groups."
605 :type '(choice (const first)
607 (const :tag "none" nil))
610 (defun custom-sort-items (items sort-alphabetically order-groups)
611 "Return a sorted copy of ITEMS.
612 ITEMS should be a `custom-group' property.
613 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
614 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
615 groups after non-groups, if nil do not order groups at all."
616 (sort (copy-sequence items)
618 (let ((typea (nth 1 a)) (typeb (nth 1 b))
619 (namea (symbol-name (nth 0 a))) (nameb (symbol-name (nth 0 b))))
620 (cond ((not order-groups)
621 ;; Since we don't care about A and B order, maybe sort.
622 (when sort-alphabetically
623 (string-lessp namea nameb)))
624 ((eq typea 'custom-group)
625 ;; If B is also a group, maybe sort. Otherwise, order A and B.
626 (if (eq typeb 'custom-group)
627 (when sort-alphabetically
628 (string-lessp namea nameb))
629 (eq order-groups 'first)))
630 ((eq typeb 'custom-group)
631 ;; Since A cannot be a group, order A and B.
632 (eq order-groups 'last))
634 ;; Since A and B cannot be groups, sort.
635 (string-lessp namea nameb)))))))
637 ;;; Custom Mode Commands.
639 (defvar custom-options nil
640 "Customization widgets in the current buffer.")
643 "Set changes in all modified options."
645 (let ((children custom-options))
646 (mapcar (lambda (child)
647 (when (eq (widget-get child :custom-state) 'modified)
648 (widget-apply child :custom-set)))
651 (defun Custom-save ()
652 "Set all modified group members and save them."
654 (let ((children custom-options))
655 (mapcar (lambda (child)
656 (when (memq (widget-get child :custom-state) '(modified set))
657 (widget-apply child :custom-save)))
661 (defvar custom-reset-menu
662 '(("Current" . Custom-reset-current)
663 ("Saved" . Custom-reset-saved)
664 ("Standard Settings" . Custom-reset-standard))
665 "Alist of actions for the `Reset' button.
666 The key is a string containing the name of the action, the value is a
667 lisp function taking the widget as an element which will be called
668 when the action is chosen.")
670 (defun custom-reset (event)
671 "Select item from reset menu."
672 (let* ((completion-ignore-case t)
673 (answer (widget-choose "Reset to"
679 (defun Custom-reset-current (&rest ignore)
680 "Reset all modified group members to their current value."
682 (let ((children custom-options))
683 (mapcar (lambda (child)
684 (when (eq (widget-get child :custom-state) 'modified)
685 (widget-apply child :custom-reset-current)))
688 (defun Custom-reset-saved (&rest ignore)
689 "Reset all modified or set group members to their saved value."
691 (let ((children custom-options))
692 (mapcar (lambda (child)
693 (when (eq (widget-get child :custom-state) 'modified)
694 (widget-apply child :custom-reset-saved)))
697 (defun Custom-reset-standard (&rest ignore)
698 "Reset all modified, set, or saved group members to their standard settings."
700 (let ((children custom-options))
701 (mapcar (lambda (child)
702 (when (eq (widget-get child :custom-state) 'modified)
703 (widget-apply child :custom-reset-standard)))
706 ;;; The Customize Commands
708 (defun custom-prompt-variable (prompt-var prompt-val)
709 "Prompt for a variable and a value and return them as a list.
710 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
711 prompt for the value. The %s escape in PROMPT-VAL is replaced with
712 the name of the variable.
714 If the variable has a `variable-interactive' property, that is used as if
715 it were the arg to `interactive' (which see) to interactively read the value.
717 If the variable has a `custom-type' property, it must be a widget and the
718 `:prompt-value' property of that widget will be used for reading the value."
719 (let* ((var (read-variable prompt-var))
720 (minibuffer-help-form '(describe-variable var)))
722 (let ((prop (get var 'variable-interactive))
723 (type (get var 'custom-type))
724 (prompt (format prompt-val var)))
726 (setq type (list type)))
728 ;; Use VAR's `variable-interactive' property
729 ;; as an interactive spec for prompting.
730 (call-interactively (list 'lambda '(arg)
731 (list 'interactive prop)
734 (widget-prompt-value type
740 (eval-minibuffer prompt)))))))
743 (defun customize-set-value (var val)
744 "Set VARIABLE to VALUE. VALUE is a Lisp object.
746 If VARIABLE has a `variable-interactive' property, that is used as if
747 it were the arg to `interactive' (which see) to interactively read the value.
749 If VARIABLE has a `custom-type' property, it must be a widget and the
750 `:prompt-value' property of that widget will be used for reading the value."
751 (interactive (custom-prompt-variable "Set variable: "
752 "Set %s to value: "))
757 (defun customize-set-variable (var val)
758 "Set the default for VARIABLE to VALUE. VALUE is a Lisp object.
760 If VARIABLE has a `custom-set' property, that is used for setting
761 VARIABLE, otherwise `set-default' is used.
763 The `customized-value' property of the VARIABLE will be set to a list
764 with a quoted VALUE as its sole list member.
766 If VARIABLE has a `variable-interactive' property, that is used as if
767 it were the arg to `interactive' (which see) to interactively read the value.
769 If VARIABLE has a `custom-type' property, it must be a widget and the
770 `:prompt-value' property of that widget will be used for reading the value. "
771 (interactive (custom-prompt-variable "Set variable: "
772 "Set customized value for %s to: "))
773 (funcall (or (get var 'custom-set) 'set-default) var val)
774 (put var 'customized-value (list (custom-quote val))))
777 (defun customize-save-variable (var val)
778 "Set the default for VARIABLE to VALUE, and save it for future sessions.
779 If VARIABLE has a `custom-set' property, that is used for setting
780 VARIABLE, otherwise `set-default' is used.
782 The `customized-value' property of the VARIABLE will be set to a list
783 with a quoted VALUE as its sole list member.
785 If VARIABLE has a `variable-interactive' property, that is used as if
786 it were the arg to `interactive' (which see) to interactively read the value.
788 If VARIABLE has a `custom-type' property, it must be a widget and the
789 `:prompt-value' property of that widget will be used for reading the value. "
790 (interactive (custom-prompt-variable "Set and ave variable: "
791 "Set and save value for %s as: "))
792 (funcall (or (get var 'custom-set) 'set-default) var val)
793 (put var 'saved-value (list (custom-quote val)))
798 "Select a customization buffer which you can use to set user options.
799 User options are structured into \"groups\".
800 Initially the top-level group `Emacs' and its immediate subgroups
801 are shown; the contents of those subgroups are initially hidden."
803 (customize-group 'emacs))
806 (defun customize-group (group)
807 "Customize GROUP, which must be a customization group."
808 (interactive (list (let ((completion-ignore-case t))
809 (completing-read "Customize group: (default emacs) "
812 (or (get symbol 'custom-loads)
813 (get symbol 'custom-group)))
815 (when (stringp group)
816 (if (string-equal "" group)
818 (setq group (intern group))))
819 (or (get group 'custom-group)
820 (custom-load-symbol group))
821 (let ((name (format "*Customize Group: %s*"
822 (custom-unlispify-tag-name group))))
823 (if (get-buffer name)
824 (switch-to-buffer name)
825 (custom-buffer-create (list (list group 'custom-group))
827 (concat " for group "
828 (custom-unlispify-tag-name group))))))
831 (defun customize-group-other-window (symbol)
832 "Customize SYMBOL, which must be a customization group."
833 (interactive (list (completing-read "Customize group: (default emacs) "
836 (get symbol 'custom-group))
839 (when (stringp symbol)
840 (if (string-equal "" symbol)
842 (setq symbol (intern symbol))))
843 (custom-buffer-create-other-window
844 (list (list symbol 'custom-group))
845 (format "*Customize Group: %s*" (custom-unlispify-tag-name symbol))))
848 (defalias 'customize-variable 'customize-option)
851 (defun customize-option (symbol)
852 "Customize SYMBOL, which must be a user option variable."
853 (interactive (custom-variable-prompt))
854 (custom-buffer-create (list (list symbol 'custom-variable))
855 (format "*Customize Option: %s*"
856 (custom-unlispify-tag-name symbol))))
859 (defun customize-changed-options (since-version)
860 "Customize all user option variables whose default values changed recently.
861 This means, in other words, variables and groups defined with a `:version'
863 (interactive "sCustomize options changed, since version (default all versions): ")
864 (if (equal since-version "")
865 (setq since-version nil))
867 (mapatoms (lambda (symbol)
868 (and (or (boundp symbol)
869 ;; For groups the previous test fails, this one
870 ;; could be used to determine if symbol is a
871 ;; group. Is there a better way for this?
872 (get symbol 'group-documentation))
873 (let ((version (get symbol 'custom-version)))
875 (or (null since-version)
876 (customize-version-lessp since-version version))))
878 ;; We have to set the right thing here,
879 ;; depending if we have a group or a
881 (if (get symbol 'group-documentation)
882 (cons (list symbol 'custom-group) found)
883 (cons (list symbol 'custom-variable) found))))))
885 (error "No user options have changed defaults in recent Emacs versions")
886 (custom-buffer-create (custom-sort-items found t nil)
887 "*Customize Changed Options*"))))
889 (defun customize-version-lessp (version1 version2)
890 (let (major1 major2 minor1 minor2)
891 (string-match "\\([0-9]+\\)[.]\\([0-9]+\\)" version1)
892 (setq major1 (read (match-string 1 version1)))
893 (setq minor1 (read (match-string 2 version1)))
894 (string-match "\\([0-9]+\\)[.]\\([0-9]+\\)" version2)
895 (setq major2 (read (match-string 1 version2)))
896 (setq minor2 (read (match-string 2 version2)))
897 (or (< major1 major2)
898 (and (= major1 major2)
899 (< minor1 minor2)))))
902 (defalias 'customize-variable-other-window 'customize-option-other-window)
905 (defun customize-option-other-window (symbol)
906 "Customize SYMBOL, which must be a user option variable.
907 Show the buffer in another window, but don't select it."
908 (interactive (custom-variable-prompt))
909 (custom-buffer-create-other-window
910 (list (list symbol 'custom-variable))
911 (format "*Customize Option: %s*" (custom-unlispify-tag-name symbol))))
914 (defun customize-face (&optional symbol)
915 "Customize SYMBOL, which should be a face name or nil.
916 If SYMBOL is nil, customize all faces."
917 (interactive (list (completing-read "Customize face: (default all) "
918 obarray 'custom-facep)))
919 (if (or (null symbol) (and (stringp symbol) (zerop (length symbol))))
920 (custom-buffer-create (custom-sort-items
921 (mapcar (lambda (symbol)
922 (list symbol 'custom-face))
926 (when (stringp symbol)
927 (setq symbol (intern symbol)))
928 (unless (symbolp symbol)
929 (error "Should be a symbol %S" symbol))
930 (custom-buffer-create (list (list symbol 'custom-face))
931 (format "*Customize Face: %s*"
932 (custom-unlispify-tag-name symbol)))))
935 (defun customize-face-other-window (&optional symbol)
936 "Show customization buffer for FACE in other window."
937 (interactive (list (completing-read "Customize face: "
938 obarray 'custom-facep)))
939 (if (or (null symbol) (and (stringp symbol) (zerop (length symbol))))
942 (setq symbol (intern symbol)))
943 (unless (symbolp symbol)
944 (error "Should be a symbol %S" symbol))
945 (custom-buffer-create-other-window
946 (list (list symbol 'custom-face))
947 (format "*Customize Face: %s*" (custom-unlispify-tag-name symbol)))))
950 (defun customize-customized ()
951 "Customize all user options set since the last save in this session."
954 (mapatoms (lambda (symbol)
955 (and (get symbol 'customized-face)
956 (custom-facep symbol)
957 (push (list symbol 'custom-face) found))
958 (and (get symbol 'customized-value)
960 (push (list symbol 'custom-variable) found))))
962 (error "No customized user options")
963 (custom-buffer-create (custom-sort-items found t nil)
964 "*Customize Customized*"))))
967 (defun customize-saved ()
968 "Customize all already saved user options."
971 (mapatoms (lambda (symbol)
972 (and (get symbol 'saved-face)
973 (custom-facep symbol)
974 (push (list symbol 'custom-face) found))
975 (and (get symbol 'saved-value)
977 (push (list symbol 'custom-variable) found))))
979 (error "No saved user options")
980 (custom-buffer-create (custom-sort-items found t nil)
981 "*Customize Saved*"))))
984 (defun customize-apropos (regexp &optional all)
985 "Customize all user options matching REGEXP.
986 If ALL is `options', include only options.
987 If ALL is `faces', include only faces.
988 If ALL is `groups', include only groups.
989 If ALL is t (interactively, with prefix arg), include options which are not
990 user-settable, as well as faces and groups."
991 (interactive "sCustomize regexp: \nP")
993 (mapatoms (lambda (symbol)
994 (when (string-match regexp (symbol-name symbol))
995 (when (and (not (memq all '(faces options)))
996 (get symbol 'custom-group))
997 (push (list symbol 'custom-group) found))
998 (when (and (not (memq all '(options groups)))
999 (custom-facep symbol))
1000 (push (list symbol 'custom-face) found))
1001 (when (and (not (memq all '(groups faces)))
1003 (or (get symbol 'saved-value)
1004 (get symbol 'standard-value)
1005 (if (memq all '(nil options))
1006 (user-variable-p symbol)
1007 (get symbol 'variable-documentation))))
1008 (push (list symbol 'custom-variable) found)))))
1010 (error "No matches")
1011 (custom-buffer-create (custom-sort-items found t
1012 custom-buffer-order-groups)
1013 "*Customize Apropos*"))))
1016 (defun customize-apropos-options (regexp &optional arg)
1017 "Customize all user options matching REGEXP.
1018 With prefix arg, include options which are not user-settable."
1019 (interactive "sCustomize regexp: \nP")
1020 (customize-apropos regexp (or arg 'options)))
1023 (defun customize-apropos-faces (regexp)
1024 "Customize all user faces matching REGEXP."
1025 (interactive "sCustomize regexp: \n")
1026 (customize-apropos regexp 'faces))
1029 (defun customize-apropos-groups (regexp)
1030 "Customize all user groups matching REGEXP."
1031 (interactive "sCustomize regexp: \n")
1032 (customize-apropos regexp 'groups))
1036 (defcustom custom-buffer-style 'links
1037 "Control the presentation style for customization buffers.
1038 The value should be a symbol, one of:
1040 brackets: groups nest within each other with big horizontal brackets.
1041 links: groups have links to subgroups."
1042 :type '(radio (const brackets)
1044 :group 'custom-buffer)
1046 (defcustom custom-buffer-indent 3
1047 "Number of spaces to indent nested groups."
1049 :group 'custom-buffer)
1052 (defun custom-buffer-create (options &optional name description)
1053 "Create a buffer containing OPTIONS.
1054 Optional NAME is the name of the buffer.
1055 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1056 SYMBOL is a customization option, and WIDGET is a widget for editing
1058 (unless name (setq name "*Customization*"))
1059 (kill-buffer (get-buffer-create name))
1060 (switch-to-buffer (get-buffer-create name))
1061 (custom-buffer-create-internal options description))
1064 (defun custom-buffer-create-other-window (options &optional name description)
1065 "Create a buffer containing OPTIONS.
1066 Optional NAME is the name of the buffer.
1067 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1068 SYMBOL is a customization option, and WIDGET is a widget for editing
1070 (unless name (setq name "*Customization*"))
1071 (kill-buffer (get-buffer-create name))
1072 (let ((window (selected-window)))
1073 (switch-to-buffer-other-window (get-buffer-create name))
1074 (custom-buffer-create-internal options description)
1075 (select-window window)))
1077 (defcustom custom-reset-button-menu nil
1078 "If non-nil, only show a single reset button in customize buffers.
1079 This button will have a menu with all three reset operations."
1081 :group 'custom-buffer)
1083 (defun custom-buffer-create-internal (options &optional description)
1084 (message "Creating customization buffer...")
1086 (widget-insert "This is a customization buffer")
1088 (widget-insert description))
1090 Square brackets show active fields; type RET or click mouse-1
1091 on an active field to invoke its action. Editing an option value
1092 changes the text in the buffer; invoke the State button and
1093 choose the Set operation to set the option value.
1095 (widget-create 'info-link
1097 :help-echo "Read the online help."
1098 "(emacs)Easy Customization")
1099 (widget-insert " for more information.\n\n")
1100 (message "Creating customization buttons...")
1101 (widget-insert "Operate on everything in this buffer:\n ")
1102 (widget-create 'push-button
1103 :tag "Set for Current Session"
1105 Make your editing in this buffer take effect for this session."
1106 :action (lambda (widget &optional event)
1109 (widget-create 'push-button
1110 :tag "Save for Future Sessions"
1112 Make your editing in this buffer take effect for future Emacs sessions."
1113 :action (lambda (widget &optional event)
1115 (if custom-reset-button-menu
1118 (widget-create 'push-button
1120 :help-echo "Show a menu with reset operations."
1121 :mouse-down-action (lambda (&rest junk) t)
1122 :action (lambda (widget &optional event)
1123 (custom-reset event))))
1124 (widget-insert "\n ")
1125 (widget-create 'push-button
1128 Reset all edited text in this buffer to reflect current values."
1129 :action 'Custom-reset-current)
1131 (widget-create 'push-button
1132 :tag "Reset to Saved"
1134 Reset all values in this buffer to their saved settings."
1135 :action 'Custom-reset-saved)
1137 (widget-create 'push-button
1138 :tag "Reset to Standard"
1140 Reset all values in this buffer to their standard settings."
1141 :action 'Custom-reset-standard))
1143 (widget-create 'push-button
1145 :help-echo "Bury the buffer."
1146 :action (lambda (widget &optional event)
1148 (widget-insert "\n\n")
1149 (message "Creating customization items...")
1150 (setq custom-options
1151 (if (= (length options) 1)
1152 (mapcar (lambda (entry)
1153 (widget-create (nth 1 entry)
1154 :documentation-shown t
1155 :custom-state 'unknown
1156 :tag (custom-unlispify-tag-name
1158 :value (nth 0 entry)))
1161 (length (length options)))
1162 (mapcar (lambda (entry)
1164 (message "Creating customization items %2d%%..."
1165 (/ (* 100.0 count) length))
1166 (widget-create (nth 1 entry)
1167 :tag (custom-unlispify-tag-name
1169 :value (nth 0 entry))
1170 (setq count (1+ count))
1171 (unless (eq (preceding-char) ?\n)
1172 (widget-insert "\n"))
1173 (widget-insert "\n")))
1175 (unless (eq (preceding-char) ?\n)
1176 (widget-insert "\n"))
1177 (message "Creating customization items %2d%%...done" 100)
1178 (unless (eq custom-buffer-style 'tree)
1179 (mapcar 'custom-magic-reset custom-options))
1180 (message "Creating customization setup...")
1182 (goto-char (point-min))
1183 (message "Creating customization buffer...done"))
1185 ;;; The Tree Browser.
1188 (defun customize-browse (&optional group)
1189 "Create a tree browser for the customize hierarchy."
1192 (setq group 'emacs))
1193 (let ((name "*Customize Browser*"))
1194 (kill-buffer (get-buffer-create name))
1195 (switch-to-buffer (get-buffer-create name)))
1198 Square brackets show active fields; type RET or click mouse-1
1199 on an active field to invoke its action.
1200 Invoke [+] below to expand a group, and [-] to collapse an expanded group.\n")
1201 (if custom-browse-only-groups
1203 Invoke the [Group] button below to edit that item in another window.\n\n")
1204 (widget-insert "Invoke the ")
1205 (widget-create 'item
1208 :tag-glyph "folder")
1209 (widget-insert ", ")
1210 (widget-create 'item
1214 (widget-insert ", and ")
1215 (widget-create 'item
1218 :tag-glyph "option")
1219 (widget-insert " buttons below to edit that
1220 item in another window.\n\n"))
1221 (let ((custom-buffer-style 'tree))
1222 (widget-create 'custom-group
1224 :custom-state 'unknown
1225 :tag (custom-unlispify-tag-name group)
1227 (goto-char (point-min)))
1229 (define-widget 'custom-browse-visibility 'item
1230 "Control visibility of items in the customize tree browser."
1232 :action 'custom-browse-visibility-action)
1234 (defun custom-browse-visibility-action (widget &rest ignore)
1235 (let ((custom-buffer-style 'tree))
1236 (custom-toggle-parent widget)))
1238 (define-widget 'custom-browse-group-tag 'push-button
1239 "Show parent in other window when activated."
1242 :action 'custom-browse-group-tag-action)
1244 (defun custom-browse-group-tag-action (widget &rest ignore)
1245 (let ((parent (widget-get widget :parent)))
1246 (customize-group-other-window (widget-value parent))))
1248 (define-widget 'custom-browse-variable-tag 'push-button
1249 "Show parent in other window when activated."
1252 :action 'custom-browse-variable-tag-action)
1254 (defun custom-browse-variable-tag-action (widget &rest ignore)
1255 (let ((parent (widget-get widget :parent)))
1256 (customize-variable-other-window (widget-value parent))))
1258 (define-widget 'custom-browse-face-tag 'push-button
1259 "Show parent in other window when activated."
1262 :action 'custom-browse-face-tag-action)
1264 (defun custom-browse-face-tag-action (widget &rest ignore)
1265 (let ((parent (widget-get widget :parent)))
1266 (customize-face-other-window (widget-value parent))))
1268 (defconst custom-browse-alist '((" " "space")
1274 (defun custom-browse-insert-prefix (prefix)
1275 "Insert PREFIX. On XEmacs convert it to line graphics."
1276 (if nil ; (string-match "XEmacs" emacs-version)
1279 (while (not (string-equal prefix ""))
1280 (let ((entry (substring prefix 0 3)))
1281 (setq prefix (substring prefix 3))
1282 (let ((overlay (make-overlay (1- (point)) (point) nil t nil))
1283 (name (nth 1 (assoc entry custom-browse-alist))))
1284 (overlay-put overlay 'end-glyph (widget-glyph-find name entry))
1285 (overlay-put overlay 'start-open t)
1286 (overlay-put overlay 'end-open t)))))
1289 ;;; Modification of Basic Widgets.
1291 ;; We add extra properties to the basic widgets needed here. This is
1292 ;; fine, as long as we are careful to stay within out own namespace.
1294 ;; We want simple widgets to be displayed by default, but complex
1295 ;; widgets to be hidden.
1297 (widget-put (get 'item 'widget-type) :custom-show t)
1298 (widget-put (get 'editable-field 'widget-type)
1299 :custom-show (lambda (widget value)
1300 (let ((pp (pp-to-string value)))
1301 (cond ((string-match "\n" pp)
1306 (widget-put (get 'menu-choice 'widget-type) :custom-show t)
1308 ;;; The `custom-manual' Widget.
1310 (define-widget 'custom-manual 'info-link
1311 "Link to the manual entry for this customization option."
1312 :help-echo "Read the manual entry for this option."
1315 ;;; The `custom-magic' Widget.
1317 (defgroup custom-magic-faces nil
1318 "Faces used by the magic button."
1319 :group 'custom-faces
1320 :group 'custom-buffer)
1322 (defface custom-invalid-face '((((class color))
1323 (:foreground "yellow" :background "red"))
1325 (:bold t :italic t :underline t)))
1326 "Face used when the customize item is invalid."
1327 :group 'custom-magic-faces)
1329 (defface custom-rogue-face '((((class color))
1330 (:foreground "pink" :background "black"))
1333 "Face used when the customize item is not defined for customization."
1334 :group 'custom-magic-faces)
1336 (defface custom-modified-face '((((class color))
1337 (:foreground "white" :background "blue"))
1340 "Face used when the customize item has been modified."
1341 :group 'custom-magic-faces)
1343 (defface custom-set-face '((((class color))
1344 (:foreground "blue" :background "white"))
1347 "Face used when the customize item has been set."
1348 :group 'custom-magic-faces)
1350 (defface custom-changed-face '((((class color))
1351 (:foreground "white" :background "blue"))
1354 "Face used when the customize item has been changed."
1355 :group 'custom-magic-faces)
1357 (defface custom-saved-face '((t (:underline t)))
1358 "Face used when the customize item has been saved."
1359 :group 'custom-magic-faces)
1361 (defconst custom-magic-alist '((nil "#" underline "\
1362 uninitialized, you should not see this.")
1363 (unknown "?" italic "\
1364 unknown, you should not see this.")
1365 (hidden "-" default "\
1366 hidden, invoke \"Show\" in the previous line to show." "\
1367 group now hidden, invoke \"Show\", above, to show contents.")
1368 (invalid "x" custom-invalid-face "\
1369 the value displayed for this %c is invalid and cannot be set.")
1370 (modified "*" custom-modified-face "\
1371 you have edited the value as text, but you have not set the %c." "\
1372 you have edited something in this group, but not set it.")
1373 (set "+" custom-set-face "\
1374 you have set this %c, but not saved it for future sessions." "\
1375 something in this group has been set, but not saved.")
1376 (changed ":" custom-changed-face "\
1377 this %c has been changed outside the customize buffer." "\
1378 something in this group has been changed outside customize.")
1379 (saved "!" custom-saved-face "\
1380 this %c has been set and saved." "\
1381 something in this group has been set and saved.")
1382 (rogue "@" custom-rogue-face "\
1383 this %c has not been changed with customize." "\
1384 something in this group is not prepared for customization.")
1385 (standard " " nil "\
1386 this %c is unchanged from its standard setting." "\
1387 visible group members are all at standard settings."))
1388 "Alist of customize option states.
1389 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1391 STATE is one of the following symbols:
1394 For internal use, should never occur.
1396 For internal use, should never occur.
1398 This item is not being displayed.
1400 This item is modified, but has an invalid form.
1402 This item is modified, and has a valid form.
1404 This item has been set but not saved.
1406 The current value of this item has been changed temporarily.
1408 This item is marked for saving.
1410 This item has no customization information.
1412 This item is unchanged from the standard setting.
1414 MAGIC is a string used to present that state.
1416 FACE is a face used to present the state.
1418 ITEM-DESC is a string describing the state for options.
1420 GROUP-DESC is a string describing the state for groups. If this is
1421 left out, ITEM-DESC will be used.
1423 The string %c in either description will be replaced with the
1424 category of the item. These are `group'. `option', and `face'.
1426 The list should be sorted most significant first.")
1428 (defcustom custom-magic-show 'long
1429 "If non-nil, show textual description of the state.
1430 If `long', show a full-line description, not just one word."
1431 :type '(choice (const :tag "no" nil)
1434 :group 'custom-buffer)
1436 (defcustom custom-magic-show-hidden '(option face)
1437 "Control whether the State button is shown for hidden items.
1438 The value should be a list with the custom categories where the State
1439 button should be visible. Possible categories are `group', `option',
1441 :type '(set (const group) (const option) (const face))
1442 :group 'custom-buffer)
1444 (defcustom custom-magic-show-button nil
1445 "Show a \"magic\" button indicating the state of each customization option."
1447 :group 'custom-buffer)
1449 (define-widget 'custom-magic 'default
1450 "Show and manipulate state for a customization option."
1452 :action 'widget-parent-action
1455 :value-create 'custom-magic-value-create
1456 :value-delete 'widget-children-value-delete)
1458 (defun widget-magic-mouse-down-action (widget &optional event)
1459 ;; Non-nil unless hidden.
1460 (not (eq (widget-get (widget-get (widget-get widget :parent) :parent)
1464 (defun custom-magic-value-create (widget)
1465 ;; Create compact status report for WIDGET.
1466 (let* ((parent (widget-get widget :parent))
1467 (state (widget-get parent :custom-state))
1468 (hidden (eq state 'hidden))
1469 (entry (assq state custom-magic-alist))
1470 (magic (nth 1 entry))
1471 (face (nth 2 entry))
1472 (category (widget-get parent :custom-category))
1473 (text (or (and (eq category 'group)
1476 (form (widget-get parent :custom-form))
1478 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text)
1479 (setq text (concat (match-string 1 text)
1480 (symbol-name category)
1481 (match-string 2 text))))
1482 (when (and custom-magic-show
1484 (memq category custom-magic-show-hidden)))
1486 (when (and (eq category 'group)
1487 (not (and (eq custom-buffer-style 'links)
1488 (> (widget-get parent :custom-level) 1))))
1489 (insert-char ?\ (* custom-buffer-indent
1490 (widget-get parent :custom-level))))
1491 (push (widget-create-child-and-convert
1493 :help-echo "Change the state of this item."
1494 :format (if hidden "%t" "%[%t%]")
1495 :button-prefix 'widget-push-button-prefix
1496 :button-suffix 'widget-push-button-suffix
1497 :mouse-down-action 'widget-magic-mouse-down-action
1501 (let ((start (point)))
1502 (if (eq custom-magic-show 'long)
1504 (insert (symbol-name state)))
1505 (cond ((eq form 'lisp)
1507 ((eq form 'mismatch)
1508 (insert " (mismatch)")))
1509 (put-text-property start (point) 'face 'custom-state-face))
1511 (when (and (eq category 'group)
1512 (not (and (eq custom-buffer-style 'links)
1513 (> (widget-get parent :custom-level) 1))))
1514 (insert-char ?\ (* custom-buffer-indent
1515 (widget-get parent :custom-level))))
1516 (when custom-magic-show-button
1517 (when custom-magic-show
1518 (let ((indent (widget-get parent :indent)))
1520 (insert-char ? indent))))
1521 (push (widget-create-child-and-convert
1523 :mouse-down-action 'widget-magic-mouse-down-action
1527 :help-echo "Change the state."
1528 :format (if hidden "%t" "%[%t%]")
1529 :tag (if (memq form '(lisp mismatch))
1530 (concat "(" magic ")")
1531 (concat "[" magic "]")))
1534 (widget-put widget :children children)))
1536 (defun custom-magic-reset (widget)
1537 "Redraw the :custom-magic property of WIDGET."
1538 (let ((magic (widget-get widget :custom-magic)))
1539 (widget-value-set magic (widget-value magic))))
1541 ;;; The `custom' Widget.
1543 (defface custom-button-face nil
1544 "Face used for buttons in customization buffers."
1545 :group 'custom-faces)
1547 (defface custom-documentation-face nil
1548 "Face used for documentation strings in customization buffers."
1549 :group 'custom-faces)
1551 (defface custom-state-face '((((class color)
1553 (:foreground "lime green"))
1556 (:foreground "dark green"))
1558 "Face used for State descriptions in the customize buffer."
1559 :group 'custom-faces)
1561 (define-widget 'custom 'default
1562 "Customize a user option."
1564 :convert-widget 'custom-convert-widget
1565 :notify 'custom-notify
1568 :custom-state 'hidden
1569 :documentation-property 'widget-subclass-responsibility
1570 :value-create 'widget-subclass-responsibility
1571 :value-delete 'widget-children-value-delete
1572 :value-get 'widget-value-value-get
1573 :validate 'widget-children-validate
1574 :match (lambda (widget value) (symbolp value)))
1576 (defun custom-convert-widget (widget)
1577 ;; Initialize :value and :tag from :args in WIDGET.
1578 (let ((args (widget-get widget :args)))
1580 (widget-put widget :value (widget-apply widget
1581 :value-to-internal (car args)))
1582 (widget-put widget :tag (custom-unlispify-tag-name (car args)))
1583 (widget-put widget :args nil)))
1586 (defun custom-notify (widget &rest args)
1587 "Keep track of changes."
1588 (let ((state (widget-get widget :custom-state)))
1589 (unless (eq state 'modified)
1590 (unless (memq state '(nil unknown hidden))
1591 (widget-put widget :custom-state 'modified))
1592 (custom-magic-reset widget)
1593 (apply 'widget-default-notify widget args))))
1595 (defun custom-redraw (widget)
1596 "Redraw WIDGET with current settings."
1597 (let ((line (count-lines (point-min) (point)))
1598 (column (current-column))
1600 (from (marker-position (widget-get widget :from)))
1601 (to (marker-position (widget-get widget :to))))
1603 (widget-value-set widget (widget-value widget))
1604 (custom-redraw-magic widget))
1605 (when (and (>= pos from) (<= pos to))
1610 (goto-line (1+ line)))
1611 (move-to-column column))
1614 (defun custom-redraw-magic (widget)
1615 "Redraw WIDGET state with current settings."
1617 (let ((magic (widget-get widget :custom-magic)))
1619 (widget-value-set magic (widget-value magic))
1620 (when (setq widget (widget-get widget :group))
1621 (custom-group-state-update widget)))
1623 (setq widget nil)))))
1626 (defun custom-show (widget value)
1627 "Non-nil if WIDGET should be shown with VALUE by default."
1628 (let ((show (widget-get widget :custom-show)))
1634 (funcall show widget value)))))
1636 (defvar custom-load-recursion nil
1637 "Hack to avoid recursive dependencies.")
1639 (defun custom-load-symbol (symbol)
1640 "Load all dependencies for SYMBOL."
1641 (unless custom-load-recursion
1642 (let ((custom-load-recursion t)
1643 (loads (get symbol 'custom-loads))
1646 (setq load (car loads)
1648 (cond ((symbolp load)
1652 ;; Don't reload a file already loaded.
1653 ((and (boundp 'preloaded-file-list)
1654 (member load preloaded-file-list)))
1655 ((assoc load load-history))
1656 ((assoc (locate-library load) load-history))
1659 ;; Without this, we would load cus-edit recursively.
1660 ;; We are still loading it when we call this,
1661 ;; and it is not in load-history yet.
1662 (or (equal load "cus-edit")
1663 (load-library load))
1666 (defun custom-load-widget (widget)
1667 "Load all dependencies for WIDGET."
1668 (custom-load-symbol (widget-value widget)))
1670 (defun custom-unloaded-symbol-p (symbol)
1671 "Return non-nil if the dependencies of SYMBOL has not yet been loaded."
1673 (loads (get symbol 'custom-loads))
1676 (setq load (car loads)
1678 (cond ((symbolp load)
1679 (unless (featurep load)
1681 ((assoc load load-history))
1682 ((assoc (locate-library load) load-history)
1688 (defun custom-unloaded-widget-p (widget)
1689 "Return non-nil if the dependencies of WIDGET has not yet been loaded."
1690 (custom-unloaded-symbol-p (widget-value widget)))
1692 (defun custom-toggle-hide (widget)
1693 "Toggle visibility of WIDGET."
1694 (custom-load-widget widget)
1695 (let ((state (widget-get widget :custom-state)))
1696 (cond ((memq state '(invalid modified))
1697 (error "There are unset changes"))
1699 (widget-put widget :custom-state 'unknown))
1701 (widget-put widget :documentation-shown nil)
1702 (widget-put widget :custom-state 'hidden)))
1703 (custom-redraw widget)
1706 (defun custom-toggle-parent (widget &rest ignore)
1707 "Toggle visibility of parent of WIDGET."
1708 (custom-toggle-hide (widget-get widget :parent)))
1710 (defun custom-add-see-also (widget &optional prefix)
1711 "Add `See also ...' to WIDGET if there are any links.
1712 Insert PREFIX first if non-nil."
1713 (let* ((symbol (widget-get widget :value))
1714 (links (get symbol 'custom-links))
1715 (many (> (length links) 2))
1716 (buttons (widget-get widget :buttons))
1717 (indent (widget-get widget :indent)))
1720 (insert-char ?\ indent))
1723 (insert "See also ")
1725 (push (widget-create-child-and-convert widget (car links))
1727 (setq links (cdr links))
1736 (widget-put widget :buttons buttons))))
1738 (defun custom-add-parent-links (widget &optional initial-string)
1739 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
1740 The value if non-nil if any parents were found.
1741 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
1742 (let ((name (widget-value widget))
1743 (type (widget-type widget))
1744 (buttons (widget-get widget :buttons))
1747 (insert (or initial-string "Parent groups:"))
1748 (mapatoms (lambda (symbol)
1749 (let ((entry (assq name (get symbol 'custom-group))))
1750 (when (eq (nth 1 entry) type)
1752 (push (widget-create-child-and-convert
1753 widget 'custom-group-link
1754 :tag (custom-unlispify-tag-name symbol)
1758 (widget-put widget :buttons buttons)
1761 (delete-region start (point)))
1764 ;;; The `custom-variable' Widget.
1766 (defface custom-variable-tag-face '((((class color)
1768 (:foreground "light blue" :underline t))
1771 (:foreground "blue" :underline t))
1773 "Face used for unpushable variable tags."
1774 :group 'custom-faces)
1776 (defface custom-variable-button-face '((t (:underline t :bold t)))
1777 "Face used for pushable variable tags."
1778 :group 'custom-faces)
1780 (defcustom custom-variable-default-form 'edit
1781 "Default form of displaying variable values."
1782 :type '(choice (const edit)
1784 :group 'custom-buffer)
1786 (define-widget 'custom-variable 'custom
1787 "Customize variable."
1789 :help-echo "Set or reset this variable."
1790 :documentation-property 'variable-documentation
1791 :custom-category 'option
1793 :custom-menu 'custom-variable-menu-create
1794 :custom-form nil ; defaults to value of `custom-variable-default-form'
1795 :value-create 'custom-variable-value-create
1796 :action 'custom-variable-action
1797 :custom-set 'custom-variable-set
1798 :custom-save 'custom-variable-save
1799 :custom-reset-current 'custom-redraw
1800 :custom-reset-saved 'custom-variable-reset-saved
1801 :custom-reset-standard 'custom-variable-reset-standard)
1803 (defun custom-variable-type (symbol)
1804 "Return a widget suitable for editing the value of SYMBOL.
1805 If SYMBOL has a `custom-type' property, use that.
1806 Otherwise, look up symbol in `custom-guess-type-alist'."
1807 (let* ((type (or (get symbol 'custom-type)
1808 (and (not (get symbol 'standard-value))
1809 (custom-guess-type symbol))
1811 (options (get symbol 'custom-options))
1812 (tmp (if (listp type)
1813 (copy-sequence type)
1816 (widget-put tmp :options options))
1819 (defun custom-variable-value-create (widget)
1820 "Here is where you edit the variables value."
1821 (custom-load-widget widget)
1822 (unless (widget-get widget :custom-form)
1823 (widget-put widget :custom-form custom-variable-default-form))
1824 (let* ((buttons (widget-get widget :buttons))
1825 (children (widget-get widget :children))
1826 (form (widget-get widget :custom-form))
1827 (state (widget-get widget :custom-state))
1828 (symbol (widget-get widget :value))
1829 (tag (widget-get widget :tag))
1830 (type (custom-variable-type symbol))
1831 (conv (widget-convert type))
1832 (get (or (get symbol 'custom-get) 'default-value))
1833 (prefix (widget-get widget :custom-prefix))
1834 (last (widget-get widget :custom-last))
1835 (value (if (default-boundp symbol)
1836 (funcall get symbol)
1837 (widget-get conv :value))))
1838 ;; If the widget is new, the child determine whether it is hidden.
1840 ((custom-show type value)
1841 (setq state 'unknown))
1843 (setq state 'hidden)))
1844 ;; If we don't know the state, see if we need to edit it in lisp form.
1845 (when (eq state 'unknown)
1846 (unless (widget-apply conv :match value)
1847 ;; (widget-apply (widget-convert type) :match value)
1848 (setq form 'mismatch)))
1849 ;; Now we can create the child widget.
1850 (cond ((eq custom-buffer-style 'tree)
1851 (insert prefix (if last " `--- " " |--- "))
1852 (push (widget-create-child-and-convert
1853 widget 'custom-browse-variable-tag)
1855 (insert " " tag "\n")
1856 (widget-put widget :buttons buttons))
1858 ;; Indicate hidden value.
1859 (push (widget-create-child-and-convert
1862 :sample-face 'custom-variable-tag-face
1866 (push (widget-create-child-and-convert
1868 :help-echo "Show the value of this option."
1869 :action 'custom-toggle-parent
1872 ((memq form '(lisp mismatch))
1873 ;; In lisp mode edit the saved value when possible.
1874 (let* ((value (cond ((get symbol 'saved-value)
1875 (car (get symbol 'saved-value)))
1876 ((get symbol 'standard-value)
1877 (car (get symbol 'standard-value)))
1878 ((default-boundp symbol)
1879 (custom-quote (funcall get symbol)))
1881 (custom-quote (widget-get conv :value))))))
1882 (insert (symbol-name symbol) ": ")
1883 (push (widget-create-child-and-convert
1885 :help-echo "Hide the value of this option."
1886 :action 'custom-toggle-parent
1890 (push (widget-create-child-and-convert
1892 :button-face 'custom-variable-button-face
1894 :tag (symbol-name symbol)
1900 (let* ((format (widget-get type :format))
1901 tag-format value-format)
1902 (unless (string-match ":" format)
1903 (error "Bad format"))
1904 (setq tag-format (substring format 0 (match-end 0)))
1905 (setq value-format (substring format (match-end 0)))
1906 (push (widget-create-child-and-convert
1909 :action 'custom-tag-action
1910 :help-echo "Change value of this option."
1911 :mouse-down-action 'custom-tag-mouse-down-action
1912 :button-face 'custom-variable-button-face
1913 :sample-face 'custom-variable-tag-face
1917 (push (widget-create-child-and-convert
1919 :help-echo "Hide the value of this option."
1920 :action 'custom-toggle-parent
1923 (push (widget-create-child-and-convert
1925 :format value-format
1928 (unless (eq custom-buffer-style 'tree)
1929 ;; Now update the state.
1930 (unless (eq (preceding-char) ?\n)
1931 (widget-insert "\n"))
1932 (if (eq state 'hidden)
1933 (widget-put widget :custom-state state)
1934 (custom-variable-state-set widget))
1935 ;; Create the magic button.
1936 (let ((magic (widget-create-child-and-convert
1937 widget 'custom-magic nil)))
1938 (widget-put widget :custom-magic magic)
1939 (push magic buttons))
1940 ;; Update properties.
1941 (widget-put widget :custom-form form)
1942 (widget-put widget :buttons buttons)
1943 (widget-put widget :children children)
1944 ;; Insert documentation.
1945 (widget-default-format-handler widget ?h)
1947 (unless (eq state 'hidden)
1948 (when (eq (widget-get widget :custom-level) 1)
1949 (custom-add-parent-links widget))
1950 (custom-add-see-also widget)))))
1952 (defun custom-tag-action (widget &rest args)
1953 "Pass :action to first child of WIDGET's parent."
1954 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
1957 (defun custom-tag-mouse-down-action (widget &rest args)
1958 "Pass :mouse-down-action to first child of WIDGET's parent."
1959 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
1960 :mouse-down-action args))
1962 (defun custom-variable-state-set (widget)
1963 "Set the state of WIDGET."
1964 (let* ((symbol (widget-value widget))
1965 (get (or (get symbol 'custom-get) 'default-value))
1966 (value (if (default-boundp symbol)
1967 (funcall get symbol)
1968 (widget-get widget :value)))
1970 (state (cond ((setq tmp (get symbol 'customized-value))
1971 (if (condition-case nil
1972 (equal value (eval (car tmp)))
1976 ((setq tmp (get symbol 'saved-value))
1977 (if (condition-case nil
1978 (equal value (eval (car tmp)))
1982 ((setq tmp (get symbol 'standard-value))
1983 (if (condition-case nil
1984 (equal value (eval (car tmp)))
1989 (widget-put widget :custom-state state)))
1991 (defvar custom-variable-menu
1992 '(("Set for Current Session" custom-variable-set
1994 (eq (widget-get widget :custom-state) 'modified)))
1995 ("Save for Future Sessions" custom-variable-save
1997 (memq (widget-get widget :custom-state) '(modified set changed rogue))))
1998 ("Reset to Current" custom-redraw
2000 (and (default-boundp (widget-value widget))
2001 (memq (widget-get widget :custom-state) '(modified changed)))))
2002 ("Reset to Saved" custom-variable-reset-saved
2004 (and (get (widget-value widget) 'saved-value)
2005 (memq (widget-get widget :custom-state)
2006 '(modified set changed rogue)))))
2007 ("Reset to Standard Settings" custom-variable-reset-standard
2009 (and (get (widget-value widget) 'standard-value)
2010 (memq (widget-get widget :custom-state)
2011 '(modified set changed saved rogue)))))
2012 ("---" ignore ignore)
2013 ("Don't show as Lisp expression" custom-variable-edit
2015 (eq (widget-get widget :custom-form) 'lisp)))
2016 ("Show initial Lisp expression" custom-variable-edit-lisp
2018 (eq (widget-get widget :custom-form) 'edit))))
2019 "Alist of actions for the `custom-variable' widget.
2020 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2021 the menu entry, ACTION is the function to call on the widget when the
2022 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2023 widget as an argument, and returns non-nil if ACTION is valid on that
2024 widget. If FILTER is nil, ACTION is always valid.")
2026 (defun custom-variable-action (widget &optional event)
2027 "Show the menu for `custom-variable' WIDGET.
2028 Optional EVENT is the location for the menu."
2029 (if (eq (widget-get widget :custom-state) 'hidden)
2030 (custom-toggle-hide widget)
2031 (unless (eq (widget-get widget :custom-state) 'modified)
2032 (custom-variable-state-set widget))
2033 (custom-redraw-magic widget)
2034 (let* ((completion-ignore-case t)
2035 (answer (widget-choose (concat "Operation on "
2036 (custom-unlispify-tag-name
2037 (widget-get widget :value)))
2038 (custom-menu-filter custom-variable-menu
2042 (funcall answer widget)))))
2044 (defun custom-variable-edit (widget)
2045 "Edit value of WIDGET."
2046 (widget-put widget :custom-state 'unknown)
2047 (widget-put widget :custom-form 'edit)
2048 (custom-redraw widget))
2050 (defun custom-variable-edit-lisp (widget)
2051 "Edit the lisp representation of the value of WIDGET."
2052 (widget-put widget :custom-state 'unknown)
2053 (widget-put widget :custom-form 'lisp)
2054 (custom-redraw widget))
2056 (defun custom-variable-set (widget)
2057 "Set the current value for the variable being edited by WIDGET."
2058 (let* ((form (widget-get widget :custom-form))
2059 (state (widget-get widget :custom-state))
2060 (child (car (widget-get widget :children)))
2061 (symbol (widget-value widget))
2062 (set (or (get symbol 'custom-set) 'set-default))
2064 (cond ((eq state 'hidden)
2065 (error "Cannot set hidden variable"))
2066 ((setq val (widget-apply child :validate))
2067 (goto-char (widget-get val :from))
2068 (error "%s" (widget-get val :error)))
2069 ((memq form '(lisp mismatch))
2070 (funcall set symbol (eval (setq val (widget-value child))))
2071 (put symbol 'customized-value (list val)))
2073 (funcall set symbol (setq val (widget-value child)))
2074 (put symbol 'customized-value (list (custom-quote val)))))
2075 (custom-variable-state-set widget)
2076 (custom-redraw-magic widget)))
2078 (defun custom-variable-save (widget)
2079 "Set and save the value for the variable being edited by WIDGET."
2080 (let* ((form (widget-get widget :custom-form))
2081 (state (widget-get widget :custom-state))
2082 (child (car (widget-get widget :children)))
2083 (symbol (widget-value widget))
2084 (set (or (get symbol 'custom-set) 'set-default))
2086 (cond ((eq state 'hidden)
2087 (error "Cannot set hidden variable"))
2088 ((setq val (widget-apply child :validate))
2089 (goto-char (widget-get val :from))
2090 (error "%s" (widget-get val :error)))
2091 ((memq form '(lisp mismatch))
2092 (put symbol 'saved-value (list (widget-value child)))
2093 (funcall set symbol (eval (widget-value child))))
2096 'saved-value (list (custom-quote (widget-value
2098 (funcall set symbol (widget-value child))))
2099 (put symbol 'customized-value nil)
2101 (custom-variable-state-set widget)
2102 (custom-redraw-magic widget)))
2104 (defun custom-variable-reset-saved (widget)
2105 "Restore the saved value for the variable being edited by WIDGET."
2106 (let* ((symbol (widget-value widget))
2107 (set (or (get symbol 'custom-set) 'set-default)))
2108 (if (get symbol 'saved-value)
2110 (funcall set symbol (eval (car (get symbol 'saved-value))))
2112 (error "No saved value for %s" symbol))
2113 (put symbol 'customized-value nil)
2114 (widget-put widget :custom-state 'unknown)
2115 (custom-redraw widget)))
2117 (defun custom-variable-reset-standard (widget)
2118 "Restore the standard setting for the variable being edited by WIDGET."
2119 (let* ((symbol (widget-value widget))
2120 (set (or (get symbol 'custom-set) 'set-default)))
2121 (if (get symbol 'standard-value)
2122 (funcall set symbol (eval (car (get symbol 'standard-value))))
2123 (error "No standard setting known for %S" symbol))
2124 (put symbol 'customized-value nil)
2125 (when (get symbol 'saved-value)
2126 (put symbol 'saved-value nil)
2128 (widget-put widget :custom-state 'unknown)
2129 (custom-redraw widget)))
2131 ;;; The `custom-face-edit' Widget.
2133 (define-widget 'custom-face-edit 'checklist
2134 "Edit face attributes."
2138 :button-args '(:help-echo "Control whether this attribute have any effect.")
2139 :args (mapcar (lambda (att)
2142 :sibling-args (widget-get (nth 1 att) :sibling-args)
2143 (list 'const :format "" :value (nth 0 att))
2145 custom-face-attributes))
2147 ;;; The `custom-display' Widget.
2149 (define-widget 'custom-display 'menu-choice
2150 "Select a display type."
2153 :help-echo "Specify frames where the face attributes should be used."
2154 :args '((const :tag "all" t)
2158 :args ((group :sibling-args (:help-echo "\
2159 Only match the specified window systems.")
2160 (const :format "Type: "
2162 (checklist :inline t
2165 :sibling-args (:help-echo "\
2166 The X11 Window System.")
2168 (const :format "PM "
2169 :sibling-args (:help-echo "\
2170 OS/2 Presentation Manager.")
2172 (const :format "W32 "
2173 :sibling-args (:help-echo "\
2176 (const :format "DOS "
2177 :sibling-args (:help-echo "\
2180 (const :format "TTY%n"
2181 :sibling-args (:help-echo "\
2182 Plain text terminals.")
2184 (group :sibling-args (:help-echo "\
2185 Only match the frames with the specified color support.")
2186 (const :format "Class: "
2188 (checklist :inline t
2190 (const :format "Color "
2191 :sibling-args (:help-echo "\
2192 Match color frames.")
2194 (const :format "Grayscale "
2195 :sibling-args (:help-echo "\
2196 Match grayscale frames.")
2198 (const :format "Monochrome%n"
2199 :sibling-args (:help-echo "\
2200 Match frames with no color support.")
2202 (group :sibling-args (:help-echo "\
2203 Only match frames with the specified intensity.")
2205 Background brightness: "
2207 (checklist :inline t
2209 (const :format "Light "
2210 :sibling-args (:help-echo "\
2211 Match frames with light backgrounds.")
2213 (const :format "Dark\n"
2214 :sibling-args (:help-echo "\
2215 Match frames with dark backgrounds.")
2218 ;;; The `custom-face' Widget.
2220 (defface custom-face-tag-face '((t (:underline t)))
2221 "Face used for face tags."
2222 :group 'custom-faces)
2224 (defcustom custom-face-default-form 'selected
2225 "Default form of displaying face definition."
2226 :type '(choice (const all)
2229 :group 'custom-buffer)
2231 (define-widget 'custom-face 'custom
2233 :sample-face 'custom-face-tag-face
2234 :help-echo "Set or reset this face."
2235 :documentation-property '(lambda (face)
2236 (face-doc-string face))
2237 :value-create 'custom-face-value-create
2238 :action 'custom-face-action
2239 :custom-category 'face
2240 :custom-form nil ; defaults to value of `custom-face-default-form'
2241 :custom-set 'custom-face-set
2242 :custom-save 'custom-face-save
2243 :custom-reset-current 'custom-redraw
2244 :custom-reset-saved 'custom-face-reset-saved
2245 :custom-reset-standard 'custom-face-reset-standard
2246 :custom-menu 'custom-face-menu-create)
2248 (define-widget 'custom-face-all 'editable-list
2249 "An editable list of display specifications and attributes."
2250 :entry-format "%i %d %v"
2251 :insert-button-args '(:help-echo "Insert new display specification here.")
2252 :append-button-args '(:help-echo "Append new display specification here.")
2253 :delete-button-args '(:help-echo "Delete this display specification.")
2254 :args '((group :format "%v" custom-display custom-face-edit)))
2256 (defconst custom-face-all (widget-convert 'custom-face-all)
2257 "Converted version of the `custom-face-all' widget.")
2259 (define-widget 'custom-display-unselected 'item
2260 "A display specification that doesn't match the selected display."
2261 :match 'custom-display-unselected-match)
2263 (defun custom-display-unselected-match (widget value)
2264 "Non-nil if VALUE is an unselected display specification."
2265 (not (face-spec-set-match-display value (selected-frame))))
2267 (define-widget 'custom-face-selected 'group
2268 "Edit the attributes of the selected display in a face specification."
2269 :args '((repeat :format ""
2271 (group custom-display-unselected sexp))
2272 (group (sexp :format "") custom-face-edit)
2277 (defconst custom-face-selected (widget-convert 'custom-face-selected)
2278 "Converted version of the `custom-face-selected' widget.")
2280 (defun custom-face-value-create (widget)
2281 "Create a list of the display specifications for WIDGET."
2282 (let ((buttons (widget-get widget :buttons))
2283 (symbol (widget-get widget :value))
2284 (tag (widget-get widget :tag))
2285 (state (widget-get widget :custom-state))
2287 (is-last (widget-get widget :custom-last))
2288 (prefix (widget-get widget :custom-prefix)))
2290 (setq tag (prin1-to-string symbol)))
2291 (cond ((eq custom-buffer-style 'tree)
2292 (insert prefix (if is-last " `--- " " |--- "))
2293 (push (widget-create-child-and-convert
2294 widget 'custom-browse-face-tag)
2296 (insert " " tag "\n")
2297 (widget-put widget :buttons buttons))
2301 (if (eq custom-buffer-style 'face)
2303 (widget-specify-sample widget begin (point))
2306 (and (string-match "XEmacs" emacs-version)
2307 ;; XEmacs cannot display uninitialized faces.
2308 (not (custom-facep symbol))
2309 (copy-face 'custom-face-empty symbol))
2310 (push (widget-create-child-and-convert widget 'item
2317 (push (widget-create-child-and-convert
2319 :help-echo "Hide or show this face."
2320 :action 'custom-toggle-parent
2321 (not (eq state 'hidden)))
2325 (let ((magic (widget-create-child-and-convert
2326 widget 'custom-magic nil)))
2327 (widget-put widget :custom-magic magic)
2328 (push magic buttons))
2330 (widget-put widget :buttons buttons)
2331 ;; Insert documentation.
2332 (widget-default-format-handler widget ?h)
2334 (unless (eq state 'hidden)
2335 (when (eq (widget-get widget :custom-level) 1)
2336 (custom-add-parent-links widget))
2337 (custom-add-see-also widget))
2339 (unless (eq (preceding-char) ?\n)
2341 (unless (eq state 'hidden)
2342 (message "Creating face editor...")
2343 (custom-load-widget widget)
2344 (unless (widget-get widget :custom-form)
2345 (widget-put widget :custom-form custom-face-default-form))
2346 (let* ((symbol (widget-value widget))
2347 (spec (or (get symbol 'saved-face)
2348 (get symbol 'face-defface-spec)
2349 ;; Attempt to construct it.
2350 (list (list t (custom-face-attributes-get
2351 symbol (selected-frame))))))
2352 (form (widget-get widget :custom-form))
2353 (indent (widget-get widget :indent))
2355 ;; If the user has changed this face in some other way,
2356 ;; edit it as the user has specified it.
2357 (if (not (face-spec-match-p symbol spec (selected-frame)))
2358 (setq spec (list (list t (face-attr-construct symbol (selected-frame))))))
2359 (setq edit (widget-create-child-and-convert
2361 (cond ((and (eq form 'selected)
2362 (widget-apply custom-face-selected
2364 (when indent (insert-char ?\ indent))
2365 'custom-face-selected)
2366 ((and (not (eq form 'lisp))
2367 (widget-apply custom-face-all
2371 (when indent (insert-char ?\ indent))
2374 (custom-face-state-set widget)
2375 (widget-put widget :children (list edit)))
2376 (message "Creating face editor...done"))))))
2378 (defvar custom-face-menu
2379 '(("Set for Current Session" custom-face-set)
2380 ("Save for Future Sessions" custom-face-save-command)
2381 ("Reset to Saved" custom-face-reset-saved
2383 (get (widget-value widget) 'saved-face)))
2384 ("Reset to Standard Setting" custom-face-reset-standard
2386 (get (widget-value widget) 'face-defface-spec)))
2387 ("---" ignore ignore)
2388 ("Show all display specs" custom-face-edit-all
2390 (not (eq (widget-get widget :custom-form) 'all))))
2391 ("Just current attributes" custom-face-edit-selected
2393 (not (eq (widget-get widget :custom-form) 'selected))))
2394 ("Show as Lisp expression" custom-face-edit-lisp
2396 (not (eq (widget-get widget :custom-form) 'lisp)))))
2397 "Alist of actions for the `custom-face' widget.
2398 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2399 the menu entry, ACTION is the function to call on the widget when the
2400 menu is selected, and FILTER is a predicate which takes a `custom-face'
2401 widget as an argument, and returns non-nil if ACTION is valid on that
2402 widget. If FILTER is nil, ACTION is always valid.")
2404 (defun custom-face-edit-selected (widget)
2405 "Edit selected attributes of the value of WIDGET."
2406 (widget-put widget :custom-state 'unknown)
2407 (widget-put widget :custom-form 'selected)
2408 (custom-redraw widget))
2410 (defun custom-face-edit-all (widget)
2411 "Edit all attributes of the value of WIDGET."
2412 (widget-put widget :custom-state 'unknown)
2413 (widget-put widget :custom-form 'all)
2414 (custom-redraw widget))
2416 (defun custom-face-edit-lisp (widget)
2417 "Edit the lisp representation of the value of WIDGET."
2418 (widget-put widget :custom-state 'unknown)
2419 (widget-put widget :custom-form 'lisp)
2420 (custom-redraw widget))
2422 (defun custom-face-state-set (widget)
2423 "Set the state of WIDGET."
2424 (let ((symbol (widget-value widget)))
2425 (widget-put widget :custom-state (cond ((get symbol 'customized-face)
2427 ((get symbol 'saved-face)
2429 ((get symbol 'face-defface-spec)
2434 (defun custom-face-action (widget &optional event)
2435 "Show the menu for `custom-face' WIDGET.
2436 Optional EVENT is the location for the menu."
2437 (if (eq (widget-get widget :custom-state) 'hidden)
2438 (custom-toggle-hide widget)
2439 (let* ((completion-ignore-case t)
2440 (symbol (widget-get widget :value))
2441 (answer (widget-choose (concat "Operation on "
2442 (custom-unlispify-tag-name symbol))
2443 (custom-menu-filter custom-face-menu
2447 (funcall answer widget)))))
2449 (defun custom-face-set (widget)
2450 "Make the face attributes in WIDGET take effect."
2451 (let* ((symbol (widget-value widget))
2452 (child (car (widget-get widget :children)))
2453 (value (widget-value child)))
2454 (put symbol 'customized-face value)
2455 (face-spec-set symbol value)
2456 (custom-face-state-set widget)
2457 (custom-redraw-magic widget)))
2459 (defun custom-face-save-command (widget)
2460 "Save in `.emacs' the face attributes in WIDGET."
2461 (custom-face-save widget)
2464 (defun custom-face-save (widget)
2465 "Prepare for saving WIDGET's face attributes, but don't write `.emacs'."
2466 (let* ((symbol (widget-value widget))
2467 (child (car (widget-get widget :children)))
2468 (value (widget-value child)))
2469 (face-spec-set symbol value)
2470 (put symbol 'saved-face value)
2471 (put symbol 'customized-face nil)
2473 (custom-face-state-set widget)
2474 (custom-redraw-magic widget)))
2476 (defun custom-face-reset-saved (widget)
2477 "Restore WIDGET to the face's default attributes."
2478 (let* ((symbol (widget-value widget))
2479 (child (car (widget-get widget :children)))
2480 (value (get symbol 'saved-face)))
2482 (error "No saved value for this face"))
2483 (put symbol 'customized-face nil)
2484 (face-spec-set symbol value)
2485 (widget-value-set child value)
2486 (custom-face-state-set widget)
2487 (custom-redraw-magic widget)))
2489 (defun custom-face-reset-standard (widget)
2490 "Restore WIDGET to the face's standard settings."
2491 (let* ((symbol (widget-value widget))
2492 (child (car (widget-get widget :children)))
2493 (value (get symbol 'face-defface-spec)))
2495 (error "No standard setting for this face"))
2496 (put symbol 'customized-face nil)
2497 (when (get symbol 'saved-face)
2498 (put symbol 'saved-face nil)
2500 (face-spec-set symbol value)
2501 (widget-value-set child value)
2502 (custom-face-state-set widget)
2503 (custom-redraw-magic widget)))
2505 ;;; The `face' Widget.
2507 (define-widget 'face 'default
2508 "Select and customize a face."
2509 :convert-widget 'widget-value-convert-widget
2510 :button-prefix 'widget-push-button-prefix
2511 :button-suffix 'widget-push-button-suffix
2512 :format "%t: %[select face%] %v"
2515 :value-create 'widget-face-value-create
2516 :value-delete 'widget-face-value-delete
2517 :value-get 'widget-value-value-get
2518 :validate 'widget-children-validate
2519 :action 'widget-face-action
2520 :match '(lambda (widget value) (symbolp value)))
2522 (defun widget-face-value-create (widget)
2523 ;; Create a `custom-face' child.
2524 (let* ((symbol (widget-value widget))
2525 (custom-buffer-style 'face)
2526 (child (widget-create-child-and-convert
2530 (custom-magic-reset child)
2531 (setq custom-options (cons child custom-options))
2532 (widget-put widget :children (list child))))
2534 (defun widget-face-value-delete (widget)
2535 ;; Remove the child from the options.
2536 (let ((child (car (widget-get widget :children))))
2537 (setq custom-options (delq child custom-options))
2538 (widget-children-value-delete widget)))
2540 (defvar face-history nil
2541 "History of entered face names.")
2543 (defun widget-face-action (widget &optional event)
2544 "Prompt for a face."
2545 (let ((answer (completing-read "Face: "
2546 (mapcar (lambda (face)
2547 (list (symbol-name face)))
2551 (unless (zerop (length answer))
2552 (widget-value-set widget (intern answer))
2553 (widget-apply widget :notify widget event)
2556 ;;; The `hook' Widget.
2558 (define-widget 'hook 'list
2560 :value-to-internal (lambda (widget value)
2561 (if (and value (symbolp value))
2564 :match (lambda (widget value)
2566 (widget-group-match widget value)))
2567 :convert-widget 'custom-hook-convert-widget
2570 (defun custom-hook-convert-widget (widget)
2571 ;; Handle `:custom-options'.
2572 (let* ((options (widget-get widget :options))
2573 (other `(editable-list :inline t
2574 :entry-format "%i %d%v"
2575 (function :format " %v")))
2577 (list `(checklist :inline t
2578 ,@(mapcar (lambda (entry)
2579 `(function-item ,entry))
2583 (widget-put widget :args args)
2586 ;;; The `custom-group-link' Widget.
2588 (define-widget 'custom-group-link 'link
2589 "Show parent in other window when activated."
2590 :help-echo "Create customization buffer for this group."
2591 :action 'custom-group-link-action)
2593 (defun custom-group-link-action (widget &rest ignore)
2594 (customize-group (widget-value widget)))
2596 ;;; The `custom-group' Widget.
2598 (defcustom custom-group-tag-faces nil
2599 ;; In XEmacs, this ought to play games with font size.
2600 "Face used for group tags.
2601 The first member is used for level 1 groups, the second for level 2,
2602 and so forth. The remaining group tags are shown with
2603 `custom-group-tag-face'."
2604 :type '(repeat face)
2605 :group 'custom-faces)
2607 (defface custom-group-tag-face-1 '((((class color)
2609 (:foreground "pink" :underline t))
2612 (:foreground "red" :underline t))
2614 "Face used for group tags.")
2616 (defface custom-group-tag-face '((((class color)
2618 (:foreground "light blue" :underline t))
2621 (:foreground "blue" :underline t))
2623 "Face used for low level group tags."
2624 :group 'custom-faces)
2626 (define-widget 'custom-group 'custom
2629 :sample-face-get 'custom-group-sample-face-get
2630 :documentation-property 'group-documentation
2631 :help-echo "Set or reset all members of this group."
2632 :value-create 'custom-group-value-create
2633 :action 'custom-group-action
2634 :custom-category 'group
2635 :custom-set 'custom-group-set
2636 :custom-save 'custom-group-save
2637 :custom-reset-current 'custom-group-reset-current
2638 :custom-reset-saved 'custom-group-reset-saved
2639 :custom-reset-standard 'custom-group-reset-standard
2640 :custom-menu 'custom-group-menu-create)
2642 (defun custom-group-sample-face-get (widget)
2643 ;; Use :sample-face.
2644 (or (nth (1- (widget-get widget :custom-level)) custom-group-tag-faces)
2645 'custom-group-tag-face))
2647 (define-widget 'custom-group-visibility 'visibility
2648 "An indicator and manipulator for hidden group contents."
2649 :create 'custom-group-visibility-create)
2651 (defun custom-group-visibility-create (widget)
2652 (let ((visible (widget-value widget)))
2654 (insert "--------")))
2655 (widget-default-create widget))
2657 (defun custom-group-members (symbol groups-only)
2658 "Return SYMBOL's custom group members.
2659 If GROUPS-ONLY non-nil, return only those members that are groups."
2660 (if (not groups-only)
2661 (get symbol 'custom-group)
2663 (dolist (entry (get symbol 'custom-group))
2664 (when (eq (nth 1 entry) 'custom-group)
2665 (push entry members)))
2666 (nreverse members))))
2668 (defun custom-group-value-create (widget)
2669 "Insert a customize group for WIDGET in the current buffer."
2670 (let* ((state (widget-get widget :custom-state))
2671 (level (widget-get widget :custom-level))
2672 ;; (indent (widget-get widget :indent))
2673 (prefix (widget-get widget :custom-prefix))
2674 (buttons (widget-get widget :buttons))
2675 (tag (widget-get widget :tag))
2676 (symbol (widget-value widget))
2677 (members (custom-group-members symbol
2678 (and (eq custom-buffer-style 'tree)
2679 custom-browse-only-groups))))
2680 (cond ((and (eq custom-buffer-style 'tree)
2682 (or members (custom-unloaded-widget-p widget)))
2683 (custom-browse-insert-prefix prefix)
2684 (push (widget-create-child-and-convert
2685 widget 'custom-browse-visibility
2686 ;; :tag-glyph "plus"
2690 ;; (widget-glyph-insert nil "-- " "horizontal")
2691 (push (widget-create-child-and-convert
2692 widget 'custom-browse-group-tag)
2694 (insert " " tag "\n")
2695 (widget-put widget :buttons buttons))
2696 ((and (eq custom-buffer-style 'tree)
2697 (zerop (length members)))
2698 (custom-browse-insert-prefix prefix)
2700 ;; (widget-glyph-insert nil "[ ]" "empty")
2701 ;; (widget-glyph-insert nil "-- " "horizontal")
2702 (push (widget-create-child-and-convert
2703 widget 'custom-browse-group-tag)
2705 (insert " " tag "\n")
2706 (widget-put widget :buttons buttons))
2707 ((eq custom-buffer-style 'tree)
2708 (custom-browse-insert-prefix prefix)
2709 (custom-load-widget widget)
2710 (if (zerop (length members))
2712 (custom-browse-insert-prefix prefix)
2714 ;; (widget-glyph-insert nil "[ ]" "empty")
2715 ;; (widget-glyph-insert nil "-- " "horizontal")
2716 (push (widget-create-child-and-convert
2717 widget 'custom-browse-group-tag)
2719 (insert " " tag "\n")
2720 (widget-put widget :buttons buttons))
2721 (push (widget-create-child-and-convert
2722 widget 'custom-browse-visibility
2723 ;; :tag-glyph "minus"
2727 ;; (widget-glyph-insert nil "-\\ " "top")
2728 (push (widget-create-child-and-convert
2729 widget 'custom-browse-group-tag)
2731 (insert " " tag "\n")
2732 (widget-put widget :buttons buttons)
2733 (message "Creating group...")
2734 (let* ((members (custom-sort-items members
2735 custom-browse-sort-alphabetically
2736 custom-browse-order-groups))
2737 (prefixes (widget-get widget :custom-prefixes))
2738 (custom-prefix-list (custom-prefix-add symbol prefixes))
2739 (extra-prefix (if (widget-get widget :custom-last)
2742 (prefix (concat prefix extra-prefix))
2745 (setq entry (car members)
2746 members (cdr members))
2747 (push (widget-create-child-and-convert
2748 widget (nth 1 entry)
2750 :tag (custom-unlispify-tag-name (nth 0 entry))
2751 :custom-prefixes custom-prefix-list
2752 :custom-level (1+ level)
2753 :custom-last (null members)
2754 :value (nth 0 entry)
2755 :custom-prefix prefix)
2757 (widget-put widget :children (reverse children)))
2758 (message "Creating group...done")))
2761 ;; Create level indicator.
2762 (unless (eq custom-buffer-style 'links)
2763 (insert-char ?\ (* custom-buffer-indent (1- level)))
2766 (let ((begin (point)))
2768 (widget-specify-sample widget begin (point)))
2770 ;; Create link/visibility indicator.
2771 (if (eq custom-buffer-style 'links)
2772 (push (widget-create-child-and-convert
2773 widget 'custom-group-link
2777 (push (widget-create-child-and-convert
2778 widget 'custom-group-visibility
2779 :help-echo "Show members of this group."
2780 :action 'custom-toggle-parent
2781 (not (eq state 'hidden)))
2784 ;; Create magic button.
2785 (let ((magic (widget-create-child-and-convert
2786 widget 'custom-magic nil)))
2787 (widget-put widget :custom-magic magic)
2788 (push magic buttons))
2790 (widget-put widget :buttons buttons)
2791 ;; Insert documentation.
2792 (if (and (eq custom-buffer-style 'links) (> level 1))
2793 (widget-put widget :documentation-indent 0))
2794 (widget-default-format-handler widget ?h))
2797 ;; Add parent groups references above the group.
2798 (if t ;;; This should test that the buffer
2799 ;;; was made to display a group.
2801 (if (custom-add-parent-links widget
2802 "Go to parent group:")
2804 ;; Create level indicator.
2805 (insert-char ?\ (* custom-buffer-indent (1- level)))
2808 (let ((start (point)))
2810 (widget-specify-sample widget start (point)))
2812 ;; Create visibility indicator.
2813 (unless (eq custom-buffer-style 'links)
2815 (push (widget-create-child-and-convert
2817 :help-echo "Hide members of this group."
2818 :action 'custom-toggle-parent
2819 (not (eq state 'hidden)))
2822 ;; Create more dashes.
2823 ;; Use 76 instead of 75 to compensate for the temporary "<"
2824 ;; added by `widget-insert'.
2825 (insert-char ?- (- 76 (current-column)
2826 (* custom-buffer-indent level)))
2828 ;; Create magic button.
2829 (let ((magic (widget-create-child-and-convert
2830 widget 'custom-magic
2833 (widget-put widget :custom-magic magic)
2834 (push magic buttons))
2836 (widget-put widget :buttons buttons)
2837 ;; Insert documentation.
2838 (widget-default-format-handler widget ?h)
2840 (if nil ;;; This should test that the buffer
2841 ;;; was not made to display a group.
2843 (insert-char ?\ custom-buffer-indent)
2844 (custom-add-parent-links widget)))
2845 (custom-add-see-also widget
2846 (make-string (* custom-buffer-indent level)
2849 (message "Creating group...")
2850 (custom-load-widget widget)
2851 (let* ((members (custom-sort-items members
2852 custom-buffer-sort-alphabetically
2853 custom-buffer-order-groups))
2854 (prefixes (widget-get widget :custom-prefixes))
2855 (custom-prefix-list (custom-prefix-add symbol prefixes))
2856 (length (length members))
2858 (children (mapcar (lambda (entry)
2859 (widget-insert "\n")
2861 Creating group members... %2d%%"
2862 (/ (* 100.0 count) length))
2863 (setq count (1+ count))
2865 (widget-create-child-and-convert
2866 widget (nth 1 entry)
2868 :tag (custom-unlispify-tag-name
2870 :custom-prefixes custom-prefix-list
2871 :custom-level (1+ level)
2872 :value (nth 0 entry))
2873 (unless (eq (preceding-char) ?\n)
2874 (widget-insert "\n"))))
2876 (message "Creating group magic...")
2877 (mapcar 'custom-magic-reset children)
2878 (message "Creating group state...")
2879 (widget-put widget :children children)
2880 (custom-group-state-update widget)
2881 (message "Creating group... done"))
2884 (insert-char ?\ (* custom-buffer-indent (1- level)))
2885 (insert "\\- " (widget-get widget :tag) " group end ")
2886 (insert-char ?- (- 75 (current-column) (* custom-buffer-indent level)))
2889 (defvar custom-group-menu
2890 '(("Set for Current Session" custom-group-set
2892 (eq (widget-get widget :custom-state) 'modified)))
2893 ("Save for Future Sessions" custom-group-save
2895 (memq (widget-get widget :custom-state) '(modified set))))
2896 ("Reset to Current" custom-group-reset-current
2898 (memq (widget-get widget :custom-state) '(modified))))
2899 ("Reset to Saved" custom-group-reset-saved
2901 (memq (widget-get widget :custom-state) '(modified set))))
2902 ("Reset to standard setting" custom-group-reset-standard
2904 (memq (widget-get widget :custom-state) '(modified set saved)))))
2905 "Alist of actions for the `custom-group' widget.
2906 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2907 the menu entry, ACTION is the function to call on the widget when the
2908 menu is selected, and FILTER is a predicate which takes a `custom-group'
2909 widget as an argument, and returns non-nil if ACTION is valid on that
2910 widget. If FILTER is nil, ACTION is always valid.")
2912 (defun custom-group-action (widget &optional event)
2913 "Show the menu for `custom-group' WIDGET.
2914 Optional EVENT is the location for the menu."
2915 (if (eq (widget-get widget :custom-state) 'hidden)
2916 (custom-toggle-hide widget)
2917 (let* ((completion-ignore-case t)
2918 (answer (widget-choose (concat "Operation on "
2919 (custom-unlispify-tag-name
2920 (widget-get widget :value)))
2921 (custom-menu-filter custom-group-menu
2925 (funcall answer widget)))))
2927 (defun custom-group-set (widget)
2928 "Set changes in all modified group members."
2929 (let ((children (widget-get widget :children)))
2930 (mapcar (lambda (child)
2931 (when (eq (widget-get child :custom-state) 'modified)
2932 (widget-apply child :custom-set)))
2935 (defun custom-group-save (widget)
2936 "Save all modified group members."
2937 (let ((children (widget-get widget :children)))
2938 (mapcar (lambda (child)
2939 (when (memq (widget-get child :custom-state) '(modified set))
2940 (widget-apply child :custom-save)))
2943 (defun custom-group-reset-current (widget)
2944 "Reset all modified group members."
2945 (let ((children (widget-get widget :children)))
2946 (mapcar (lambda (child)
2947 (when (eq (widget-get child :custom-state) 'modified)
2948 (widget-apply child :custom-reset-current)))
2951 (defun custom-group-reset-saved (widget)
2952 "Reset all modified or set group members."
2953 (let ((children (widget-get widget :children)))
2954 (mapcar (lambda (child)
2955 (when (memq (widget-get child :custom-state) '(modified set))
2956 (widget-apply child :custom-reset-saved)))
2959 (defun custom-group-reset-standard (widget)
2960 "Reset all modified, set, or saved group members."
2961 (let ((children (widget-get widget :children)))
2962 (mapcar (lambda (child)
2963 (when (memq (widget-get child :custom-state)
2964 '(modified set saved))
2965 (widget-apply child :custom-reset-standard)))
2968 (defun custom-group-state-update (widget)
2970 (unless (eq (widget-get widget :custom-state) 'hidden)
2971 (let* ((children (widget-get widget :children))
2972 (states (mapcar (lambda (child)
2973 (widget-get child :custom-state))
2975 (magics custom-magic-alist)
2978 (let ((magic (car (car magics))))
2979 (if (and (not (eq magic 'hidden))
2980 (memq magic states))
2983 (setq magics (cdr magics)))))
2984 (widget-put widget :custom-state found)))
2985 (custom-magic-reset widget))
2987 ;;; The `custom-save-all' Function.
2989 (defcustom custom-file nil
2990 "File used for storing customization information.
2991 The default is nil, which means to use your init file
2992 as specified by `user-init-file'. If you specify some other file,
2993 you need to explicitly load that file for the settings to take effect."
2994 :type '(choice (const :tag "Your Emacs init file" nil) file)
2997 (defun custom-file ()
2998 "Return the file name for saving customizations."
3002 (read-file-name "File for customizations: "
3003 "~/" nil nil ".emacs"))))
3005 (defun custom-save-delete (symbol)
3006 "Delete the call to SYMBOL from `custom-file'.
3007 Leave point at the location of the call, or after the last expression."
3008 (let ((default-major-mode))
3009 (set-buffer (find-file-noselect (custom-file))))
3010 (goto-char (point-min))
3013 (let ((sexp (condition-case nil
3014 (read (current-buffer))
3015 (end-of-file (throw 'found nil)))))
3016 (when (and (listp sexp)
3017 (eq (car sexp) symbol))
3018 (delete-region (save-excursion
3022 (throw 'found nil))))))
3024 (defun custom-save-variables ()
3025 "Save all customized variables in `custom-file'."
3027 (custom-save-delete 'custom-set-variables)
3028 (let ((standard-output (current-buffer)))
3031 (princ "(custom-set-variables")
3032 (mapatoms (lambda (symbol)
3033 (let ((value (get symbol 'saved-value))
3034 (requests (get symbol 'custom-requests))
3035 (now (not (or (get symbol 'standard-value)
3036 (and (not (boundp symbol))
3037 (not (get symbol 'force-value)))))))
3054 (unless (looking-at "\n")
3057 (defun custom-save-faces ()
3058 "Save all customized faces in `custom-file'."
3060 (custom-save-delete 'custom-set-faces)
3061 (let ((standard-output (current-buffer)))
3064 (princ "(custom-set-faces")
3065 (let ((value (get 'default 'saved-face)))
3066 ;; The default face must be first, since it affects the others.
3068 (princ "\n '(default ")
3070 (if (or (get 'default 'face-defface-spec)
3071 (and (not (custom-facep 'default))
3072 (not (get 'default 'force-face))))
3075 (mapatoms (lambda (symbol)
3076 (let ((value (get symbol 'saved-face)))
3077 (when (and (not (eq symbol 'default))
3078 ;; Don't print default face here.
3084 (if (or (get symbol 'face-defface-spec)
3085 (and (not (custom-facep symbol))
3086 (not (get symbol 'force-face))))
3090 (unless (looking-at "\n")
3094 (defun customize-save-customized ()
3095 "Save all user options which have been set in this session."
3097 (mapatoms (lambda (symbol)
3098 (let ((face (get symbol 'customized-face))
3099 (value (get symbol 'customized-value)))
3101 (put symbol 'saved-face face)
3102 (put symbol 'customized-face nil))
3104 (put symbol 'saved-value value)
3105 (put symbol 'customized-value nil)))))
3106 ;; We really should update all custom buffers here.
3110 (defun custom-save-all ()
3111 "Save all customizations in `custom-file'."
3112 (let ((inhibit-read-only t))
3113 (custom-save-variables)
3116 (let ((default-major-mode nil))
3117 (set-buffer (find-file-noselect (custom-file))))
3120 ;;; The Customize Menu.
3124 (defcustom custom-menu-nesting 2
3125 "Maximum nesting in custom menus."
3127 :group 'custom-menu)
3129 (defun custom-face-menu-create (widget symbol)
3130 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
3131 (vector (custom-unlispify-menu-entry symbol)
3132 `(customize-face ',symbol)
3135 (defun custom-variable-menu-create (widget symbol)
3136 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
3137 (let ((type (get symbol 'custom-type)))
3138 (unless (listp type)
3139 (setq type (list type)))
3140 (if (and type (widget-get type :custom-menu))
3141 (widget-apply type :custom-menu symbol)
3142 (vector (custom-unlispify-menu-entry symbol)
3143 `(customize-variable ',symbol)
3146 ;; Add checkboxes to boolean variable entries.
3147 (widget-put (get 'boolean 'widget-type)
3148 :custom-menu (lambda (widget symbol)
3149 (vector (custom-unlispify-menu-entry symbol)
3150 `(customize-variable ',symbol)
3152 ':selected symbol)))
3154 (if (string-match "XEmacs" emacs-version)
3155 ;; XEmacs can create menus dynamically.
3156 (defun custom-group-menu-create (widget symbol)
3157 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
3158 `( ,(custom-unlispify-menu-entry symbol t)
3159 :filter (lambda (&rest junk)
3160 (cdr (custom-menu-create ',symbol)))))
3162 (defun custom-group-menu-create (widget symbol)
3163 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
3164 ;; Limit the nesting.
3165 (let ((custom-menu-nesting (1- custom-menu-nesting)))
3166 (custom-menu-create symbol))))
3169 (defun custom-menu-create (symbol)
3170 "Create menu for customization group SYMBOL.
3171 The menu is in a format applicable to `easy-menu-define'."
3172 (let* ((item (vector (custom-unlispify-menu-entry symbol)
3173 `(customize-group ',symbol)
3175 (if (and (or (not (boundp 'custom-menu-nesting))
3176 (>= custom-menu-nesting 0))
3177 (< (length (get symbol 'custom-group)) widget-menu-max-size))
3178 (let ((custom-prefix-list (custom-prefix-add symbol
3179 custom-prefix-list))
3180 (members (custom-sort-items (get symbol 'custom-group)
3181 custom-menu-sort-alphabetically
3182 custom-menu-order-groups)))
3183 (custom-load-symbol symbol)
3184 `(,(custom-unlispify-menu-entry symbol t)
3187 ,@(mapcar (lambda (entry)
3188 (widget-apply (if (listp (nth 1 entry))
3190 (list (nth 1 entry)))
3191 :custom-menu (nth 0 entry)))
3196 (defun customize-menu-create (symbol &optional name)
3197 "Return a customize menu for customization group SYMBOL.
3198 If optional NAME is given, use that as the name of the menu.
3199 Otherwise the menu will be named `Customize'.
3200 The format is suitable for use with `easy-menu-define'."
3202 (setq name "Customize"))
3203 (if (string-match "XEmacs" emacs-version)
3204 ;; We can delay it under XEmacs.
3206 :filter (lambda (&rest junk)
3207 (cdr (custom-menu-create ',symbol))))
3208 ;; But we must create it now under Emacs.
3209 (cons name (cdr (custom-menu-create symbol)))))
3211 ;;; The Custom Mode.
3213 (defvar custom-mode-map nil
3214 "Keymap for `custom-mode'.")
3216 (unless custom-mode-map
3217 (setq custom-mode-map (make-sparse-keymap))
3218 (set-keymap-parent custom-mode-map widget-keymap)
3219 (suppress-keymap custom-mode-map)
3220 (define-key custom-mode-map " " 'scroll-up)
3221 (define-key custom-mode-map "\177" 'scroll-down)
3222 (define-key custom-mode-map "q" 'bury-buffer)
3223 (define-key custom-mode-map "u" 'Custom-goto-parent)
3224 (define-key custom-mode-map "n" 'widget-forward)
3225 (define-key custom-mode-map "p" 'widget-backward)
3226 (define-key custom-mode-map [mouse-1] 'Custom-move-and-invoke))
3228 (defun Custom-move-and-invoke (event)
3229 "Move to where you click, and if it is an active field, invoke it."
3231 (mouse-set-point event)
3232 (if (widget-event-point event)
3233 (let* ((pos (widget-event-point event))
3234 (button (get-char-property pos 'button)))
3236 (widget-button-click event)))))
3238 (easy-menu-define Custom-mode-menu
3240 "Menu used in customization buffers."
3242 ,(customize-menu-create 'customize)
3243 ["Set" Custom-set t]
3244 ["Save" Custom-save t]
3245 ["Reset to Current" Custom-reset-current t]
3246 ["Reset to Saved" Custom-reset-saved t]
3247 ["Reset to Standard Settings" Custom-reset-standard t]
3248 ["Info" (Info-goto-node "(custom)The Customization Buffer") t]))
3250 (defun Custom-goto-parent ()
3251 "Go to the parent group listed at the top of this buffer.
3252 If several parents are listed, go to the first of them."
3255 (goto-char (point-min))
3256 (if (search-forward "\nGo to parent group: " nil t)
3257 (let* ((button (get-char-property (point) 'button))
3258 (parent (downcase (widget-get button :tag))))
3259 (customize-group parent)))))
3261 (defcustom custom-mode-hook nil
3262 "Hook called when entering custom-mode."
3264 :group 'custom-buffer )
3266 (defun custom-state-buffer-message (widget)
3267 (if (eq (widget-get (widget-get widget :parent) :custom-state) 'modified)
3268 (message "To install your edits, invoke [State] and choose the Set operation")))
3270 (defun custom-mode ()
3271 "Major mode for editing customization buffers.
3273 The following commands are available:
3275 Move to next button or editable field. \\[widget-forward]
3276 Move to previous button or editable field. \\[widget-backward]
3277 \\<widget-field-keymap>\
3278 Complete content of editable text field. \\[widget-complete]
3279 \\<custom-mode-map>\
3280 Invoke button under the mouse pointer. \\[Custom-move-and-invoke]
3281 Invoke button under point. \\[widget-button-press]
3282 Set all modifications. \\[Custom-set]
3283 Make all modifications default. \\[Custom-save]
3284 Reset all modified options. \\[Custom-reset-current]
3285 Reset all modified or set options. \\[Custom-reset-saved]
3286 Reset all options. \\[Custom-reset-standard]
3288 Entry to this mode calls the value of `custom-mode-hook'
3289 if that value is non-nil."
3290 (kill-all-local-variables)
3291 (setq major-mode 'custom-mode
3293 (use-local-map custom-mode-map)
3294 (easy-menu-add Custom-mode-menu)
3295 (make-local-variable 'custom-options)
3296 (make-local-variable 'widget-documentation-face)
3297 (setq widget-documentation-face 'custom-documentation-face)
3298 (make-local-variable 'widget-button-face)
3299 (setq widget-button-face 'custom-button-face)
3300 (make-local-hook 'widget-edit-functions)
3301 (add-hook 'widget-edit-functions 'custom-state-buffer-message nil t)
3302 (run-hooks 'custom-mode-hook))
3308 ;; cus-edit.el ends here