1 ;;; cus-edit.el --- Tools for customizating Emacs and Lisp packages.
3 ;; Copyright (C) 1996, 1997 Free Software Foundation, Inc.
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
6 ;; Keywords: help, faces
8 ;; X-URL: http://www.dina.kvl.dk/~abraham/custom/
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
29 ;; This file implements the code to create and edit customize buffers.
33 ;; No commands should have names starting with `custom-' because
34 ;; that interferes with completion. Use `customize-' for commands
35 ;; that the user will run with M-x, and `Custom-' for interactive commands.
42 (eval-when-compile (require 'cl))
52 (define-widget-keywords :custom-last :custom-prefix :custom-category
53 :custom-prefixes :custom-menu
55 :custom-magic :custom-state :custom-level :custom-form
56 :custom-set :custom-save :custom-reset-current :custom-reset-saved
57 :custom-reset-standard)
59 (put 'custom-define-hook 'custom-type 'hook)
60 (put 'custom-define-hook 'standard-value '(nil))
61 (custom-add-to-group 'customize 'custom-define-hook 'custom-variable)
63 ;;; Customization Groups.
66 "Customization of the One True Editor."
67 :link '(custom-manual "(emacs)Top"))
69 ;; Most of these groups are stolen from `finder.el',
71 "Basic text editing facilities."
75 "Abbreviation handling, typing shortcuts, macros."
79 (defgroup matching nil
80 "Various sorts of searching and matching."
83 (defgroup emulations nil
84 "Emulations of other editors."
91 (defgroup outlines nil
92 "Support for hierarchical outlining."
95 (defgroup external nil
96 "Interfacing to external utilities."
100 "Code related to the `bib' bibliography processor."
104 (defgroup processes nil
105 "Process, subshell, compilation, and job control support."
109 (defgroup convenience nil
110 "Convenience features for faster editing."
113 (defgroup programming nil
114 "Support for programming in other languages."
117 (defgroup languages nil
118 "Specialized modes for editing programming languages."
122 "Lisp support, including Emacs Lisp."
127 "Support for the C language and related languages."
135 "Support for object-oriented programming."
138 (defgroup applications nil
139 "Applications written in Emacs."
142 (defgroup calendar nil
143 "Calendar and time management support."
144 :group 'applications)
147 "Modes for electronic-mail handling."
148 :group 'applications)
151 "Support for netnews reading and posting."
152 :group 'applications)
155 "Games, jokes and amusements."
156 :group 'applications)
158 (defgroup development nil
159 "Support for further development of Emacs."
163 "Support for Emacs documentation."
166 (defgroup extensions nil
167 "Emacs Lisp language extensions."
170 (defgroup internal nil
171 "Code for Emacs internals, build process, defaults."
175 "Maintenance aids for the Emacs development group."
179 (defgroup environment nil
180 "Fitting Emacs with its environment."
184 "Communications, networking, remote access to files."
188 (defgroup hardware nil
189 "Support for interfacing with exotic hardware."
192 (defgroup terminals nil
193 "Support for terminal types."
197 "Front-ends/assistants for, or emulators of, UNIX features."
201 "Support code for vms."
205 "Internationalization and alternate character-set support."
210 "The X Window system."
214 "Support for Emacs frames and window systems."
218 "Support editing files of data."
222 "Support editing files."
230 "Code related to the TeX formatter."
234 "Support for multiple fonts."
237 (defgroup hypermedia nil
238 "Support for links between text or other media types."
242 "Support for on-line help systems."
246 "Code local to your site."
249 (defgroup customize '((widgets custom-group))
250 "Customization of the Customization support."
251 :link '(custom-manual "(custom)Top")
252 :link '(url-link :tag "Development Page"
253 "http://www.dina.kvl.dk/~abraham/custom/")
257 (defgroup custom-faces nil
258 "Faces used by customize."
262 (defgroup custom-browse nil
263 "Control customize browser."
267 (defgroup custom-buffer nil
268 "Control customize buffers."
272 (defgroup custom-menu nil
273 "Control customize menus."
277 (defgroup abbrev-mode nil
278 "Word abbreviations mode."
282 "Storage allocation and gc for GNU Emacs Lisp interpreter."
283 :tag "Storage Allocation"
287 "Undoing changes in buffers."
290 (defgroup modeline nil
291 "Content of the modeline."
295 "Indenting and filling text."
298 (defgroup editing-basics nil
299 "Most basic editing facilities."
302 (defgroup display nil
303 "How characters are displayed in buffers."
306 (defgroup execute nil
307 "Executing external commands."
310 (defgroup installation nil
311 "The Emacs installation."
319 "Internal Emacs limits."
323 "Debugging Emacs itself."
326 (defgroup minibuffer nil
327 "Controling the behaviour of the minibuffer."
330 (defgroup keyboard nil
331 "Input from the keyboard."
335 "Input from the mouse."
339 "Input from the menus."
342 (defgroup auto-save nil
343 "Preventing accidential loss of data."
346 (defgroup processes-basics nil
347 "Basic stuff dealing with processes."
351 "MULE Emacs internationalization."
354 (defgroup windows nil
355 "Windows within a frame."
360 (defun custom-last (x &optional n)
361 ;; Stolen from `cl.el'.
362 "Returns the last link in the list LIST.
363 With optional argument N, returns Nth-to-last link (default 1)."
366 (while (consp p) (incf m) (pop p))
368 (if (< n m) (nthcdr (- m n) x) x)))
369 (while (consp (cdr x)) (pop x))
372 (defun custom-quote (sexp)
373 "Quote SEXP iff it is not self quoting."
374 (if (or (memq sexp '(t nil))
376 (eq (aref (symbol-name sexp) 0) ?:))
378 (memq (car sexp) '(lambda)))
381 (and (fboundp 'characterp)
386 (defun custom-split-regexp-maybe (regexp)
387 "If REGEXP is a string, split it to a list at `\\|'.
388 You can get the original back with from the result with:
389 (mapconcat 'identity result \"\\|\")
391 IF REGEXP is not a string, return it unchanged."
395 (while (string-match "\\\\|" regexp start)
396 (setq all (cons (substring regexp start (match-beginning 0)) all)
397 start (match-end 0)))
398 (nreverse (cons (substring regexp start) all)))
401 (defun custom-variable-prompt ()
402 ;; Code stolen from `help.el'.
403 "Prompt for a variable, defaulting to the variable at point.
404 Return a list suitable for use in `interactive'."
405 (let ((v (variable-at-point))
406 (enable-recursive-minibuffers t)
408 (setq val (completing-read
410 (format "Customize option: (default %s) " v)
411 "Customize variable: ")
412 obarray (lambda (symbol)
414 (or (get symbol 'custom-type)
415 (user-variable-p symbol)))) t))
416 (list (if (equal val "")
417 (if (symbolp v) v nil)
420 (defun custom-menu-filter (menu widget)
421 "Convert MENU to the form used by `widget-choose'.
422 MENU should be in the same format as `custom-variable-menu'.
423 WIDGET is the widget to apply the filter entries of MENU on."
425 current name action filter)
427 (setq current (car menu)
429 action (nth 1 current)
430 filter (nth 2 current)
432 (if (or (null filter) (funcall filter widget))
433 (push (cons name action) result)
439 (defvar custom-prefix-list nil
440 "List of prefixes that should be ignored by `custom-unlispify'")
442 (defcustom custom-unlispify-menu-entries t
443 "Display menu entries as words instead of symbols if non nil."
447 (defcustom custom-unlispify-remove-prefixes nil
448 "Non-nil means remove group prefixes from option names in buffer."
452 (defun custom-unlispify-menu-entry (symbol &optional no-suffix)
453 "Convert symbol into a menu entry."
454 (cond ((not custom-unlispify-menu-entries)
455 (symbol-name symbol))
456 ((get symbol 'custom-tag)
458 (get symbol 'custom-tag)
459 (concat (get symbol 'custom-tag) "...")))
462 (set-buffer (get-buffer-create " *Custom-Work*"))
464 (princ symbol (current-buffer))
465 (goto-char (point-min))
466 (when (and (eq (get symbol 'custom-type) 'boolean)
467 (re-search-forward "-p\\'" nil t))
468 (replace-match "" t t)
469 (goto-char (point-min)))
470 (if custom-unlispify-remove-prefixes
471 (let ((prefixes custom-prefix-list)
474 (setq prefix (car prefixes))
475 (if (search-forward prefix (+ (point) (length prefix)) t)
478 (delete-region (point-min) (point)))
479 (setq prefixes (cdr prefixes))))))
480 (subst-char-in-region (point-min) (point-max) ?- ?\ t)
481 (capitalize-region (point-min) (point-max))
483 (goto-char (point-max))
487 (defcustom custom-unlispify-tag-names t
488 "Display tag names as words instead of symbols if non nil."
489 :group 'custom-buffer
492 (defun custom-unlispify-tag-name (symbol)
493 "Convert symbol into a menu entry."
494 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names))
495 (custom-unlispify-menu-entry symbol t)))
497 (defun custom-prefix-add (symbol prefixes)
498 ;; Addd SYMBOL to list of ignored PREFIXES.
499 (cons (or (get symbol 'custom-prefix)
500 (concat (symbol-name symbol) "-"))
505 (defcustom custom-guess-name-alist
510 ("-function\\'" function)
511 ("-functions\\'" (repeat function))
512 ("-list\\'" (repeat sexp))
513 ("-alist\\'" (repeat (cons sexp sexp))))
514 "Alist of (MATCH TYPE).
516 MATCH should be a regexp matching the name of a symbol, and TYPE should
517 be a widget suitable for editing the value of that symbol. The TYPE
518 of the first entry where MATCH matches the name of the symbol will be
521 This is used for guessing the type of variables not declared with
523 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
526 (defcustom custom-guess-doc-alist
527 '(("\\`\\*?Non-nil " boolean))
528 "Alist of (MATCH TYPE).
530 MATCH should be a regexp matching a documentation string, and TYPE
531 should be a widget suitable for editing the value of a variable with
532 that documentation string. The TYPE of the first entry where MATCH
533 matches the name of the symbol will be used.
535 This is used for guessing the type of variables not declared with
537 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
540 (defun custom-guess-type (symbol)
541 "Guess a widget suitable for editing the value of SYMBOL.
542 This is done by matching SYMBOL with `custom-guess-name-alist' and
543 if that fails, the doc string with `custom-guess-doc-alist'."
544 (let ((name (symbol-name symbol))
545 (names custom-guess-name-alist)
548 (setq current (car names)
550 (when (string-match (nth 0 current) name)
551 (setq found (nth 1 current)
554 (let ((doc (documentation-property symbol 'variable-documentation))
555 (docs custom-guess-doc-alist))
558 (setq current (car docs)
560 (when (string-match (nth 0 current) doc)
561 (setq found (nth 1 current)
567 (defcustom custom-browse-sort-alphabetically nil
568 "If non-nil, sort members of each customization group alphabetically."
570 :group 'custom-browse)
572 (defcustom custom-browse-order-groups nil
573 "If non-nil, order group members within each customization group.
574 If `first', order groups before non-groups.
575 If `last', order groups after non-groups."
576 :type '(choice (const first)
578 (const :tag "none" nil))
579 :group 'custom-browse)
581 (defcustom custom-browse-only-groups nil
582 "If non-nil, show group members only within each customization group."
584 :group 'custom-browse)
586 (defcustom custom-buffer-sort-alphabetically nil
587 "If non-nil, sort members of each customization group alphabetically."
589 :group 'custom-buffer)
591 (defcustom custom-buffer-order-groups 'last
592 "If non-nil, order group members within each customization group.
593 If `first', order groups before non-groups.
594 If `last', order groups after non-groups."
595 :type '(choice (const first)
597 (const :tag "none" nil))
598 :group 'custom-buffer)
600 (defcustom custom-menu-sort-alphabetically nil
601 "If non-nil, sort members of each customization group alphabetically."
605 (defcustom custom-menu-order-groups 'first
606 "If non-nil, order group members within each customization group.
607 If `first', order groups before non-groups.
608 If `last', order groups after non-groups."
609 :type '(choice (const first)
611 (const :tag "none" nil))
614 ;;;###autoload (add-hook 'same-window-regexps "\\`\\*Customiz.*\\*\\'")
616 (defun custom-sort-items (items sort-alphabetically order-groups)
617 "Return a sorted copy of ITEMS.
618 ITEMS should be a `custom-group' property.
619 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
620 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
621 groups after non-groups, if nil do not order groups at all."
622 (sort (copy-sequence items)
624 (let ((typea (nth 1 a)) (typeb (nth 1 b))
625 (namea (symbol-name (nth 0 a))) (nameb (symbol-name (nth 0 b))))
626 (cond ((not order-groups)
627 ;; Since we don't care about A and B order, maybe sort.
628 (when sort-alphabetically
629 (string-lessp namea nameb)))
630 ((eq typea 'custom-group)
631 ;; If B is also a group, maybe sort. Otherwise, order A and B.
632 (if (eq typeb 'custom-group)
633 (when sort-alphabetically
634 (string-lessp namea nameb))
635 (eq order-groups 'first)))
636 ((eq typeb 'custom-group)
637 ;; Since A cannot be a group, order A and B.
638 (eq order-groups 'last))
640 ;; Since A and B cannot be groups, sort.
641 (string-lessp namea nameb)))))))
643 ;;; Custom Mode Commands.
645 (defvar custom-options nil
646 "Customization widgets in the current buffer.")
649 "Set changes in all modified options."
651 (let ((children custom-options))
652 (mapcar (lambda (child)
653 (when (eq (widget-get child :custom-state) 'modified)
654 (widget-apply child :custom-set)))
657 (defun Custom-save ()
658 "Set all modified group members and save them."
660 (let ((children custom-options))
661 (mapcar (lambda (child)
662 (when (memq (widget-get child :custom-state) '(modified set))
663 (widget-apply child :custom-save)))
667 (defvar custom-reset-menu
668 '(("Current" . Custom-reset-current)
669 ("Saved" . Custom-reset-saved)
670 ("Standard Settings" . Custom-reset-standard))
671 "Alist of actions for the `Reset' button.
672 The key is a string containing the name of the action, the value is a
673 lisp function taking the widget as an element which will be called
674 when the action is chosen.")
676 (defun custom-reset (event)
677 "Select item from reset menu."
678 (let* ((completion-ignore-case t)
679 (answer (widget-choose "Reset to"
685 (defun Custom-reset-current (&rest ignore)
686 "Reset all modified group members to their current value."
688 (let ((children custom-options))
689 (mapcar (lambda (child)
690 (when (eq (widget-get child :custom-state) 'modified)
691 (widget-apply child :custom-reset-current)))
694 (defun Custom-reset-saved (&rest ignore)
695 "Reset all modified or set group members to their saved value."
697 (let ((children custom-options))
698 (mapcar (lambda (child)
699 (when (eq (widget-get child :custom-state) 'modified)
700 (widget-apply child :custom-reset-saved)))
703 (defun Custom-reset-standard (&rest ignore)
704 "Reset all modified, set, or saved group members to their standard settings."
706 (let ((children custom-options))
707 (mapcar (lambda (child)
708 (when (eq (widget-get child :custom-state) 'modified)
709 (widget-apply child :custom-reset-standard)))
712 ;;; The Customize Commands
714 (defun custom-prompt-variable (prompt-var prompt-val)
715 "Prompt for a variable and a value and return them as a list.
716 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
717 prompt for the value. The %s escape in PROMPT-VAL is replaced with
718 the name of the variable.
720 If the variable has a `variable-interactive' property, that is used as if
721 it were the arg to `interactive' (which see) to interactively read the value.
723 If the variable has a `custom-type' property, it must be a widget and the
724 `:prompt-value' property of that widget will be used for reading the value."
725 (let* ((var (read-variable prompt-var))
726 (minibuffer-help-form '(describe-variable var)))
728 (let ((prop (get var 'variable-interactive))
729 (type (get var 'custom-type))
730 (prompt (format prompt-val var)))
732 (setq type (list type)))
734 ;; Use VAR's `variable-interactive' property
735 ;; as an interactive spec for prompting.
736 (call-interactively (list 'lambda '(arg)
737 (list 'interactive prop)
740 (widget-prompt-value type
746 (eval-minibuffer prompt)))))))
749 (defun customize-set-value (var val)
750 "Set VARIABLE to VALUE. VALUE is a Lisp object.
752 If VARIABLE has a `variable-interactive' property, that is used as if
753 it were the arg to `interactive' (which see) to interactively read the value.
755 If VARIABLE has a `custom-type' property, it must be a widget and the
756 `:prompt-value' property of that widget will be used for reading the value."
757 (interactive (custom-prompt-variable "Set variable: "
758 "Set %s to value: "))
763 (defun customize-set-variable (var val)
764 "Set the default for VARIABLE to VALUE. VALUE is a Lisp object.
766 If VARIABLE has a `custom-set' property, that is used for setting
767 VARIABLE, otherwise `set-default' is used.
769 The `customized-value' property of the VARIABLE will be set to a list
770 with a quoted VALUE as its sole list member.
772 If VARIABLE has a `variable-interactive' property, that is used as if
773 it were the arg to `interactive' (which see) to interactively read the value.
775 If VARIABLE has a `custom-type' property, it must be a widget and the
776 `:prompt-value' property of that widget will be used for reading the value. "
777 (interactive (custom-prompt-variable "Set variable: "
778 "Set customized value for %s to: "))
779 (funcall (or (get var 'custom-set) 'set-default) var val)
780 (put var 'customized-value (list (custom-quote val))))
783 (defun customize-save-variable (var val)
784 "Set the default for VARIABLE to VALUE, and save it for future sessions.
785 If VARIABLE has a `custom-set' property, that is used for setting
786 VARIABLE, otherwise `set-default' is used.
788 The `customized-value' property of the VARIABLE will be set to a list
789 with a quoted VALUE as its sole list member.
791 If VARIABLE has a `variable-interactive' property, that is used as if
792 it were the arg to `interactive' (which see) to interactively read the value.
794 If VARIABLE has a `custom-type' property, it must be a widget and the
795 `:prompt-value' property of that widget will be used for reading the value. "
796 (interactive (custom-prompt-variable "Set and ave variable: "
797 "Set and save value for %s as: "))
798 (funcall (or (get var 'custom-set) 'set-default) var val)
799 (put var 'saved-value (list (custom-quote val)))
804 "Select a customization buffer which you can use to set user options.
805 User options are structured into \"groups\".
806 Initially the top-level group `Emacs' and its immediate subgroups
807 are shown; the contents of those subgroups are initially hidden."
809 (customize-group 'emacs))
812 (defun customize-group (group)
813 "Customize GROUP, which must be a customization group."
814 (interactive (list (let ((completion-ignore-case t))
815 (completing-read "Customize group: (default emacs) "
818 (or (get symbol 'custom-loads)
819 (get symbol 'custom-group)))
821 (when (stringp group)
822 (if (string-equal "" group)
824 (setq group (intern group))))
825 (or (get group 'custom-group)
826 (custom-load-symbol group))
827 (let ((name (format "*Customize Group: %s*"
828 (custom-unlispify-tag-name group))))
829 (if (get-buffer name)
831 (custom-buffer-create (list (list group 'custom-group))
833 (concat " for group "
834 (custom-unlispify-tag-name group))))))
837 (defun customize-group-other-window (group)
838 "Customize GROUP, which must be a customization group."
839 (interactive (list (let ((completion-ignore-case t))
840 (completing-read "Customize group: (default emacs) "
843 (or (get symbol 'custom-loads)
844 (get symbol 'custom-group)))
846 (when (stringp group)
847 (if (string-equal "" group)
849 (setq group (intern group))))
850 (or (get group 'custom-group)
851 (custom-load-symbol group))
852 (let ((name (format "*Customize Group: %s*"
853 (custom-unlispify-tag-name group))))
854 (if (get-buffer name)
855 (let ((window (selected-window)))
857 (select-window window))
858 (custom-buffer-create-other-window
859 (list (list group 'custom-group))
861 (concat " for group "
862 (custom-unlispify-tag-name group))))))
865 (defalias 'customize-variable 'customize-option)
868 (defun customize-option (symbol)
869 "Customize SYMBOL, which must be a user option variable."
870 (interactive (custom-variable-prompt))
871 (custom-buffer-create (list (list symbol 'custom-variable))
872 (format "*Customize Option: %s*"
873 (custom-unlispify-tag-name symbol))))
876 (defun customize-changed-options (since-version)
877 "Customize all user option variables whose default values changed recently.
878 This means, in other words, variables and groups defined with a `:version'
880 (interactive "sCustomize options changed, since version (default all versions): ")
881 (if (equal since-version "")
882 (setq since-version nil))
885 (mapatoms (lambda (symbol)
886 (and (or (boundp symbol)
887 ;; For variables not yet loaded.
888 (get symbol 'standard-value)
889 ;; For groups the previous test fails, this one
890 ;; could be used to determine if symbol is a
891 ;; group. Is there a better way for this?
892 (get symbol 'group-documentation))
893 (let ((version (get symbol 'custom-version)))
895 (or (null since-version)
896 (customize-version-lessp since-version version))
897 (if (member version versions)
899 ;;; Collect all versions that we use.
900 (push version versions))))
902 ;; We have to set the right thing here,
903 ;; depending if we have a group or a
905 (if (get symbol 'group-documentation)
906 (cons (list symbol 'custom-group) found)
907 (cons (list symbol 'custom-variable) found))))))
909 (error "No user options have changed defaults in recent Emacs versions")
913 (cdr (assoc (car versions) custom-versions-load-alist)))
915 (setq versions (cdr versions)))
916 (put 'custom-versions-load-alist 'custom-loads
917 ;; Get all the files that correspond to element from the
918 ;; VERSIONS list. This could use some simplification.
919 (apply 'nconc flist)))
920 ;; Because we set all the files needed to be loaded as a
921 ;; `custom-loads' property to `custom-versions-load-alist' this
922 ;; call will actually load them.
923 (custom-load-symbol 'custom-versions-load-alist)
925 (put 'custom-versions-load-alist 'custom-loads nil)
926 (custom-buffer-create (custom-sort-items found t 'first)
927 "*Customize Changed Options*"))))
929 (defun customize-version-lessp (version1 version2)
930 (let (major1 major2 minor1 minor2)
931 (string-match "\\([0-9]+\\)[.]\\([0-9]+\\)" version1)
932 (setq major1 (read (match-string 1 version1)))
933 (setq minor1 (read (match-string 2 version1)))
934 (string-match "\\([0-9]+\\)[.]\\([0-9]+\\)" version2)
935 (setq major2 (read (match-string 1 version2)))
936 (setq minor2 (read (match-string 2 version2)))
937 (or (< major1 major2)
938 (and (= major1 major2)
939 (< minor1 minor2)))))
942 (defalias 'customize-variable-other-window 'customize-option-other-window)
945 (defun customize-option-other-window (symbol)
946 "Customize SYMBOL, which must be a user option variable.
947 Show the buffer in another window, but don't select it."
948 (interactive (custom-variable-prompt))
949 (custom-buffer-create-other-window
950 (list (list symbol 'custom-variable))
951 (format "*Customize Option: %s*" (custom-unlispify-tag-name symbol))))
954 (defun customize-face (&optional symbol)
955 "Customize SYMBOL, which should be a face name or nil.
956 If SYMBOL is nil, customize all faces."
957 (interactive (list (completing-read "Customize face: (default all) "
958 obarray 'custom-facep)))
959 (if (or (null symbol) (and (stringp symbol) (zerop (length symbol))))
960 (custom-buffer-create (custom-sort-items
961 (mapcar (lambda (symbol)
962 (list symbol 'custom-face))
966 (when (stringp symbol)
967 (setq symbol (intern symbol)))
968 (unless (symbolp symbol)
969 (error "Should be a symbol %S" symbol))
970 (custom-buffer-create (list (list symbol 'custom-face))
971 (format "*Customize Face: %s*"
972 (custom-unlispify-tag-name symbol)))))
975 (defun customize-face-other-window (&optional symbol)
976 "Show customization buffer for FACE in other window."
977 (interactive (list (completing-read "Customize face: "
978 obarray 'custom-facep)))
979 (if (or (null symbol) (and (stringp symbol) (zerop (length symbol))))
982 (setq symbol (intern symbol)))
983 (unless (symbolp symbol)
984 (error "Should be a symbol %S" symbol))
985 (custom-buffer-create-other-window
986 (list (list symbol 'custom-face))
987 (format "*Customize Face: %s*" (custom-unlispify-tag-name symbol)))))
990 (defun customize-customized ()
991 "Customize all user options set since the last save in this session."
994 (mapatoms (lambda (symbol)
995 (and (get symbol 'customized-face)
996 (custom-facep symbol)
997 (push (list symbol 'custom-face) found))
998 (and (get symbol 'customized-value)
1000 (push (list symbol 'custom-variable) found))))
1002 (error "No customized user options")
1003 (custom-buffer-create (custom-sort-items found t nil)
1004 "*Customize Customized*"))))
1007 (defun customize-saved ()
1008 "Customize all already saved user options."
1011 (mapatoms (lambda (symbol)
1012 (and (get symbol 'saved-face)
1013 (custom-facep symbol)
1014 (push (list symbol 'custom-face) found))
1015 (and (get symbol 'saved-value)
1017 (push (list symbol 'custom-variable) found))))
1019 (error "No saved user options")
1020 (custom-buffer-create (custom-sort-items found t nil)
1021 "*Customize Saved*"))))
1024 (defun customize-apropos (regexp &optional all)
1025 "Customize all user options matching REGEXP.
1026 If ALL is `options', include only options.
1027 If ALL is `faces', include only faces.
1028 If ALL is `groups', include only groups.
1029 If ALL is t (interactively, with prefix arg), include options which are not
1030 user-settable, as well as faces and groups."
1031 (interactive "sCustomize regexp: \nP")
1033 (mapatoms (lambda (symbol)
1034 (when (string-match regexp (symbol-name symbol))
1035 (when (and (not (memq all '(faces options)))
1036 (get symbol 'custom-group))
1037 (push (list symbol 'custom-group) found))
1038 (when (and (not (memq all '(options groups)))
1039 (custom-facep symbol))
1040 (push (list symbol 'custom-face) found))
1041 (when (and (not (memq all '(groups faces)))
1043 (or (get symbol 'saved-value)
1044 (get symbol 'standard-value)
1045 (if (memq all '(nil options))
1046 (user-variable-p symbol)
1047 (get symbol 'variable-documentation))))
1048 (push (list symbol 'custom-variable) found)))))
1050 (error "No matches")
1051 (custom-buffer-create (custom-sort-items found t
1052 custom-buffer-order-groups)
1053 "*Customize Apropos*"))))
1056 (defun customize-apropos-options (regexp &optional arg)
1057 "Customize all user options matching REGEXP.
1058 With prefix arg, include options which are not user-settable."
1059 (interactive "sCustomize regexp: \nP")
1060 (customize-apropos regexp (or arg 'options)))
1063 (defun customize-apropos-faces (regexp)
1064 "Customize all user faces matching REGEXP."
1065 (interactive "sCustomize regexp: \n")
1066 (customize-apropos regexp 'faces))
1069 (defun customize-apropos-groups (regexp)
1070 "Customize all user groups matching REGEXP."
1071 (interactive "sCustomize regexp: \n")
1072 (customize-apropos regexp 'groups))
1076 (defcustom custom-buffer-style 'links
1077 "Control the presentation style for customization buffers.
1078 The value should be a symbol, one of:
1080 brackets: groups nest within each other with big horizontal brackets.
1081 links: groups have links to subgroups."
1082 :type '(radio (const brackets)
1084 :group 'custom-buffer)
1086 (defcustom custom-buffer-indent 3
1087 "Number of spaces to indent nested groups."
1089 :group 'custom-buffer)
1092 (defun custom-buffer-create (options &optional name description)
1093 "Create a buffer containing OPTIONS.
1094 Optional NAME is the name of the buffer.
1095 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1096 SYMBOL is a customization option, and WIDGET is a widget for editing
1098 (unless name (setq name "*Customization*"))
1099 (kill-buffer (get-buffer-create name))
1100 (pop-to-buffer (get-buffer-create name))
1101 (custom-buffer-create-internal options description))
1104 (defun custom-buffer-create-other-window (options &optional name description)
1105 "Create a buffer containing OPTIONS.
1106 Optional NAME is the name of the buffer.
1107 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1108 SYMBOL is a customization option, and WIDGET is a widget for editing
1110 (unless name (setq name "*Customization*"))
1111 (kill-buffer (get-buffer-create name))
1112 (let ((window (selected-window))
1114 (special-display-buffer-names nil)
1115 (special-display-regexps nil)
1116 (same-window-buffer-names nil)
1117 (same-window-regexps nil))
1118 (pop-to-buffer (get-buffer-create name))
1119 (custom-buffer-create-internal options description)
1120 (select-window window)))
1122 (defcustom custom-reset-button-menu nil
1123 "If non-nil, only show a single reset button in customize buffers.
1124 This button will have a menu with all three reset operations."
1126 :group 'custom-buffer)
1128 (defun custom-buffer-create-internal (options &optional description)
1129 (message "Creating customization buffer...")
1131 (widget-insert "This is a customization buffer")
1133 (widget-insert description))
1135 Square brackets show active fields; type RET or click mouse-1
1136 on an active field to invoke its action. Editing an option value
1137 changes the text in the buffer; invoke the State button and
1138 choose the Set operation to set the option value.
1140 (widget-create 'info-link
1142 :help-echo "Read the online help."
1143 "(emacs)Easy Customization")
1144 (widget-insert " for more information.\n\n")
1145 (message "Creating customization buttons...")
1146 (widget-insert "Operate on everything in this buffer:\n ")
1147 (widget-create 'push-button
1148 :tag "Set for Current Session"
1150 Make your editing in this buffer take effect for this session."
1151 :action (lambda (widget &optional event)
1154 (widget-create 'push-button
1155 :tag "Save for Future Sessions"
1157 Make your editing in this buffer take effect for future Emacs sessions."
1158 :action (lambda (widget &optional event)
1160 (if custom-reset-button-menu
1163 (widget-create 'push-button
1165 :help-echo "Show a menu with reset operations."
1166 :mouse-down-action (lambda (&rest junk) t)
1167 :action (lambda (widget &optional event)
1168 (custom-reset event))))
1169 (widget-insert "\n ")
1170 (widget-create 'push-button
1173 Reset all edited text in this buffer to reflect current values."
1174 :action 'Custom-reset-current)
1176 (widget-create 'push-button
1177 :tag "Reset to Saved"
1179 Reset all values in this buffer to their saved settings."
1180 :action 'Custom-reset-saved)
1182 (widget-create 'push-button
1183 :tag "Reset to Standard"
1185 Reset all values in this buffer to their standard settings."
1186 :action 'Custom-reset-standard))
1188 (widget-create 'push-button
1190 :help-echo "Bury the buffer."
1191 :action (lambda (widget &optional event)
1193 (widget-insert "\n\n")
1194 (message "Creating customization items...")
1195 (setq custom-options
1196 (if (= (length options) 1)
1197 (mapcar (lambda (entry)
1198 (widget-create (nth 1 entry)
1199 :documentation-shown t
1200 :custom-state 'unknown
1201 :tag (custom-unlispify-tag-name
1203 :value (nth 0 entry)))
1206 (length (length options)))
1207 (mapcar (lambda (entry)
1209 (message "Creating customization items ...%2d%%"
1210 (/ (* 100.0 count) length))
1211 (widget-create (nth 1 entry)
1212 :tag (custom-unlispify-tag-name
1214 :value (nth 0 entry))
1215 (setq count (1+ count))
1216 (unless (eq (preceding-char) ?\n)
1217 (widget-insert "\n"))
1218 (widget-insert "\n")))
1220 (unless (eq (preceding-char) ?\n)
1221 (widget-insert "\n"))
1222 (message "Creating customization items ...%2d%%done" 100)
1223 (unless (eq custom-buffer-style 'tree)
1224 (mapcar 'custom-magic-reset custom-options))
1225 (message "Creating customization setup...")
1227 (goto-char (point-min))
1228 (message "Creating customization buffer...done"))
1230 ;;; The Tree Browser.
1233 (defun customize-browse (&optional group)
1234 "Create a tree browser for the customize hierarchy."
1237 (setq group 'emacs))
1238 (let ((name "*Customize Browser*"))
1239 (kill-buffer (get-buffer-create name))
1240 (pop-to-buffer (get-buffer-create name)))
1243 Square brackets show active fields; type RET or click mouse-1
1244 on an active field to invoke its action.
1245 Invoke [+] below to expand a group, and [-] to collapse an expanded group.\n")
1246 (if custom-browse-only-groups
1248 Invoke the [Group] button below to edit that item in another window.\n\n")
1249 (widget-insert "Invoke the ")
1250 (widget-create 'item
1253 :tag-glyph "folder")
1254 (widget-insert ", ")
1255 (widget-create 'item
1259 (widget-insert ", and ")
1260 (widget-create 'item
1263 :tag-glyph "option")
1264 (widget-insert " buttons below to edit that
1265 item in another window.\n\n"))
1266 (let ((custom-buffer-style 'tree))
1267 (widget-create 'custom-group
1269 :custom-state 'unknown
1270 :tag (custom-unlispify-tag-name group)
1272 (goto-char (point-min)))
1274 (define-widget 'custom-browse-visibility 'item
1275 "Control visibility of items in the customize tree browser."
1277 :action 'custom-browse-visibility-action)
1279 (defun custom-browse-visibility-action (widget &rest ignore)
1280 (let ((custom-buffer-style 'tree))
1281 (custom-toggle-parent widget)))
1283 (define-widget 'custom-browse-group-tag 'push-button
1284 "Show parent in other window when activated."
1287 :action 'custom-browse-group-tag-action)
1289 (defun custom-browse-group-tag-action (widget &rest ignore)
1290 (let ((parent (widget-get widget :parent)))
1291 (customize-group-other-window (widget-value parent))))
1293 (define-widget 'custom-browse-variable-tag 'push-button
1294 "Show parent in other window when activated."
1297 :action 'custom-browse-variable-tag-action)
1299 (defun custom-browse-variable-tag-action (widget &rest ignore)
1300 (let ((parent (widget-get widget :parent)))
1301 (customize-variable-other-window (widget-value parent))))
1303 (define-widget 'custom-browse-face-tag 'push-button
1304 "Show parent in other window when activated."
1307 :action 'custom-browse-face-tag-action)
1309 (defun custom-browse-face-tag-action (widget &rest ignore)
1310 (let ((parent (widget-get widget :parent)))
1311 (customize-face-other-window (widget-value parent))))
1313 (defconst custom-browse-alist '((" " "space")
1319 (defun custom-browse-insert-prefix (prefix)
1320 "Insert PREFIX. On XEmacs convert it to line graphics."
1321 (if nil ; (string-match "XEmacs" emacs-version)
1324 (while (not (string-equal prefix ""))
1325 (let ((entry (substring prefix 0 3)))
1326 (setq prefix (substring prefix 3))
1327 (let ((overlay (make-overlay (1- (point)) (point) nil t nil))
1328 (name (nth 1 (assoc entry custom-browse-alist))))
1329 (overlay-put overlay 'end-glyph (widget-glyph-find name entry))
1330 (overlay-put overlay 'start-open t)
1331 (overlay-put overlay 'end-open t)))))
1334 ;;; Modification of Basic Widgets.
1336 ;; We add extra properties to the basic widgets needed here. This is
1337 ;; fine, as long as we are careful to stay within out own namespace.
1339 ;; We want simple widgets to be displayed by default, but complex
1340 ;; widgets to be hidden.
1342 (widget-put (get 'item 'widget-type) :custom-show t)
1343 (widget-put (get 'editable-field 'widget-type)
1344 :custom-show (lambda (widget value)
1345 (let ((pp (pp-to-string value)))
1346 (cond ((string-match "\n" pp)
1351 (widget-put (get 'menu-choice 'widget-type) :custom-show t)
1353 ;;; The `custom-manual' Widget.
1355 (define-widget 'custom-manual 'info-link
1356 "Link to the manual entry for this customization option."
1357 :help-echo "Read the manual entry for this option."
1360 ;;; The `custom-magic' Widget.
1362 (defgroup custom-magic-faces nil
1363 "Faces used by the magic button."
1364 :group 'custom-faces
1365 :group 'custom-buffer)
1367 (defface custom-invalid-face '((((class color))
1368 (:foreground "yellow" :background "red"))
1370 (:bold t :italic t :underline t)))
1371 "Face used when the customize item is invalid."
1372 :group 'custom-magic-faces)
1374 (defface custom-rogue-face '((((class color))
1375 (:foreground "pink" :background "black"))
1378 "Face used when the customize item is not defined for customization."
1379 :group 'custom-magic-faces)
1381 (defface custom-modified-face '((((class color))
1382 (:foreground "white" :background "blue"))
1385 "Face used when the customize item has been modified."
1386 :group 'custom-magic-faces)
1388 (defface custom-set-face '((((class color))
1389 (:foreground "blue" :background "white"))
1392 "Face used when the customize item has been set."
1393 :group 'custom-magic-faces)
1395 (defface custom-changed-face '((((class color))
1396 (:foreground "white" :background "blue"))
1399 "Face used when the customize item has been changed."
1400 :group 'custom-magic-faces)
1402 (defface custom-saved-face '((t (:underline t)))
1403 "Face used when the customize item has been saved."
1404 :group 'custom-magic-faces)
1406 (defconst custom-magic-alist '((nil "#" underline "\
1407 uninitialized, you should not see this.")
1408 (unknown "?" italic "\
1409 unknown, you should not see this.")
1410 (hidden "-" default "\
1411 hidden, invoke \"Show\" in the previous line to show." "\
1412 group now hidden, invoke \"Show\", above, to show contents.")
1413 (invalid "x" custom-invalid-face "\
1414 the value displayed for this %c is invalid and cannot be set.")
1415 (modified "*" custom-modified-face "\
1416 you have edited the value as text, but you have not set the %c." "\
1417 you have edited something in this group, but not set it.")
1418 (set "+" custom-set-face "\
1419 you have set this %c, but not saved it for future sessions." "\
1420 something in this group has been set, but not saved.")
1421 (changed ":" custom-changed-face "\
1422 this %c has been changed outside the customize buffer." "\
1423 something in this group has been changed outside customize.")
1424 (saved "!" custom-saved-face "\
1425 this %c has been set and saved." "\
1426 something in this group has been set and saved.")
1427 (rogue "@" custom-rogue-face "\
1428 this %c has not been changed with customize." "\
1429 something in this group is not prepared for customization.")
1430 (standard " " nil "\
1431 this %c is unchanged from its standard setting." "\
1432 visible group members are all at standard settings."))
1433 "Alist of customize option states.
1434 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1436 STATE is one of the following symbols:
1439 For internal use, should never occur.
1441 For internal use, should never occur.
1443 This item is not being displayed.
1445 This item is modified, but has an invalid form.
1447 This item is modified, and has a valid form.
1449 This item has been set but not saved.
1451 The current value of this item has been changed temporarily.
1453 This item is marked for saving.
1455 This item has no customization information.
1457 This item is unchanged from the standard setting.
1459 MAGIC is a string used to present that state.
1461 FACE is a face used to present the state.
1463 ITEM-DESC is a string describing the state for options.
1465 GROUP-DESC is a string describing the state for groups. If this is
1466 left out, ITEM-DESC will be used.
1468 The string %c in either description will be replaced with the
1469 category of the item. These are `group'. `option', and `face'.
1471 The list should be sorted most significant first.")
1473 (defcustom custom-magic-show 'long
1474 "If non-nil, show textual description of the state.
1475 If `long', show a full-line description, not just one word."
1476 :type '(choice (const :tag "no" nil)
1478 (other :tag "short" short))
1479 :group 'custom-buffer)
1481 (defcustom custom-magic-show-hidden '(option face)
1482 "Control whether the State button is shown for hidden items.
1483 The value should be a list with the custom categories where the State
1484 button should be visible. Possible categories are `group', `option',
1486 :type '(set (const group) (const option) (const face))
1487 :group 'custom-buffer)
1489 (defcustom custom-magic-show-button nil
1490 "Show a \"magic\" button indicating the state of each customization option."
1492 :group 'custom-buffer)
1494 (define-widget 'custom-magic 'default
1495 "Show and manipulate state for a customization option."
1497 :action 'widget-parent-action
1500 :value-create 'custom-magic-value-create
1501 :value-delete 'widget-children-value-delete)
1503 (defun widget-magic-mouse-down-action (widget &optional event)
1504 ;; Non-nil unless hidden.
1505 (not (eq (widget-get (widget-get (widget-get widget :parent) :parent)
1509 (defun custom-magic-value-create (widget)
1510 ;; Create compact status report for WIDGET.
1511 (let* ((parent (widget-get widget :parent))
1512 (state (widget-get parent :custom-state))
1513 (hidden (eq state 'hidden))
1514 (entry (assq state custom-magic-alist))
1515 (magic (nth 1 entry))
1516 (face (nth 2 entry))
1517 (category (widget-get parent :custom-category))
1518 (text (or (and (eq category 'group)
1521 (form (widget-get parent :custom-form))
1523 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text)
1524 (setq text (concat (match-string 1 text)
1525 (symbol-name category)
1526 (match-string 2 text))))
1527 (when (and custom-magic-show
1529 (memq category custom-magic-show-hidden)))
1531 (when (and (eq category 'group)
1532 (not (and (eq custom-buffer-style 'links)
1533 (> (widget-get parent :custom-level) 1))))
1534 (insert-char ?\ (* custom-buffer-indent
1535 (widget-get parent :custom-level))))
1536 (push (widget-create-child-and-convert
1538 :help-echo "Change the state of this item."
1539 :format (if hidden "%t" "%[%t%]")
1540 :button-prefix 'widget-push-button-prefix
1541 :button-suffix 'widget-push-button-suffix
1542 :mouse-down-action 'widget-magic-mouse-down-action
1546 (let ((start (point)))
1547 (if (eq custom-magic-show 'long)
1549 (insert (symbol-name state)))
1550 (cond ((eq form 'lisp)
1552 ((eq form 'mismatch)
1553 (insert " (mismatch)")))
1554 (put-text-property start (point) 'face 'custom-state-face))
1556 (when (and (eq category 'group)
1557 (not (and (eq custom-buffer-style 'links)
1558 (> (widget-get parent :custom-level) 1))))
1559 (insert-char ?\ (* custom-buffer-indent
1560 (widget-get parent :custom-level))))
1561 (when custom-magic-show-button
1562 (when custom-magic-show
1563 (let ((indent (widget-get parent :indent)))
1565 (insert-char ? indent))))
1566 (push (widget-create-child-and-convert
1568 :mouse-down-action 'widget-magic-mouse-down-action
1572 :help-echo "Change the state."
1573 :format (if hidden "%t" "%[%t%]")
1574 :tag (if (memq form '(lisp mismatch))
1575 (concat "(" magic ")")
1576 (concat "[" magic "]")))
1579 (widget-put widget :children children)))
1581 (defun custom-magic-reset (widget)
1582 "Redraw the :custom-magic property of WIDGET."
1583 (let ((magic (widget-get widget :custom-magic)))
1584 (widget-value-set magic (widget-value magic))))
1586 ;;; The `custom' Widget.
1588 (defface custom-button-face nil
1589 "Face used for buttons in customization buffers."
1590 :group 'custom-faces)
1592 (defface custom-documentation-face nil
1593 "Face used for documentation strings in customization buffers."
1594 :group 'custom-faces)
1596 (defface custom-state-face '((((class color)
1598 (:foreground "lime green"))
1601 (:foreground "dark green"))
1603 "Face used for State descriptions in the customize buffer."
1604 :group 'custom-faces)
1606 (define-widget 'custom 'default
1607 "Customize a user option."
1609 :convert-widget 'custom-convert-widget
1610 :notify 'custom-notify
1613 :custom-state 'hidden
1614 :documentation-property 'widget-subclass-responsibility
1615 :value-create 'widget-subclass-responsibility
1616 :value-delete 'widget-children-value-delete
1617 :value-get 'widget-value-value-get
1618 :validate 'widget-children-validate
1619 :match (lambda (widget value) (symbolp value)))
1621 (defun custom-convert-widget (widget)
1622 ;; Initialize :value and :tag from :args in WIDGET.
1623 (let ((args (widget-get widget :args)))
1625 (widget-put widget :value (widget-apply widget
1626 :value-to-internal (car args)))
1627 (widget-put widget :tag (custom-unlispify-tag-name (car args)))
1628 (widget-put widget :args nil)))
1631 (defun custom-notify (widget &rest args)
1632 "Keep track of changes."
1633 (let ((state (widget-get widget :custom-state)))
1634 (unless (eq state 'modified)
1635 (unless (memq state '(nil unknown hidden))
1636 (widget-put widget :custom-state 'modified))
1637 (custom-magic-reset widget)
1638 (apply 'widget-default-notify widget args))))
1640 (defun custom-redraw (widget)
1641 "Redraw WIDGET with current settings."
1642 (let ((line (count-lines (point-min) (point)))
1643 (column (current-column))
1645 (from (marker-position (widget-get widget :from)))
1646 (to (marker-position (widget-get widget :to))))
1648 (widget-value-set widget (widget-value widget))
1649 (custom-redraw-magic widget))
1650 (when (and (>= pos from) (<= pos to))
1655 (goto-line (1+ line)))
1656 (move-to-column column))
1659 (defun custom-redraw-magic (widget)
1660 "Redraw WIDGET state with current settings."
1662 (let ((magic (widget-get widget :custom-magic)))
1664 (widget-value-set magic (widget-value magic))
1665 (when (setq widget (widget-get widget :group))
1666 (custom-group-state-update widget)))
1668 (setq widget nil)))))
1671 (defun custom-show (widget value)
1672 "Non-nil if WIDGET should be shown with VALUE by default."
1673 (let ((show (widget-get widget :custom-show)))
1679 (funcall show widget value)))))
1681 (defvar custom-load-recursion nil
1682 "Hack to avoid recursive dependencies.")
1684 (defun custom-load-symbol (symbol)
1685 "Load all dependencies for SYMBOL."
1686 (unless custom-load-recursion
1687 (let ((custom-load-recursion t)
1688 (loads (get symbol 'custom-loads))
1691 (setq load (car loads)
1693 (cond ((symbolp load)
1697 ;; Don't reload a file already loaded.
1698 ((and (boundp 'preloaded-file-list)
1699 (member load preloaded-file-list)))
1700 ((assoc load load-history))
1701 ((assoc (locate-library load) load-history))
1704 ;; Without this, we would load cus-edit recursively.
1705 ;; We are still loading it when we call this,
1706 ;; and it is not in load-history yet.
1707 (or (equal load "cus-edit")
1708 (load-library load))
1711 (defun custom-load-widget (widget)
1712 "Load all dependencies for WIDGET."
1713 (custom-load-symbol (widget-value widget)))
1715 (defun custom-unloaded-symbol-p (symbol)
1716 "Return non-nil if the dependencies of SYMBOL has not yet been loaded."
1718 (loads (get symbol 'custom-loads))
1721 (setq load (car loads)
1723 (cond ((symbolp load)
1724 (unless (featurep load)
1726 ((assoc load load-history))
1727 ((assoc (locate-library load) load-history)
1733 (defun custom-unloaded-widget-p (widget)
1734 "Return non-nil if the dependencies of WIDGET has not yet been loaded."
1735 (custom-unloaded-symbol-p (widget-value widget)))
1737 (defun custom-toggle-hide (widget)
1738 "Toggle visibility of WIDGET."
1739 (custom-load-widget widget)
1740 (let ((state (widget-get widget :custom-state)))
1741 (cond ((memq state '(invalid modified))
1742 (error "There are unset changes"))
1744 (widget-put widget :custom-state 'unknown))
1746 (widget-put widget :documentation-shown nil)
1747 (widget-put widget :custom-state 'hidden)))
1748 (custom-redraw widget)
1751 (defun custom-toggle-parent (widget &rest ignore)
1752 "Toggle visibility of parent of WIDGET."
1753 (custom-toggle-hide (widget-get widget :parent)))
1755 (defun custom-add-see-also (widget &optional prefix)
1756 "Add `See also ...' to WIDGET if there are any links.
1757 Insert PREFIX first if non-nil."
1758 (let* ((symbol (widget-get widget :value))
1759 (links (get symbol 'custom-links))
1760 (many (> (length links) 2))
1761 (buttons (widget-get widget :buttons))
1762 (indent (widget-get widget :indent)))
1765 (insert-char ?\ indent))
1768 (insert "See also ")
1770 (push (widget-create-child-and-convert widget (car links))
1772 (setq links (cdr links))
1781 (widget-put widget :buttons buttons))))
1783 (defun custom-add-parent-links (widget &optional initial-string)
1784 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
1785 The value if non-nil if any parents were found.
1786 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
1787 (let ((name (widget-value widget))
1788 (type (widget-type widget))
1789 (buttons (widget-get widget :buttons))
1792 (insert (or initial-string "Parent groups:"))
1793 (mapatoms (lambda (symbol)
1794 (let ((entry (assq name (get symbol 'custom-group))))
1795 (when (eq (nth 1 entry) type)
1797 (push (widget-create-child-and-convert
1798 widget 'custom-group-link
1799 :tag (custom-unlispify-tag-name symbol)
1803 (widget-put widget :buttons buttons)
1806 (delete-region start (point)))
1809 ;;; The `custom-variable' Widget.
1811 (defface custom-variable-tag-face '((((class color)
1813 (:foreground "light blue" :underline t))
1816 (:foreground "blue" :underline t))
1818 "Face used for unpushable variable tags."
1819 :group 'custom-faces)
1821 (defface custom-variable-button-face '((t (:underline t :bold t)))
1822 "Face used for pushable variable tags."
1823 :group 'custom-faces)
1825 (defcustom custom-variable-default-form 'edit
1826 "Default form of displaying variable values."
1827 :type '(choice (const edit)
1829 :group 'custom-buffer
1832 (define-widget 'custom-variable 'custom
1833 "Customize variable."
1835 :help-echo "Set or reset this variable."
1836 :documentation-property 'variable-documentation
1837 :custom-category 'option
1839 :custom-menu 'custom-variable-menu-create
1840 :custom-form nil ; defaults to value of `custom-variable-default-form'
1841 :value-create 'custom-variable-value-create
1842 :action 'custom-variable-action
1843 :custom-set 'custom-variable-set
1844 :custom-save 'custom-variable-save
1845 :custom-reset-current 'custom-redraw
1846 :custom-reset-saved 'custom-variable-reset-saved
1847 :custom-reset-standard 'custom-variable-reset-standard)
1849 (defun custom-variable-type (symbol)
1850 "Return a widget suitable for editing the value of SYMBOL.
1851 If SYMBOL has a `custom-type' property, use that.
1852 Otherwise, look up symbol in `custom-guess-type-alist'."
1853 (let* ((type (or (get symbol 'custom-type)
1854 (and (not (get symbol 'standard-value))
1855 (custom-guess-type symbol))
1857 (options (get symbol 'custom-options))
1858 (tmp (if (listp type)
1859 (copy-sequence type)
1862 (widget-put tmp :options options))
1865 (defun custom-variable-value-create (widget)
1866 "Here is where you edit the variables value."
1867 (custom-load-widget widget)
1868 (unless (widget-get widget :custom-form)
1869 (widget-put widget :custom-form custom-variable-default-form))
1870 (let* ((buttons (widget-get widget :buttons))
1871 (children (widget-get widget :children))
1872 (form (widget-get widget :custom-form))
1873 (state (widget-get widget :custom-state))
1874 (symbol (widget-get widget :value))
1875 (tag (widget-get widget :tag))
1876 (type (custom-variable-type symbol))
1877 (conv (widget-convert type))
1878 (get (or (get symbol 'custom-get) 'default-value))
1879 (prefix (widget-get widget :custom-prefix))
1880 (last (widget-get widget :custom-last))
1881 (value (if (default-boundp symbol)
1882 (funcall get symbol)
1883 (widget-get conv :value))))
1884 ;; If the widget is new, the child determine whether it is hidden.
1886 ((custom-show type value)
1887 (setq state 'unknown))
1889 (setq state 'hidden)))
1890 ;; If we don't know the state, see if we need to edit it in lisp form.
1891 (when (eq state 'unknown)
1892 (unless (widget-apply conv :match value)
1893 ;; (widget-apply (widget-convert type) :match value)
1894 (setq form 'mismatch)))
1895 ;; Now we can create the child widget.
1896 (cond ((eq custom-buffer-style 'tree)
1897 (insert prefix (if last " `--- " " |--- "))
1898 (push (widget-create-child-and-convert
1899 widget 'custom-browse-variable-tag)
1901 (insert " " tag "\n")
1902 (widget-put widget :buttons buttons))
1904 ;; Indicate hidden value.
1905 (push (widget-create-child-and-convert
1908 :sample-face 'custom-variable-tag-face
1912 (push (widget-create-child-and-convert
1914 :help-echo "Show the value of this option."
1915 :action 'custom-toggle-parent
1918 ((memq form '(lisp mismatch))
1919 ;; In lisp mode edit the saved value when possible.
1920 (let* ((value (cond ((get symbol 'saved-value)
1921 (car (get symbol 'saved-value)))
1922 ((get symbol 'standard-value)
1923 (car (get symbol 'standard-value)))
1924 ((default-boundp symbol)
1925 (custom-quote (funcall get symbol)))
1927 (custom-quote (widget-get conv :value))))))
1928 (insert (symbol-name symbol) ": ")
1929 (push (widget-create-child-and-convert
1931 :help-echo "Hide the value of this option."
1932 :action 'custom-toggle-parent
1936 (push (widget-create-child-and-convert
1938 :button-face 'custom-variable-button-face
1940 :tag (symbol-name symbol)
1946 (let* ((format (widget-get type :format))
1947 tag-format value-format)
1948 (unless (string-match ":" format)
1949 (error "Bad format"))
1950 (setq tag-format (substring format 0 (match-end 0)))
1951 (setq value-format (substring format (match-end 0)))
1952 (push (widget-create-child-and-convert
1955 :action 'custom-tag-action
1956 :help-echo "Change value of this option."
1957 :mouse-down-action 'custom-tag-mouse-down-action
1958 :button-face 'custom-variable-button-face
1959 :sample-face 'custom-variable-tag-face
1963 (push (widget-create-child-and-convert
1965 :help-echo "Hide the value of this option."
1966 :action 'custom-toggle-parent
1969 (push (widget-create-child-and-convert
1971 :format value-format
1974 (unless (eq custom-buffer-style 'tree)
1975 ;; Now update the state.
1976 (unless (eq (preceding-char) ?\n)
1977 (widget-insert "\n"))
1978 (if (eq state 'hidden)
1979 (widget-put widget :custom-state state)
1980 (custom-variable-state-set widget))
1981 ;; Create the magic button.
1982 (let ((magic (widget-create-child-and-convert
1983 widget 'custom-magic nil)))
1984 (widget-put widget :custom-magic magic)
1985 (push magic buttons))
1986 ;; Update properties.
1987 (widget-put widget :custom-form form)
1988 (widget-put widget :buttons buttons)
1989 (widget-put widget :children children)
1990 ;; Insert documentation.
1991 (widget-default-format-handler widget ?h)
1993 (unless (eq state 'hidden)
1994 (when (eq (widget-get widget :custom-level) 1)
1995 (custom-add-parent-links widget))
1996 (custom-add-see-also widget)))))
1998 (defun custom-tag-action (widget &rest args)
1999 "Pass :action to first child of WIDGET's parent."
2000 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
2003 (defun custom-tag-mouse-down-action (widget &rest args)
2004 "Pass :mouse-down-action to first child of WIDGET's parent."
2005 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
2006 :mouse-down-action args))
2008 (defun custom-variable-state-set (widget)
2009 "Set the state of WIDGET."
2010 (let* ((symbol (widget-value widget))
2011 (get (or (get symbol 'custom-get) 'default-value))
2012 (value (if (default-boundp symbol)
2013 (funcall get symbol)
2014 (widget-get widget :value)))
2016 (state (cond ((setq tmp (get symbol 'customized-value))
2017 (if (condition-case nil
2018 (equal value (eval (car tmp)))
2022 ((setq tmp (get symbol 'saved-value))
2023 (if (condition-case nil
2024 (equal value (eval (car tmp)))
2028 ((setq tmp (get symbol 'standard-value))
2029 (if (condition-case nil
2030 (equal value (eval (car tmp)))
2035 (widget-put widget :custom-state state)))
2037 (defvar custom-variable-menu
2038 '(("Set for Current Session" custom-variable-set
2040 (eq (widget-get widget :custom-state) 'modified)))
2041 ("Save for Future Sessions" custom-variable-save
2043 (memq (widget-get widget :custom-state) '(modified set changed rogue))))
2044 ("Reset to Current" custom-redraw
2046 (and (default-boundp (widget-value widget))
2047 (memq (widget-get widget :custom-state) '(modified changed)))))
2048 ("Reset to Saved" custom-variable-reset-saved
2050 (and (get (widget-value widget) 'saved-value)
2051 (memq (widget-get widget :custom-state)
2052 '(modified set changed rogue)))))
2053 ("Reset to Standard Settings" custom-variable-reset-standard
2055 (and (get (widget-value widget) 'standard-value)
2056 (memq (widget-get widget :custom-state)
2057 '(modified set changed saved rogue)))))
2058 ("---" ignore ignore)
2059 ("Don't show as Lisp expression" custom-variable-edit
2061 (eq (widget-get widget :custom-form) 'lisp)))
2062 ("Show initial Lisp expression" custom-variable-edit-lisp
2064 (eq (widget-get widget :custom-form) 'edit))))
2065 "Alist of actions for the `custom-variable' widget.
2066 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2067 the menu entry, ACTION is the function to call on the widget when the
2068 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2069 widget as an argument, and returns non-nil if ACTION is valid on that
2070 widget. If FILTER is nil, ACTION is always valid.")
2072 (defun custom-variable-action (widget &optional event)
2073 "Show the menu for `custom-variable' WIDGET.
2074 Optional EVENT is the location for the menu."
2075 (if (eq (widget-get widget :custom-state) 'hidden)
2076 (custom-toggle-hide widget)
2077 (unless (eq (widget-get widget :custom-state) 'modified)
2078 (custom-variable-state-set widget))
2079 (custom-redraw-magic widget)
2080 (let* ((completion-ignore-case t)
2081 (answer (widget-choose (concat "Operation on "
2082 (custom-unlispify-tag-name
2083 (widget-get widget :value)))
2084 (custom-menu-filter custom-variable-menu
2088 (funcall answer widget)))))
2090 (defun custom-variable-edit (widget)
2091 "Edit value of WIDGET."
2092 (widget-put widget :custom-state 'unknown)
2093 (widget-put widget :custom-form 'edit)
2094 (custom-redraw widget))
2096 (defun custom-variable-edit-lisp (widget)
2097 "Edit the lisp representation of the value of WIDGET."
2098 (widget-put widget :custom-state 'unknown)
2099 (widget-put widget :custom-form 'lisp)
2100 (custom-redraw widget))
2102 (defun custom-variable-set (widget)
2103 "Set the current value for the variable being edited by WIDGET."
2104 (let* ((form (widget-get widget :custom-form))
2105 (state (widget-get widget :custom-state))
2106 (child (car (widget-get widget :children)))
2107 (symbol (widget-value widget))
2108 (set (or (get symbol 'custom-set) 'set-default))
2110 (cond ((eq state 'hidden)
2111 (error "Cannot set hidden variable"))
2112 ((setq val (widget-apply child :validate))
2113 (goto-char (widget-get val :from))
2114 (error "%s" (widget-get val :error)))
2115 ((memq form '(lisp mismatch))
2116 (funcall set symbol (eval (setq val (widget-value child))))
2117 (put symbol 'customized-value (list val)))
2119 (funcall set symbol (setq val (widget-value child)))
2120 (put symbol 'customized-value (list (custom-quote val)))))
2121 (custom-variable-state-set widget)
2122 (custom-redraw-magic widget)))
2124 (defun custom-variable-save (widget)
2125 "Set and save the value for the variable being edited by WIDGET."
2126 (let* ((form (widget-get widget :custom-form))
2127 (state (widget-get widget :custom-state))
2128 (child (car (widget-get widget :children)))
2129 (symbol (widget-value widget))
2130 (set (or (get symbol 'custom-set) 'set-default))
2132 (cond ((eq state 'hidden)
2133 (error "Cannot set hidden variable"))
2134 ((setq val (widget-apply child :validate))
2135 (goto-char (widget-get val :from))
2136 (error "%s" (widget-get val :error)))
2137 ((memq form '(lisp mismatch))
2138 (put symbol 'saved-value (list (widget-value child)))
2139 (funcall set symbol (eval (widget-value child))))
2142 'saved-value (list (custom-quote (widget-value
2144 (funcall set symbol (widget-value child))))
2145 (put symbol 'customized-value nil)
2147 (custom-variable-state-set widget)
2148 (custom-redraw-magic widget)))
2150 (defun custom-variable-reset-saved (widget)
2151 "Restore the saved value for the variable being edited by WIDGET."
2152 (let* ((symbol (widget-value widget))
2153 (set (or (get symbol 'custom-set) 'set-default)))
2154 (if (get symbol 'saved-value)
2156 (funcall set symbol (eval (car (get symbol 'saved-value))))
2158 (error "No saved value for %s" symbol))
2159 (put symbol 'customized-value nil)
2160 (widget-put widget :custom-state 'unknown)
2161 (custom-redraw widget)))
2163 (defun custom-variable-reset-standard (widget)
2164 "Restore the standard setting for the variable being edited by WIDGET."
2165 (let* ((symbol (widget-value widget))
2166 (set (or (get symbol 'custom-set) 'set-default)))
2167 (if (get symbol 'standard-value)
2168 (funcall set symbol (eval (car (get symbol 'standard-value))))
2169 (error "No standard setting known for %S" symbol))
2170 (put symbol 'customized-value nil)
2171 (when (get symbol 'saved-value)
2172 (put symbol 'saved-value nil)
2174 (widget-put widget :custom-state 'unknown)
2175 (custom-redraw widget)))
2177 ;;; The `custom-face-edit' Widget.
2179 (define-widget 'custom-face-edit 'checklist
2180 "Edit face attributes."
2184 :button-args '(:help-echo "Control whether this attribute have any effect.")
2185 :args (mapcar (lambda (att)
2188 :sibling-args (widget-get (nth 1 att) :sibling-args)
2189 (list 'const :format "" :value (nth 0 att))
2191 custom-face-attributes))
2193 ;;; The `custom-display' Widget.
2195 (define-widget 'custom-display 'menu-choice
2196 "Select a display type."
2199 :help-echo "Specify frames where the face attributes should be used."
2200 :args '((const :tag "all" t)
2204 :args ((group :sibling-args (:help-echo "\
2205 Only match the specified window systems.")
2206 (const :format "Type: "
2208 (checklist :inline t
2211 :sibling-args (:help-echo "\
2212 The X11 Window System.")
2214 (const :format "PM "
2215 :sibling-args (:help-echo "\
2216 OS/2 Presentation Manager.")
2218 (const :format "W32 "
2219 :sibling-args (:help-echo "\
2222 (const :format "DOS "
2223 :sibling-args (:help-echo "\
2226 (const :format "TTY%n"
2227 :sibling-args (:help-echo "\
2228 Plain text terminals.")
2230 (group :sibling-args (:help-echo "\
2231 Only match the frames with the specified color support.")
2232 (const :format "Class: "
2234 (checklist :inline t
2236 (const :format "Color "
2237 :sibling-args (:help-echo "\
2238 Match color frames.")
2240 (const :format "Grayscale "
2241 :sibling-args (:help-echo "\
2242 Match grayscale frames.")
2244 (const :format "Monochrome%n"
2245 :sibling-args (:help-echo "\
2246 Match frames with no color support.")
2248 (group :sibling-args (:help-echo "\
2249 Only match frames with the specified intensity.")
2251 Background brightness: "
2253 (checklist :inline t
2255 (const :format "Light "
2256 :sibling-args (:help-echo "\
2257 Match frames with light backgrounds.")
2259 (const :format "Dark\n"
2260 :sibling-args (:help-echo "\
2261 Match frames with dark backgrounds.")
2264 ;;; The `custom-face' Widget.
2266 (defface custom-face-tag-face '((t (:underline t)))
2267 "Face used for face tags."
2268 :group 'custom-faces)
2270 (defcustom custom-face-default-form 'selected
2271 "Default form of displaying face definition."
2272 :type '(choice (const all)
2275 :group 'custom-buffer
2278 (define-widget 'custom-face 'custom
2280 :sample-face 'custom-face-tag-face
2281 :help-echo "Set or reset this face."
2282 :documentation-property '(lambda (face)
2283 (face-doc-string face))
2284 :value-create 'custom-face-value-create
2285 :action 'custom-face-action
2286 :custom-category 'face
2287 :custom-form nil ; defaults to value of `custom-face-default-form'
2288 :custom-set 'custom-face-set
2289 :custom-save 'custom-face-save
2290 :custom-reset-current 'custom-redraw
2291 :custom-reset-saved 'custom-face-reset-saved
2292 :custom-reset-standard 'custom-face-reset-standard
2293 :custom-menu 'custom-face-menu-create)
2295 (define-widget 'custom-face-all 'editable-list
2296 "An editable list of display specifications and attributes."
2297 :entry-format "%i %d %v"
2298 :insert-button-args '(:help-echo "Insert new display specification here.")
2299 :append-button-args '(:help-echo "Append new display specification here.")
2300 :delete-button-args '(:help-echo "Delete this display specification.")
2301 :args '((group :format "%v" custom-display custom-face-edit)))
2303 (defconst custom-face-all (widget-convert 'custom-face-all)
2304 "Converted version of the `custom-face-all' widget.")
2306 (define-widget 'custom-display-unselected 'item
2307 "A display specification that doesn't match the selected display."
2308 :match 'custom-display-unselected-match)
2310 (defun custom-display-unselected-match (widget value)
2311 "Non-nil if VALUE is an unselected display specification."
2312 (not (face-spec-set-match-display value (selected-frame))))
2314 (define-widget 'custom-face-selected 'group
2315 "Edit the attributes of the selected display in a face specification."
2316 :args '((repeat :format ""
2318 (group custom-display-unselected sexp))
2319 (group (sexp :format "") custom-face-edit)
2324 (defconst custom-face-selected (widget-convert 'custom-face-selected)
2325 "Converted version of the `custom-face-selected' widget.")
2327 (defun custom-face-value-create (widget)
2328 "Create a list of the display specifications for WIDGET."
2329 (let ((buttons (widget-get widget :buttons))
2330 (symbol (widget-get widget :value))
2331 (tag (widget-get widget :tag))
2332 (state (widget-get widget :custom-state))
2334 (is-last (widget-get widget :custom-last))
2335 (prefix (widget-get widget :custom-prefix)))
2337 (setq tag (prin1-to-string symbol)))
2338 (cond ((eq custom-buffer-style 'tree)
2339 (insert prefix (if is-last " `--- " " |--- "))
2340 (push (widget-create-child-and-convert
2341 widget 'custom-browse-face-tag)
2343 (insert " " tag "\n")
2344 (widget-put widget :buttons buttons))
2348 (if (eq custom-buffer-style 'face)
2350 (widget-specify-sample widget begin (point))
2353 (and (string-match "XEmacs" emacs-version)
2354 ;; XEmacs cannot display uninitialized faces.
2355 (not (custom-facep symbol))
2356 (copy-face 'custom-face-empty symbol))
2357 (push (widget-create-child-and-convert widget 'item
2364 (push (widget-create-child-and-convert
2366 :help-echo "Hide or show this face."
2367 :action 'custom-toggle-parent
2368 (not (eq state 'hidden)))
2372 (let ((magic (widget-create-child-and-convert
2373 widget 'custom-magic nil)))
2374 (widget-put widget :custom-magic magic)
2375 (push magic buttons))
2377 (widget-put widget :buttons buttons)
2378 ;; Insert documentation.
2379 (widget-default-format-handler widget ?h)
2381 (unless (eq state 'hidden)
2382 (when (eq (widget-get widget :custom-level) 1)
2383 (custom-add-parent-links widget))
2384 (custom-add-see-also widget))
2386 (unless (eq (preceding-char) ?\n)
2388 (unless (eq state 'hidden)
2389 (message "Creating face editor...")
2390 (custom-load-widget widget)
2391 (unless (widget-get widget :custom-form)
2392 (widget-put widget :custom-form custom-face-default-form))
2393 (let* ((symbol (widget-value widget))
2394 (spec (or (get symbol 'saved-face)
2395 (get symbol 'face-defface-spec)
2396 ;; Attempt to construct it.
2397 (list (list t (custom-face-attributes-get
2398 symbol (selected-frame))))))
2399 (form (widget-get widget :custom-form))
2400 (indent (widget-get widget :indent))
2402 ;; If the user has changed this face in some other way,
2403 ;; edit it as the user has specified it.
2404 (if (not (face-spec-match-p symbol spec (selected-frame)))
2405 (setq spec (list (list t (face-attr-construct symbol (selected-frame))))))
2406 (setq edit (widget-create-child-and-convert
2408 (cond ((and (eq form 'selected)
2409 (widget-apply custom-face-selected
2411 (when indent (insert-char ?\ indent))
2412 'custom-face-selected)
2413 ((and (not (eq form 'lisp))
2414 (widget-apply custom-face-all
2418 (when indent (insert-char ?\ indent))
2421 (custom-face-state-set widget)
2422 (widget-put widget :children (list edit)))
2423 (message "Creating face editor...done"))))))
2425 (defvar custom-face-menu
2426 '(("Set for Current Session" custom-face-set)
2427 ("Save for Future Sessions" custom-face-save-command)
2428 ("Reset to Saved" custom-face-reset-saved
2430 (get (widget-value widget) 'saved-face)))
2431 ("Reset to Standard Setting" custom-face-reset-standard
2433 (get (widget-value widget) 'face-defface-spec)))
2434 ("---" ignore ignore)
2435 ("Show all display specs" custom-face-edit-all
2437 (not (eq (widget-get widget :custom-form) 'all))))
2438 ("Just current attributes" custom-face-edit-selected
2440 (not (eq (widget-get widget :custom-form) 'selected))))
2441 ("Show as Lisp expression" custom-face-edit-lisp
2443 (not (eq (widget-get widget :custom-form) 'lisp)))))
2444 "Alist of actions for the `custom-face' widget.
2445 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2446 the menu entry, ACTION is the function to call on the widget when the
2447 menu is selected, and FILTER is a predicate which takes a `custom-face'
2448 widget as an argument, and returns non-nil if ACTION is valid on that
2449 widget. If FILTER is nil, ACTION is always valid.")
2451 (defun custom-face-edit-selected (widget)
2452 "Edit selected attributes of the value of WIDGET."
2453 (widget-put widget :custom-state 'unknown)
2454 (widget-put widget :custom-form 'selected)
2455 (custom-redraw widget))
2457 (defun custom-face-edit-all (widget)
2458 "Edit all attributes of the value of WIDGET."
2459 (widget-put widget :custom-state 'unknown)
2460 (widget-put widget :custom-form 'all)
2461 (custom-redraw widget))
2463 (defun custom-face-edit-lisp (widget)
2464 "Edit the lisp representation of the value of WIDGET."
2465 (widget-put widget :custom-state 'unknown)
2466 (widget-put widget :custom-form 'lisp)
2467 (custom-redraw widget))
2469 (defun custom-face-state-set (widget)
2470 "Set the state of WIDGET."
2471 (let ((symbol (widget-value widget)))
2472 (widget-put widget :custom-state (cond ((get symbol 'customized-face)
2474 ((get symbol 'saved-face)
2476 ((get symbol 'face-defface-spec)
2481 (defun custom-face-action (widget &optional event)
2482 "Show the menu for `custom-face' WIDGET.
2483 Optional EVENT is the location for the menu."
2484 (if (eq (widget-get widget :custom-state) 'hidden)
2485 (custom-toggle-hide widget)
2486 (let* ((completion-ignore-case t)
2487 (symbol (widget-get widget :value))
2488 (answer (widget-choose (concat "Operation on "
2489 (custom-unlispify-tag-name symbol))
2490 (custom-menu-filter custom-face-menu
2494 (funcall answer widget)))))
2496 (defun custom-face-set (widget)
2497 "Make the face attributes in WIDGET take effect."
2498 (let* ((symbol (widget-value widget))
2499 (child (car (widget-get widget :children)))
2500 (value (widget-value child)))
2501 (put symbol 'customized-face value)
2502 (face-spec-set symbol value)
2503 (custom-face-state-set widget)
2504 (custom-redraw-magic widget)))
2506 (defun custom-face-save-command (widget)
2507 "Save in `.emacs' the face attributes in WIDGET."
2508 (custom-face-save widget)
2511 (defun custom-face-save (widget)
2512 "Prepare for saving WIDGET's face attributes, but don't write `.emacs'."
2513 (let* ((symbol (widget-value widget))
2514 (child (car (widget-get widget :children)))
2515 (value (widget-value child)))
2516 (face-spec-set symbol value)
2517 (put symbol 'saved-face value)
2518 (put symbol 'customized-face nil)
2520 (custom-face-state-set widget)
2521 (custom-redraw-magic widget)))
2523 (defun custom-face-reset-saved (widget)
2524 "Restore WIDGET to the face's default attributes."
2525 (let* ((symbol (widget-value widget))
2526 (child (car (widget-get widget :children)))
2527 (value (get symbol 'saved-face)))
2529 (error "No saved value for this face"))
2530 (put symbol 'customized-face nil)
2531 (face-spec-set symbol value)
2532 (widget-value-set child value)
2533 (custom-face-state-set widget)
2534 (custom-redraw-magic widget)))
2536 (defun custom-face-reset-standard (widget)
2537 "Restore WIDGET to the face's standard settings."
2538 (let* ((symbol (widget-value widget))
2539 (child (car (widget-get widget :children)))
2540 (value (get symbol 'face-defface-spec)))
2542 (error "No standard setting for this face"))
2543 (put symbol 'customized-face nil)
2544 (when (get symbol 'saved-face)
2545 (put symbol 'saved-face nil)
2547 (face-spec-set symbol value)
2548 (widget-value-set child value)
2549 (custom-face-state-set widget)
2550 (custom-redraw-magic widget)))
2552 ;;; The `face' Widget.
2554 (define-widget 'face 'default
2555 "Select and customize a face."
2556 :convert-widget 'widget-value-convert-widget
2557 :button-prefix 'widget-push-button-prefix
2558 :button-suffix 'widget-push-button-suffix
2559 :format "%t: %[select face%] %v"
2562 :value-create 'widget-face-value-create
2563 :value-delete 'widget-face-value-delete
2564 :value-get 'widget-value-value-get
2565 :validate 'widget-children-validate
2566 :action 'widget-face-action
2567 :match '(lambda (widget value) (symbolp value)))
2569 (defun widget-face-value-create (widget)
2570 ;; Create a `custom-face' child.
2571 (let* ((symbol (widget-value widget))
2572 (custom-buffer-style 'face)
2573 (child (widget-create-child-and-convert
2577 (custom-magic-reset child)
2578 (setq custom-options (cons child custom-options))
2579 (widget-put widget :children (list child))))
2581 (defun widget-face-value-delete (widget)
2582 ;; Remove the child from the options.
2583 (let ((child (car (widget-get widget :children))))
2584 (setq custom-options (delq child custom-options))
2585 (widget-children-value-delete widget)))
2587 (defvar face-history nil
2588 "History of entered face names.")
2590 (defun widget-face-action (widget &optional event)
2591 "Prompt for a face."
2592 (let ((answer (completing-read "Face: "
2593 (mapcar (lambda (face)
2594 (list (symbol-name face)))
2598 (unless (zerop (length answer))
2599 (widget-value-set widget (intern answer))
2600 (widget-apply widget :notify widget event)
2603 ;;; The `hook' Widget.
2605 (define-widget 'hook 'list
2607 :value-to-internal (lambda (widget value)
2608 (if (and value (symbolp value))
2611 :match (lambda (widget value)
2613 (widget-group-match widget value)))
2614 :convert-widget 'custom-hook-convert-widget
2617 (defun custom-hook-convert-widget (widget)
2618 ;; Handle `:custom-options'.
2619 (let* ((options (widget-get widget :options))
2620 (other `(editable-list :inline t
2621 :entry-format "%i %d%v"
2622 (function :format " %v")))
2624 (list `(checklist :inline t
2625 ,@(mapcar (lambda (entry)
2626 `(function-item ,entry))
2630 (widget-put widget :args args)
2633 ;;; The `custom-group-link' Widget.
2635 (define-widget 'custom-group-link 'link
2636 "Show parent in other window when activated."
2637 :help-echo "Create customization buffer for this group."
2638 :action 'custom-group-link-action)
2640 (defun custom-group-link-action (widget &rest ignore)
2641 (customize-group (widget-value widget)))
2643 ;;; The `custom-group' Widget.
2645 (defcustom custom-group-tag-faces nil
2646 ;; In XEmacs, this ought to play games with font size.
2647 "Face used for group tags.
2648 The first member is used for level 1 groups, the second for level 2,
2649 and so forth. The remaining group tags are shown with
2650 `custom-group-tag-face'."
2651 :type '(repeat face)
2652 :group 'custom-faces)
2654 (defface custom-group-tag-face-1 '((((class color)
2656 (:foreground "pink" :underline t))
2659 (:foreground "red" :underline t))
2661 "Face used for group tags.")
2663 (defface custom-group-tag-face '((((class color)
2665 (:foreground "light blue" :underline t))
2668 (:foreground "blue" :underline t))
2670 "Face used for low level group tags."
2671 :group 'custom-faces)
2673 (define-widget 'custom-group 'custom
2676 :sample-face-get 'custom-group-sample-face-get
2677 :documentation-property 'group-documentation
2678 :help-echo "Set or reset all members of this group."
2679 :value-create 'custom-group-value-create
2680 :action 'custom-group-action
2681 :custom-category 'group
2682 :custom-set 'custom-group-set
2683 :custom-save 'custom-group-save
2684 :custom-reset-current 'custom-group-reset-current
2685 :custom-reset-saved 'custom-group-reset-saved
2686 :custom-reset-standard 'custom-group-reset-standard
2687 :custom-menu 'custom-group-menu-create)
2689 (defun custom-group-sample-face-get (widget)
2690 ;; Use :sample-face.
2691 (or (nth (1- (widget-get widget :custom-level)) custom-group-tag-faces)
2692 'custom-group-tag-face))
2694 (define-widget 'custom-group-visibility 'visibility
2695 "An indicator and manipulator for hidden group contents."
2696 :create 'custom-group-visibility-create)
2698 (defun custom-group-visibility-create (widget)
2699 (let ((visible (widget-value widget)))
2701 (insert "--------")))
2702 (widget-default-create widget))
2704 (defun custom-group-members (symbol groups-only)
2705 "Return SYMBOL's custom group members.
2706 If GROUPS-ONLY non-nil, return only those members that are groups."
2707 (if (not groups-only)
2708 (get symbol 'custom-group)
2710 (dolist (entry (get symbol 'custom-group))
2711 (when (eq (nth 1 entry) 'custom-group)
2712 (push entry members)))
2713 (nreverse members))))
2715 (defun custom-group-value-create (widget)
2716 "Insert a customize group for WIDGET in the current buffer."
2717 (let* ((state (widget-get widget :custom-state))
2718 (level (widget-get widget :custom-level))
2719 ;; (indent (widget-get widget :indent))
2720 (prefix (widget-get widget :custom-prefix))
2721 (buttons (widget-get widget :buttons))
2722 (tag (widget-get widget :tag))
2723 (symbol (widget-value widget))
2724 (members (custom-group-members symbol
2725 (and (eq custom-buffer-style 'tree)
2726 custom-browse-only-groups))))
2727 (cond ((and (eq custom-buffer-style 'tree)
2729 (or members (custom-unloaded-widget-p widget)))
2730 (custom-browse-insert-prefix prefix)
2731 (push (widget-create-child-and-convert
2732 widget 'custom-browse-visibility
2733 ;; :tag-glyph "plus"
2737 ;; (widget-glyph-insert nil "-- " "horizontal")
2738 (push (widget-create-child-and-convert
2739 widget 'custom-browse-group-tag)
2741 (insert " " tag "\n")
2742 (widget-put widget :buttons buttons))
2743 ((and (eq custom-buffer-style 'tree)
2744 (zerop (length members)))
2745 (custom-browse-insert-prefix prefix)
2747 ;; (widget-glyph-insert nil "[ ]" "empty")
2748 ;; (widget-glyph-insert nil "-- " "horizontal")
2749 (push (widget-create-child-and-convert
2750 widget 'custom-browse-group-tag)
2752 (insert " " tag "\n")
2753 (widget-put widget :buttons buttons))
2754 ((eq custom-buffer-style 'tree)
2755 (custom-browse-insert-prefix prefix)
2756 (custom-load-widget widget)
2757 (if (zerop (length members))
2759 (custom-browse-insert-prefix prefix)
2761 ;; (widget-glyph-insert nil "[ ]" "empty")
2762 ;; (widget-glyph-insert nil "-- " "horizontal")
2763 (push (widget-create-child-and-convert
2764 widget 'custom-browse-group-tag)
2766 (insert " " tag "\n")
2767 (widget-put widget :buttons buttons))
2768 (push (widget-create-child-and-convert
2769 widget 'custom-browse-visibility
2770 ;; :tag-glyph "minus"
2774 ;; (widget-glyph-insert nil "-\\ " "top")
2775 (push (widget-create-child-and-convert
2776 widget 'custom-browse-group-tag)
2778 (insert " " tag "\n")
2779 (widget-put widget :buttons buttons)
2780 (message "Creating group...")
2781 (let* ((members (custom-sort-items members
2782 custom-browse-sort-alphabetically
2783 custom-browse-order-groups))
2784 (prefixes (widget-get widget :custom-prefixes))
2785 (custom-prefix-list (custom-prefix-add symbol prefixes))
2786 (extra-prefix (if (widget-get widget :custom-last)
2789 (prefix (concat prefix extra-prefix))
2792 (setq entry (car members)
2793 members (cdr members))
2794 (push (widget-create-child-and-convert
2795 widget (nth 1 entry)
2797 :tag (custom-unlispify-tag-name (nth 0 entry))
2798 :custom-prefixes custom-prefix-list
2799 :custom-level (1+ level)
2800 :custom-last (null members)
2801 :value (nth 0 entry)
2802 :custom-prefix prefix)
2804 (widget-put widget :children (reverse children)))
2805 (message "Creating group...done")))
2808 ;; Create level indicator.
2809 (unless (eq custom-buffer-style 'links)
2810 (insert-char ?\ (* custom-buffer-indent (1- level)))
2813 (let ((begin (point)))
2815 (widget-specify-sample widget begin (point)))
2817 ;; Create link/visibility indicator.
2818 (if (eq custom-buffer-style 'links)
2819 (push (widget-create-child-and-convert
2820 widget 'custom-group-link
2824 (push (widget-create-child-and-convert
2825 widget 'custom-group-visibility
2826 :help-echo "Show members of this group."
2827 :action 'custom-toggle-parent
2828 (not (eq state 'hidden)))
2831 ;; Create magic button.
2832 (let ((magic (widget-create-child-and-convert
2833 widget 'custom-magic nil)))
2834 (widget-put widget :custom-magic magic)
2835 (push magic buttons))
2837 (widget-put widget :buttons buttons)
2838 ;; Insert documentation.
2839 (if (and (eq custom-buffer-style 'links) (> level 1))
2840 (widget-put widget :documentation-indent 0))
2841 (widget-default-format-handler widget ?h))
2844 ;; Add parent groups references above the group.
2845 (if t ;;; This should test that the buffer
2846 ;;; was made to display a group.
2848 (if (custom-add-parent-links widget
2849 "Go to parent group:")
2851 ;; Create level indicator.
2852 (insert-char ?\ (* custom-buffer-indent (1- level)))
2855 (let ((start (point)))
2857 (widget-specify-sample widget start (point)))
2859 ;; Create visibility indicator.
2860 (unless (eq custom-buffer-style 'links)
2862 (push (widget-create-child-and-convert
2864 :help-echo "Hide members of this group."
2865 :action 'custom-toggle-parent
2866 (not (eq state 'hidden)))
2869 ;; Create more dashes.
2870 ;; Use 76 instead of 75 to compensate for the temporary "<"
2871 ;; added by `widget-insert'.
2872 (insert-char ?- (- 76 (current-column)
2873 (* custom-buffer-indent level)))
2875 ;; Create magic button.
2876 (let ((magic (widget-create-child-and-convert
2877 widget 'custom-magic
2880 (widget-put widget :custom-magic magic)
2881 (push magic buttons))
2883 (widget-put widget :buttons buttons)
2884 ;; Insert documentation.
2885 (widget-default-format-handler widget ?h)
2887 (if nil ;;; This should test that the buffer
2888 ;;; was not made to display a group.
2890 (insert-char ?\ custom-buffer-indent)
2891 (custom-add-parent-links widget)))
2892 (custom-add-see-also widget
2893 (make-string (* custom-buffer-indent level)
2896 (message "Creating group...")
2897 (custom-load-widget widget)
2898 (let* ((members (custom-sort-items members
2899 custom-buffer-sort-alphabetically
2900 custom-buffer-order-groups))
2901 (prefixes (widget-get widget :custom-prefixes))
2902 (custom-prefix-list (custom-prefix-add symbol prefixes))
2903 (length (length members))
2905 (children (mapcar (lambda (entry)
2906 (widget-insert "\n")
2908 Creating group members... %2d%%"
2909 (/ (* 100.0 count) length))
2910 (setq count (1+ count))
2912 (widget-create-child-and-convert
2913 widget (nth 1 entry)
2915 :tag (custom-unlispify-tag-name
2917 :custom-prefixes custom-prefix-list
2918 :custom-level (1+ level)
2919 :value (nth 0 entry))
2920 (unless (eq (preceding-char) ?\n)
2921 (widget-insert "\n"))))
2923 (message "Creating group magic...")
2924 (mapcar 'custom-magic-reset children)
2925 (message "Creating group state...")
2926 (widget-put widget :children children)
2927 (custom-group-state-update widget)
2928 (message "Creating group... done"))
2931 (insert-char ?\ (* custom-buffer-indent (1- level)))
2932 (insert "\\- " (widget-get widget :tag) " group end ")
2933 (insert-char ?- (- 75 (current-column) (* custom-buffer-indent level)))
2936 (defvar custom-group-menu
2937 '(("Set for Current Session" custom-group-set
2939 (eq (widget-get widget :custom-state) 'modified)))
2940 ("Save for Future Sessions" custom-group-save
2942 (memq (widget-get widget :custom-state) '(modified set))))
2943 ("Reset to Current" custom-group-reset-current
2945 (memq (widget-get widget :custom-state) '(modified))))
2946 ("Reset to Saved" custom-group-reset-saved
2948 (memq (widget-get widget :custom-state) '(modified set))))
2949 ("Reset to standard setting" custom-group-reset-standard
2951 (memq (widget-get widget :custom-state) '(modified set saved)))))
2952 "Alist of actions for the `custom-group' widget.
2953 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2954 the menu entry, ACTION is the function to call on the widget when the
2955 menu is selected, and FILTER is a predicate which takes a `custom-group'
2956 widget as an argument, and returns non-nil if ACTION is valid on that
2957 widget. If FILTER is nil, ACTION is always valid.")
2959 (defun custom-group-action (widget &optional event)
2960 "Show the menu for `custom-group' WIDGET.
2961 Optional EVENT is the location for the menu."
2962 (if (eq (widget-get widget :custom-state) 'hidden)
2963 (custom-toggle-hide widget)
2964 (let* ((completion-ignore-case t)
2965 (answer (widget-choose (concat "Operation on "
2966 (custom-unlispify-tag-name
2967 (widget-get widget :value)))
2968 (custom-menu-filter custom-group-menu
2972 (funcall answer widget)))))
2974 (defun custom-group-set (widget)
2975 "Set changes in all modified group members."
2976 (let ((children (widget-get widget :children)))
2977 (mapcar (lambda (child)
2978 (when (eq (widget-get child :custom-state) 'modified)
2979 (widget-apply child :custom-set)))
2982 (defun custom-group-save (widget)
2983 "Save all modified group members."
2984 (let ((children (widget-get widget :children)))
2985 (mapcar (lambda (child)
2986 (when (memq (widget-get child :custom-state) '(modified set))
2987 (widget-apply child :custom-save)))
2990 (defun custom-group-reset-current (widget)
2991 "Reset all modified group members."
2992 (let ((children (widget-get widget :children)))
2993 (mapcar (lambda (child)
2994 (when (eq (widget-get child :custom-state) 'modified)
2995 (widget-apply child :custom-reset-current)))
2998 (defun custom-group-reset-saved (widget)
2999 "Reset all modified or set group members."
3000 (let ((children (widget-get widget :children)))
3001 (mapcar (lambda (child)
3002 (when (memq (widget-get child :custom-state) '(modified set))
3003 (widget-apply child :custom-reset-saved)))
3006 (defun custom-group-reset-standard (widget)
3007 "Reset all modified, set, or saved group members."
3008 (let ((children (widget-get widget :children)))
3009 (mapcar (lambda (child)
3010 (when (memq (widget-get child :custom-state)
3011 '(modified set saved))
3012 (widget-apply child :custom-reset-standard)))
3015 (defun custom-group-state-update (widget)
3017 (unless (eq (widget-get widget :custom-state) 'hidden)
3018 (let* ((children (widget-get widget :children))
3019 (states (mapcar (lambda (child)
3020 (widget-get child :custom-state))
3022 (magics custom-magic-alist)
3025 (let ((magic (car (car magics))))
3026 (if (and (not (eq magic 'hidden))
3027 (memq magic states))
3030 (setq magics (cdr magics)))))
3031 (widget-put widget :custom-state found)))
3032 (custom-magic-reset widget))
3034 ;;; The `custom-save-all' Function.
3036 (defcustom custom-file nil
3037 "File used for storing customization information.
3038 The default is nil, which means to use your init file
3039 as specified by `user-init-file'. If you specify some other file,
3040 you need to explicitly load that file for the settings to take effect."
3041 :type '(choice (const :tag "Your Emacs init file" nil) file)
3044 (defun custom-file ()
3045 "Return the file name for saving customizations."
3049 (read-file-name "File for customizations: "
3050 "~/" nil nil ".emacs"))))
3052 (defun custom-save-delete (symbol)
3053 "Delete the call to SYMBOL from `custom-file'.
3054 Leave point at the location of the call, or after the last expression."
3055 (let ((default-major-mode))
3056 (set-buffer (find-file-noselect (custom-file))))
3057 (goto-char (point-min))
3060 (let ((sexp (condition-case nil
3061 (read (current-buffer))
3062 (end-of-file (throw 'found nil)))))
3063 (when (and (listp sexp)
3064 (eq (car sexp) symbol))
3065 (delete-region (save-excursion
3069 (throw 'found nil))))))
3071 (defun custom-save-variables ()
3072 "Save all customized variables in `custom-file'."
3074 (custom-save-delete 'custom-set-variables)
3075 (let ((standard-output (current-buffer)))
3078 (princ "(custom-set-variables")
3079 (mapatoms (lambda (symbol)
3080 (let ((value (get symbol 'saved-value))
3081 (requests (get symbol 'custom-requests))
3082 (now (not (or (get symbol 'standard-value)
3083 (and (not (boundp symbol))
3084 (not (get symbol 'force-value)))))))
3101 (unless (looking-at "\n")
3104 (defun custom-save-faces ()
3105 "Save all customized faces in `custom-file'."
3107 (custom-save-delete 'custom-set-faces)
3108 (let ((standard-output (current-buffer)))
3111 (princ "(custom-set-faces")
3112 (let ((value (get 'default 'saved-face)))
3113 ;; The default face must be first, since it affects the others.
3115 (princ "\n '(default ")
3117 (if (or (get 'default 'face-defface-spec)
3118 (and (not (custom-facep 'default))
3119 (not (get 'default 'force-face))))
3122 (mapatoms (lambda (symbol)
3123 (let ((value (get symbol 'saved-face)))
3124 (when (and (not (eq symbol 'default))
3125 ;; Don't print default face here.
3131 (if (or (get symbol 'face-defface-spec)
3132 (and (not (custom-facep symbol))
3133 (not (get symbol 'force-face))))
3137 (unless (looking-at "\n")
3141 (defun customize-save-customized ()
3142 "Save all user options which have been set in this session."
3144 (mapatoms (lambda (symbol)
3145 (let ((face (get symbol 'customized-face))
3146 (value (get symbol 'customized-value)))
3148 (put symbol 'saved-face face)
3149 (put symbol 'customized-face nil))
3151 (put symbol 'saved-value value)
3152 (put symbol 'customized-value nil)))))
3153 ;; We really should update all custom buffers here.
3157 (defun custom-save-all ()
3158 "Save all customizations in `custom-file'."
3159 (let ((inhibit-read-only t))
3160 (custom-save-variables)
3163 (let ((default-major-mode nil))
3164 (set-buffer (find-file-noselect (custom-file))))
3167 ;;; The Customize Menu.
3171 (defcustom custom-menu-nesting 2
3172 "Maximum nesting in custom menus."
3174 :group 'custom-menu)
3176 (defun custom-face-menu-create (widget symbol)
3177 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
3178 (vector (custom-unlispify-menu-entry symbol)
3179 `(customize-face ',symbol)
3182 (defun custom-variable-menu-create (widget symbol)
3183 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
3184 (let ((type (get symbol 'custom-type)))
3185 (unless (listp type)
3186 (setq type (list type)))
3187 (if (and type (widget-get type :custom-menu))
3188 (widget-apply type :custom-menu symbol)
3189 (vector (custom-unlispify-menu-entry symbol)
3190 `(customize-variable ',symbol)
3193 ;; Add checkboxes to boolean variable entries.
3194 (widget-put (get 'boolean 'widget-type)
3195 :custom-menu (lambda (widget symbol)
3196 (vector (custom-unlispify-menu-entry symbol)
3197 `(customize-variable ',symbol)
3199 ':selected symbol)))
3201 (if (string-match "XEmacs" emacs-version)
3202 ;; XEmacs can create menus dynamically.
3203 (defun custom-group-menu-create (widget symbol)
3204 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
3205 `( ,(custom-unlispify-menu-entry symbol t)
3206 :filter (lambda (&rest junk)
3207 (cdr (custom-menu-create ',symbol)))))
3209 (defun custom-group-menu-create (widget symbol)
3210 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
3211 ;; Limit the nesting.
3212 (let ((custom-menu-nesting (1- custom-menu-nesting)))
3213 (custom-menu-create symbol))))
3216 (defun custom-menu-create (symbol)
3217 "Create menu for customization group SYMBOL.
3218 The menu is in a format applicable to `easy-menu-define'."
3219 (let* ((item (vector (custom-unlispify-menu-entry symbol)
3220 `(customize-group ',symbol)
3222 (if (and (or (not (boundp 'custom-menu-nesting))
3223 (>= custom-menu-nesting 0))
3224 (< (length (get symbol 'custom-group)) widget-menu-max-size))
3225 (let ((custom-prefix-list (custom-prefix-add symbol
3226 custom-prefix-list))
3227 (members (custom-sort-items (get symbol 'custom-group)
3228 custom-menu-sort-alphabetically
3229 custom-menu-order-groups)))
3230 (custom-load-symbol symbol)
3231 `(,(custom-unlispify-menu-entry symbol t)
3234 ,@(mapcar (lambda (entry)
3235 (widget-apply (if (listp (nth 1 entry))
3237 (list (nth 1 entry)))
3238 :custom-menu (nth 0 entry)))
3243 (defun customize-menu-create (symbol &optional name)
3244 "Return a customize menu for customization group SYMBOL.
3245 If optional NAME is given, use that as the name of the menu.
3246 Otherwise the menu will be named `Customize'.
3247 The format is suitable for use with `easy-menu-define'."
3249 (setq name "Customize"))
3250 (if (string-match "XEmacs" emacs-version)
3251 ;; We can delay it under XEmacs.
3253 :filter (lambda (&rest junk)
3254 (cdr (custom-menu-create ',symbol))))
3255 ;; But we must create it now under Emacs.
3256 (cons name (cdr (custom-menu-create symbol)))))
3258 ;;; The Custom Mode.
3260 (defvar custom-mode-map nil
3261 "Keymap for `custom-mode'.")
3263 (unless custom-mode-map
3264 (setq custom-mode-map (make-sparse-keymap))
3265 (set-keymap-parent custom-mode-map widget-keymap)
3266 (suppress-keymap custom-mode-map)
3267 (define-key custom-mode-map " " 'scroll-up)
3268 (define-key custom-mode-map "\177" 'scroll-down)
3269 (define-key custom-mode-map "q" 'bury-buffer)
3270 (define-key custom-mode-map "u" 'Custom-goto-parent)
3271 (define-key custom-mode-map "n" 'widget-forward)
3272 (define-key custom-mode-map "p" 'widget-backward)
3273 (define-key custom-mode-map [mouse-1] 'Custom-move-and-invoke))
3275 (defun Custom-move-and-invoke (event)
3276 "Move to where you click, and if it is an active field, invoke it."
3278 (mouse-set-point event)
3279 (if (widget-event-point event)
3280 (let* ((pos (widget-event-point event))
3281 (button (get-char-property pos 'button)))
3283 (widget-button-click event)))))
3285 (easy-menu-define Custom-mode-menu
3287 "Menu used in customization buffers."
3289 ,(customize-menu-create 'customize)
3290 ["Set" Custom-set t]
3291 ["Save" Custom-save t]
3292 ["Reset to Current" Custom-reset-current t]
3293 ["Reset to Saved" Custom-reset-saved t]
3294 ["Reset to Standard Settings" Custom-reset-standard t]
3295 ["Info" (Info-goto-node "(custom)The Customization Buffer") t]))
3297 (defun Custom-goto-parent ()
3298 "Go to the parent group listed at the top of this buffer.
3299 If several parents are listed, go to the first of them."
3302 (goto-char (point-min))
3303 (if (search-forward "\nGo to parent group: " nil t)
3304 (let* ((button (get-char-property (point) 'button))
3305 (parent (downcase (widget-get button :tag))))
3306 (customize-group parent)))))
3308 (defcustom custom-mode-hook nil
3309 "Hook called when entering custom-mode."
3311 :group 'custom-buffer )
3313 (defun custom-state-buffer-message (widget)
3314 (if (eq (widget-get (widget-get widget :parent) :custom-state) 'modified)
3315 (message "To install your edits, invoke [State] and choose the Set operation")))
3317 (defun custom-mode ()
3318 "Major mode for editing customization buffers.
3320 The following commands are available:
3322 Move to next button or editable field. \\[widget-forward]
3323 Move to previous button or editable field. \\[widget-backward]
3324 \\<widget-field-keymap>\
3325 Complete content of editable text field. \\[widget-complete]
3326 \\<custom-mode-map>\
3327 Invoke button under the mouse pointer. \\[Custom-move-and-invoke]
3328 Invoke button under point. \\[widget-button-press]
3329 Set all modifications. \\[Custom-set]
3330 Make all modifications default. \\[Custom-save]
3331 Reset all modified options. \\[Custom-reset-current]
3332 Reset all modified or set options. \\[Custom-reset-saved]
3333 Reset all options. \\[Custom-reset-standard]
3335 Entry to this mode calls the value of `custom-mode-hook'
3336 if that value is non-nil."
3337 (kill-all-local-variables)
3338 (setq major-mode 'custom-mode
3340 (use-local-map custom-mode-map)
3341 (easy-menu-add Custom-mode-menu)
3342 (make-local-variable 'custom-options)
3343 (make-local-variable 'widget-documentation-face)
3344 (setq widget-documentation-face 'custom-documentation-face)
3345 (make-local-variable 'widget-button-face)
3346 (setq widget-button-face 'custom-button-face)
3347 (make-local-hook 'widget-edit-functions)
3348 (add-hook 'widget-edit-functions 'custom-state-buffer-message nil t)
3349 (run-hooks 'custom-mode-hook))
3355 ;; cus-edit.el ends here