1 ;;; cus-edit.el --- tools for customizing Emacs and Lisp packages
3 ;; Copyright (C) 1996, 1997, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
7 ;; Keywords: help, faces
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
28 ;; This file implements the code to create and edit customize buffers.
32 ;; No commands should have names starting with `custom-' because
33 ;; that interferes with completion. Use `customize-' for commands
34 ;; that the user will run with M-x, and `Custom-' for interactive commands.
41 (defvar custom-versions-load-alist)) ; from cus-load
51 (put 'custom-define-hook 'custom-type 'hook)
52 (put 'custom-define-hook 'standard-value '(nil))
53 (custom-add-to-group 'customize 'custom-define-hook 'custom-variable)
55 ;;; Customization Groups.
58 "Customization of the One True Editor."
59 :link '(custom-manual "(emacs)Top"))
61 ;; Most of these groups are stolen from `finder.el',
63 "Basic text editing facilities."
67 "Abbreviation handling, typing shortcuts, macros."
71 (defgroup matching nil
72 "Various sorts of searching and matching."
75 (defgroup emulations nil
76 "Emulations of other editors."
83 (defgroup outlines nil
84 "Support for hierarchical outlining."
87 (defgroup external nil
88 "Interfacing to external utilities."
92 "Code related to the `bib' bibliography processor."
96 (defgroup processes nil
97 "Process, subshell, compilation, and job control support."
101 (defgroup convenience nil
102 "Convenience features for faster editing."
105 (defgroup programming nil
106 "Support for programming in other languages."
109 (defgroup languages nil
110 "Specialized modes for editing programming languages."
114 "Lisp support, including Emacs Lisp."
119 "Support for the C language and related languages."
127 "Support for object-oriented programming."
130 (defgroup applications nil
131 "Applications written in Emacs."
134 (defgroup calendar nil
135 "Calendar and time management support."
136 :group 'applications)
139 "Modes for electronic-mail handling."
140 :group 'applications)
143 "Support for netnews reading and posting."
144 :group 'applications)
147 "Games, jokes and amusements."
148 :group 'applications)
150 (defgroup development nil
151 "Support for further development of Emacs."
155 "Support for Emacs documentation."
158 (defgroup extensions nil
159 "Emacs Lisp language extensions."
162 (defgroup internal nil
163 "Code for Emacs internals, build process, defaults."
167 "Maintenance aids for the Emacs development group."
171 (defgroup environment nil
172 "Fitting Emacs with its environment."
176 "Communications, networking, remote access to files."
180 (defgroup hardware nil
181 "Support for interfacing with exotic hardware."
184 (defgroup terminals nil
185 "Support for terminal types."
189 "Front-ends/assistants for, or emulators of, UNIX features."
193 "Support code for vms."
197 "Internationalization and alternate character-set support."
202 "The X Window system."
206 "Support for Emacs frames and window systems."
210 "Support editing files of data."
214 "Support editing files."
222 "Code related to the TeX formatter."
226 "Support for multiple fonts."
229 (defgroup hypermedia nil
230 "Support for links between text or other media types."
234 "Support for on-line help systems."
237 (defgroup multimedia nil
238 "Non-textual support, specifically images and sound."
242 "Code local to your site."
245 (defgroup customize '((widgets custom-group))
246 "Customization of the Customization support."
247 :link '(custom-manual "(elisp)Customization")
248 :link '(url-link :tag "(Old?) Development Page"
249 "http://www.dina.kvl.dk/~abraham/custom/")
253 (defgroup custom-faces nil
254 "Faces used by customize."
258 (defgroup custom-browse nil
259 "Control customize browser."
263 (defgroup custom-buffer nil
264 "Control customize buffers."
268 (defgroup custom-menu nil
269 "Control customize menus."
273 (defgroup abbrev-mode nil
274 "Word abbreviations mode."
278 "Storage allocation and gc for GNU Emacs Lisp interpreter."
279 :tag "Storage Allocation"
283 "Undoing changes in buffers."
286 (defgroup modeline nil
287 "Content of the modeline."
291 "Indenting and filling text."
294 (defgroup editing-basics nil
295 "Most basic editing facilities."
298 (defgroup display nil
299 "How characters are displayed in buffers."
302 (defgroup execute nil
303 "Executing external commands."
306 (defgroup installation nil
307 "The Emacs installation."
315 "Internal Emacs limits."
319 "Debugging Emacs itself."
322 (defgroup minibuffer nil
323 "Controling the behaviour of the minibuffer."
326 (defgroup keyboard nil
327 "Input from the keyboard."
331 "Input from the mouse."
335 "Input from the menus."
338 (defgroup auto-save nil
339 "Preventing accidential loss of data."
342 (defgroup processes-basics nil
343 "Basic stuff dealing with processes."
347 "MULE Emacs internationalization."
350 (defgroup windows nil
351 "Windows within a frame."
356 (defun custom-quote (sexp)
357 "Quote SEXP iff it is not self quoting."
358 (if (or (memq sexp '(t nil))
361 (memq (car sexp) '(lambda)))
365 ;;; (and (fboundp 'characterp)
366 ;;; (characterp sexp))
371 (defun custom-split-regexp-maybe (regexp)
372 "If REGEXP is a string, split it to a list at `\\|'.
373 You can get the original back with from the result with:
374 (mapconcat 'identity result \"\\|\")
376 IF REGEXP is not a string, return it unchanged."
380 (while (string-match "\\\\|" regexp start)
381 (setq all (cons (substring regexp start (match-beginning 0)) all)
382 start (match-end 0)))
383 (nreverse (cons (substring regexp start) all)))
386 (defun custom-variable-prompt ()
387 "Prompt for a custom variable, defaulting to the variable at point.
388 Return a list suitable for use in `interactive'."
389 (let ((v (variable-at-point))
390 (enable-recursive-minibuffers t)
392 (setq val (completing-read
393 (if (and (symbolp v) (custom-variable-p v))
394 (format "Customize option: (default %s) " v)
395 "Customize option: ")
396 obarray 'custom-variable-p t))
397 (list (if (equal val "")
398 (if (symbolp v) v nil)
401 (defun custom-menu-filter (menu widget)
402 "Convert MENU to the form used by `widget-choose'.
403 MENU should be in the same format as `custom-variable-menu'.
404 WIDGET is the widget to apply the filter entries of MENU on."
406 current name action filter)
408 (setq current (car menu)
410 action (nth 1 current)
411 filter (nth 2 current)
413 (if (or (null filter) (funcall filter widget))
414 (push (cons name action) result)
420 (defvar custom-prefix-list nil
421 "List of prefixes that should be ignored by `custom-unlispify'.")
423 (defcustom custom-unlispify-menu-entries t
424 "Display menu entries as words instead of symbols if non nil."
428 (defcustom custom-unlispify-remove-prefixes nil
429 "Non-nil means remove group prefixes from option names in buffer."
431 :group 'custom-buffer
434 (defun custom-unlispify-menu-entry (symbol &optional no-suffix)
435 "Convert SYMBOL into a menu entry."
436 (cond ((not custom-unlispify-menu-entries)
437 (symbol-name symbol))
438 ((get symbol 'custom-tag)
440 (get symbol 'custom-tag)
441 (concat (get symbol 'custom-tag) "...")))
444 (set-buffer (get-buffer-create " *Custom-Work*"))
446 (princ symbol (current-buffer))
447 (goto-char (point-min))
448 ;; FIXME: Boolean variables are not predicates, so they shouldn't
449 ;; end with `-p'. -stef
450 ;; (when (and (eq (get symbol 'custom-type) 'boolean)
451 ;; (re-search-forward "-p\\'" nil t))
452 ;; (replace-match "" t t)
453 ;; (goto-char (point-min)))
454 (if custom-unlispify-remove-prefixes
455 (let ((prefixes custom-prefix-list)
458 (setq prefix (car prefixes))
459 (if (search-forward prefix (+ (point) (length prefix)) t)
462 (delete-region (point-min) (point)))
463 (setq prefixes (cdr prefixes))))))
464 (subst-char-in-region (point-min) (point-max) ?- ?\ t)
465 (capitalize-region (point-min) (point-max))
467 (goto-char (point-max))
471 (defcustom custom-unlispify-tag-names t
472 "Display tag names as words instead of symbols if non nil."
473 :group 'custom-buffer
476 (defun custom-unlispify-tag-name (symbol)
477 "Convert SYMBOL into a menu entry."
478 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names))
479 (custom-unlispify-menu-entry symbol t)))
481 (defun custom-prefix-add (symbol prefixes)
482 "Add SYMBOL to list of ignored PREFIXES."
483 (cons (or (get symbol 'custom-prefix)
484 (concat (symbol-name symbol) "-"))
489 (defcustom custom-guess-name-alist
494 ("-function\\'" function)
495 ("-functions\\'" (repeat function))
496 ("-list\\'" (repeat sexp))
497 ("-alist\\'" (repeat (cons sexp sexp))))
498 "Alist of (MATCH TYPE).
500 MATCH should be a regexp matching the name of a symbol, and TYPE should
501 be a widget suitable for editing the value of that symbol. The TYPE
502 of the first entry where MATCH matches the name of the symbol will be
505 This is used for guessing the type of variables not declared with
507 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
510 (defcustom custom-guess-doc-alist
511 '(("\\`\\*?Non-nil " boolean))
512 "Alist of (MATCH TYPE).
514 MATCH should be a regexp matching a documentation string, and TYPE
515 should be a widget suitable for editing the value of a variable with
516 that documentation string. The TYPE of the first entry where MATCH
517 matches the name of the symbol will be used.
519 This is used for guessing the type of variables not declared with
521 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
524 (defun custom-guess-type (symbol)
525 "Guess a widget suitable for editing the value of SYMBOL.
526 This is done by matching SYMBOL with `custom-guess-name-alist' and
527 if that fails, the doc string with `custom-guess-doc-alist'."
528 (let ((name (symbol-name symbol))
529 (names custom-guess-name-alist)
532 (setq current (car names)
534 (when (string-match (nth 0 current) name)
535 (setq found (nth 1 current)
538 (let ((doc (documentation-property symbol 'variable-documentation))
539 (docs custom-guess-doc-alist))
542 (setq current (car docs)
544 (when (string-match (nth 0 current) doc)
545 (setq found (nth 1 current)
551 (defcustom custom-browse-sort-alphabetically nil
552 "If non-nil, sort members of each customization group alphabetically."
554 :group 'custom-browse)
556 (defcustom custom-browse-order-groups nil
557 "If non-nil, order group members within each customization group.
558 If `first', order groups before non-groups.
559 If `last', order groups after non-groups."
560 :type '(choice (const first)
562 (const :tag "none" nil))
563 :group 'custom-browse)
565 (defcustom custom-browse-only-groups nil
566 "If non-nil, show group members only within each customization group."
568 :group 'custom-browse)
570 (defcustom custom-buffer-sort-alphabetically nil
571 "If non-nil, sort members of each customization group alphabetically."
573 :group 'custom-buffer)
575 (defcustom custom-buffer-order-groups 'last
576 "If non-nil, order group members within each customization group.
577 If `first', order groups before non-groups.
578 If `last', order groups after non-groups."
579 :type '(choice (const first)
581 (const :tag "none" nil))
582 :group 'custom-buffer)
584 (defcustom custom-menu-sort-alphabetically nil
585 "If non-nil, sort members of each customization group alphabetically."
589 (defcustom custom-menu-order-groups 'first
590 "If non-nil, order group members within each customization group.
591 If `first', order groups before non-groups.
592 If `last', order groups after non-groups."
593 :type '(choice (const first)
595 (const :tag "none" nil))
598 ;;;###autoload (add-hook 'same-window-regexps "\\`\\*Customiz.*\\*\\'")
600 (defun custom-sort-items (items sort-alphabetically order-groups)
601 "Return a sorted copy of ITEMS.
602 ITEMS should be a `custom-group' property.
603 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
604 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
605 groups after non-groups, if nil do not order groups at all."
606 (sort (copy-sequence items)
608 (let ((typea (nth 1 a)) (typeb (nth 1 b))
609 (namea (nth 0 a)) (nameb (nth 0 b)))
610 (cond ((not order-groups)
611 ;; Since we don't care about A and B order, maybe sort.
612 (when sort-alphabetically
613 (string-lessp namea nameb)))
614 ((eq typea 'custom-group)
615 ;; If B is also a group, maybe sort. Otherwise, order A and B.
616 (if (eq typeb 'custom-group)
617 (when sort-alphabetically
618 (string-lessp namea nameb))
619 (eq order-groups 'first)))
620 ((eq typeb 'custom-group)
621 ;; Since A cannot be a group, order A and B.
622 (eq order-groups 'last))
624 ;; Since A and B cannot be groups, sort.
625 (string-lessp namea nameb)))))))
627 ;;; Custom Mode Commands.
629 (defvar custom-options nil
630 "Customization widgets in the current buffer.")
633 "Set changes in all modified options."
635 (let ((children custom-options))
636 (mapc (lambda (child)
637 (when (eq (widget-get child :custom-state) 'modified)
638 (widget-apply child :custom-set)))
641 (defun Custom-save ()
642 "Set all modified group members and save them."
644 (let ((children custom-options))
645 (mapc (lambda (child)
646 (when (memq (widget-get child :custom-state)
647 '(modified set changed rogue))
648 (widget-apply child :custom-save)))
652 (defvar custom-reset-menu
653 '(("Current" . Custom-reset-current)
654 ("Saved" . Custom-reset-saved)
655 ("Erase Customization (use standard settings)" . Custom-reset-standard))
656 "Alist of actions for the `Reset' button.
657 The key is a string containing the name of the action, the value is a
658 Lisp function taking the widget as an element which will be called
659 when the action is chosen.")
661 (defun custom-reset (event)
662 "Select item from reset menu."
663 (let* ((completion-ignore-case t)
664 (answer (widget-choose "Reset to"
670 (defun Custom-reset-current (&rest ignore)
671 "Reset all modified group members to their current value."
673 (let ((children custom-options))
674 (mapc (lambda (widget)
675 (if (memq (widget-get widget :custom-state)
677 (widget-apply widget :custom-reset-current)))
680 (defun Custom-reset-saved (&rest ignore)
681 "Reset all modified or set group members to their saved value."
683 (let ((children custom-options))
684 (mapc (lambda (widget)
685 (if (memq (widget-get widget :custom-state)
686 '(modified set changed rogue))
687 (widget-apply widget :custom-reset-saved)))
690 (defun Custom-reset-standard (&rest ignore)
691 "Erase all customization (either current or saved) for the group members.
692 The immediate result is to restore them to their standard settings.
693 This operation eliminates any saved settings for the group members,
694 making them as if they had never been customized at all."
696 (let ((children custom-options))
697 (mapc (lambda (widget)
698 (and (widget-apply widget :custom-standard-value)
699 (if (memq (widget-get widget :custom-state)
700 '(modified set changed saved rogue))
701 (widget-apply widget :custom-reset-standard))))
704 ;;; The Customize Commands
706 (defun custom-prompt-variable (prompt-var prompt-val &optional comment)
707 "Prompt for a variable and a value and return them as a list.
708 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
709 prompt for the value. The %s escape in PROMPT-VAL is replaced with
710 the name of the variable.
712 If the variable has a `variable-interactive' property, that is used as if
713 it were the arg to `interactive' (which see) to interactively read the value.
715 If the variable has a `custom-type' property, it must be a widget and the
716 `:prompt-value' property of that widget will be used for reading the value.
718 If optional COMMENT argument is non nil, also prompt for a comment and return
719 it as the third element in the list."
720 (let* ((var (read-variable prompt-var))
721 (minibuffer-help-form '(describe-variable var))
723 (let ((prop (get var 'variable-interactive))
724 (type (get var 'custom-type))
725 (prompt (format prompt-val var)))
727 (setq type (list type)))
729 ;; Use VAR's `variable-interactive' property
730 ;; as an interactive spec for prompting.
731 (call-interactively (list 'lambda '(arg)
732 (list 'interactive prop)
735 (widget-prompt-value type
741 (eval-minibuffer prompt))))))
744 (read-string "Comment: " (get var 'variable-comment)))
748 (defun customize-set-value (variable value &optional comment)
749 "Set VARIABLE to VALUE, and return VALUE. VALUE is a Lisp object.
751 If VARIABLE has a `variable-interactive' property, that is used as if
752 it were the arg to `interactive' (which see) to interactively read the value.
754 If VARIABLE has a `custom-type' property, it must be a widget and the
755 `:prompt-value' property of that widget will be used for reading the value.
757 If given a prefix (or a COMMENT argument), also prompt for a comment."
758 (interactive (custom-prompt-variable "Set variable: "
762 (cond ((string= comment "")
763 (put variable 'variable-comment nil))
765 (put variable 'variable-comment comment)))
766 (set variable value))
769 (defun customize-set-variable (variable value &optional comment)
770 "Set the default for VARIABLE to VALUE, and return VALUE.
771 VALUE is a Lisp object.
773 If VARIABLE has a `custom-set' property, that is used for setting
774 VARIABLE, otherwise `set-default' is used.
776 The `customized-value' property of the VARIABLE will be set to a list
777 with a quoted VALUE as its sole list member.
779 If VARIABLE has a `variable-interactive' property, that is used as if
780 it were the arg to `interactive' (which see) to interactively read the value.
782 If VARIABLE has a `custom-type' property, it must be a widget and the
783 `:prompt-value' property of that widget will be used for reading the value.
785 If given a prefix (or a COMMENT argument), also prompt for a comment."
786 (interactive (custom-prompt-variable "Set variable: "
787 "Set customized value for %s to: "
789 (custom-load-symbol variable)
790 (funcall (or (get variable 'custom-set) 'set-default) variable value)
791 (put variable 'customized-value (list (custom-quote value)))
792 (cond ((string= comment "")
793 (put variable 'variable-comment nil)
794 (put variable 'customized-variable-comment nil))
796 (put variable 'variable-comment comment)
797 (put variable 'customized-variable-comment comment)))
801 (defun customize-save-variable (variable value &optional comment)
802 "Set the default for VARIABLE to VALUE, and save it for future sessions.
805 If VARIABLE has a `custom-set' property, that is used for setting
806 VARIABLE, otherwise `set-default' is used.
808 The `customized-value' property of the VARIABLE will be set to a list
809 with a quoted VALUE as its sole list member.
811 If VARIABLE has a `variable-interactive' property, that is used as if
812 it were the arg to `interactive' (which see) to interactively read the value.
814 If VARIABLE has a `custom-type' property, it must be a widget and the
815 `:prompt-value' property of that widget will be used for reading the value.
817 If given a prefix (or a COMMENT argument), also prompt for a comment."
818 (interactive (custom-prompt-variable "Set and save variable: "
819 "Set and save value for %s as: "
821 (funcall (or (get variable 'custom-set) 'set-default) variable value)
822 (put variable 'saved-value (list (custom-quote value)))
823 (custom-push-theme 'theme-value variable 'user 'set (list (custom-quote value)))
824 (cond ((string= comment "")
825 (put variable 'variable-comment nil)
826 (put variable 'saved-variable-comment nil))
828 (put variable 'variable-comment comment)
829 (put variable 'saved-variable-comment comment)))
835 "Select a customization buffer which you can use to set user options.
836 User options are structured into \"groups\".
837 Initially the top-level group `Emacs' and its immediate subgroups
838 are shown; the contents of those subgroups are initially hidden."
840 (customize-group 'emacs))
843 (defun customize-mode (mode)
844 "Customize options related to the current major mode.
845 If a prefix \\[universal-argument] was given (or if the current major mode has no known group),
846 then prompt for the MODE to customize."
849 (let ((completion-regexp-list '("-mode\\'"))
850 (group (custom-group-of-mode major-mode)))
851 (if (and group (not current-prefix-arg))
854 (completing-read (if group
855 (format "Major mode (default %s): " major-mode)
858 'custom-group-of-mode
859 t nil nil (if group (symbol-name major-mode))))))))
860 (customize-group (custom-group-of-mode mode)))
864 (defun customize-group (group)
865 "Customize GROUP, which must be a customization group."
866 (interactive (list (let ((completion-ignore-case t))
867 (completing-read "Customize group: (default emacs) "
870 (or (get symbol 'custom-loads)
871 (get symbol 'custom-group)))
873 (when (stringp group)
874 (if (string-equal "" group)
876 (setq group (intern group))))
877 (custom-load-symbol group)
878 (let ((name (format "*Customize Group: %s*"
879 (custom-unlispify-tag-name group))))
880 (if (get-buffer name)
882 (custom-buffer-create (list (list group 'custom-group))
884 (concat " for group "
885 (custom-unlispify-tag-name group))))))
888 (defun customize-group-other-window (group)
889 "Customize GROUP, which must be a customization group."
890 (interactive (list (let ((completion-ignore-case t))
891 (completing-read "Customize group: (default emacs) "
894 (or (get symbol 'custom-loads)
895 (get symbol 'custom-group)))
897 (when (stringp group)
898 (if (string-equal "" group)
900 (setq group (intern group))))
901 (custom-load-symbol group)
902 (let ((name (format "*Customize Group: %s*"
903 (custom-unlispify-tag-name group))))
904 (if (get-buffer name)
905 (let ((window (selected-window))
906 ;; Copied from `custom-buffer-create-other-window'.
908 (special-display-buffer-names nil)
909 (special-display-regexps nil)
910 (same-window-buffer-names nil)
911 (same-window-regexps nil))
913 (select-window window))
914 (custom-buffer-create-other-window
915 (list (list group 'custom-group))
917 (concat " for group "
918 (custom-unlispify-tag-name group))))))
921 (defalias 'customize-variable 'customize-option)
924 (defun customize-option (symbol)
925 "Customize SYMBOL, which must be a user option variable."
926 (interactive (custom-variable-prompt))
927 (custom-buffer-create (list (list symbol 'custom-variable))
928 (format "*Customize Option: %s*"
929 (custom-unlispify-tag-name symbol))))
932 (defalias 'customize-variable-other-window 'customize-option-other-window)
935 (defun customize-option-other-window (symbol)
936 "Customize SYMBOL, which must be a user option variable.
937 Show the buffer in another window, but don't select it."
938 (interactive (custom-variable-prompt))
939 (custom-buffer-create-other-window
940 (list (list symbol 'custom-variable))
941 (format "*Customize Option: %s*" (custom-unlispify-tag-name symbol))))
943 (defvar customize-changed-options-previous-release "20.2"
944 "Version for `customize-changed-options' to refer back to by default.")
947 (defun customize-changed-options (since-version)
948 "Customize all user option variables changed in Emacs itself.
949 This includes new user option variables and faces, and new
950 customization groups, as well as older options and faces whose default
951 values have changed since the previous major Emacs release.
953 With argument SINCE-VERSION (a string), customize all user option
954 variables that were added (or their meanings were changed) since that
957 (interactive "sCustomize options changed, since version (default all versions): ")
958 (if (equal since-version "")
959 (setq since-version nil)
960 (unless (condition-case nil
961 (numberp (read since-version))
963 (signal 'wrong-type-argument (list 'numberp since-version))))
964 (unless since-version
965 (setq since-version customize-changed-options-previous-release))
968 (mapatoms (lambda (symbol)
969 (and (or (boundp symbol)
970 ;; For variables not yet loaded.
971 (get symbol 'standard-value)
972 ;; For groups the previous test fails, this one
973 ;; could be used to determine if symbol is a
974 ;; group. Is there a better way for this?
975 (get symbol 'group-documentation))
976 (let ((version (get symbol 'custom-version)))
978 (or (null since-version)
979 (customize-version-lessp since-version version))
980 (if (member version versions)
982 ;;; Collect all versions that we use.
983 (push version versions))))
985 ;; We have to set the right thing here,
986 ;; depending if we have a group or a
988 (if (get symbol 'group-documentation)
989 (cons (list symbol 'custom-group) found)
990 (cons (list symbol 'custom-variable) found))))))
992 (error "No user option defaults have been changed since Emacs %s"
997 (cdr (assoc (car versions) custom-versions-load-alist)))
999 (setq versions (cdr versions)))
1000 (put 'custom-versions-load-alist 'custom-loads
1001 ;; Get all the files that correspond to element from the
1002 ;; VERSIONS list. This could use some simplification.
1003 (apply 'nconc flist)))
1004 ;; Because we set all the files needed to be loaded as a
1005 ;; `custom-loads' property to `custom-versions-load-alist' this
1006 ;; call will actually load them.
1007 (custom-load-symbol 'custom-versions-load-alist)
1009 (put 'custom-versions-load-alist 'custom-loads nil)
1010 (custom-buffer-create (custom-sort-items found t 'first)
1011 "*Customize Changed Options*"))))
1013 (defun customize-version-lessp (version1 version2)
1014 ;; Why are the versions strings, and given that they are, why aren't
1015 ;; they converted to numbers and compared as such here? -- fx
1017 ;; In case someone made a mistake and left out the quotes
1018 ;; in the :version value.
1019 (if (numberp version2)
1020 (setq version2 (prin1-to-string version2)))
1021 (let (major1 major2 minor1 minor2)
1022 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version1)
1023 (setq major1 (read (or (match-string 1 version1)
1025 (setq minor1 (read (or (match-string 3 version1)
1027 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version2)
1028 (setq major2 (read (or (match-string 1 version2)
1030 (setq minor2 (read (or (match-string 3 version2)
1032 (or (< major1 major2)
1033 (and (= major1 major2)
1034 (< minor1 minor2)))))
1037 (defun customize-face (&optional face)
1038 "Customize SYMBOL, which should be a face name or nil.
1039 If SYMBOL is nil, customize all faces.
1041 Interactively, when point is on text which has a face specified,
1042 suggest to customized that face, if it's customizable."
1044 (list (read-face-name "Customize face" "all faces" t)))
1045 (if (member face '(nil ""))
1046 (setq face (face-list)))
1047 (if (and (listp face) (null (cdr face)))
1048 (setq face (car face)))
1050 (custom-buffer-create (custom-sort-items
1052 (list s 'custom-face))
1055 "*Customize Faces*")
1056 (unless (facep face)
1057 (error "Invalid face %S" face))
1058 (custom-buffer-create (list (list face 'custom-face))
1059 (format "*Customize Face: %s*"
1060 (custom-unlispify-tag-name face)))))
1063 (defun customize-face-other-window (&optional face)
1064 "Show customization buffer for face SYMBOL in other window.
1066 Interactively, when point is on text which has a face specified,
1067 suggest to customized that face, if it's customizable."
1069 (list (read-face-name "Customize face" "all faces" t)))
1070 (if (member face '(nil ""))
1071 (setq face (face-list)))
1072 (if (and (listp face) (null (cdr face)))
1073 (setq face (car face)))
1075 (custom-buffer-create-other-window
1078 (list s 'custom-face))
1081 "*Customize Faces*")
1082 (unless (facep face)
1083 (error "Invalid face %S" face))
1084 (custom-buffer-create-other-window
1085 (list (list face 'custom-face))
1086 (format "*Customize Face: %s*"
1087 (custom-unlispify-tag-name face)))))
1090 (defun customize-customized ()
1091 "Customize all user options set since the last save in this session."
1094 (mapatoms (lambda (symbol)
1095 (and (or (get symbol 'customized-face)
1096 (get symbol 'customized-face-comment))
1097 (custom-facep symbol)
1098 (push (list symbol 'custom-face) found))
1099 (and (or (get symbol 'customized-value)
1100 (get symbol 'customized-variable-comment))
1102 (push (list symbol 'custom-variable) found))))
1104 (error "No customized user options")
1105 (custom-buffer-create (custom-sort-items found t nil)
1106 "*Customize Customized*"))))
1109 (defun customize-saved ()
1110 "Customize all already saved user options."
1113 (mapatoms (lambda (symbol)
1114 (and (or (get symbol 'saved-face)
1115 (get symbol 'saved-face-comment))
1116 (custom-facep symbol)
1117 (push (list symbol 'custom-face) found))
1118 (and (or (get symbol 'saved-value)
1119 (get symbol 'saved-variable-comment))
1121 (push (list symbol 'custom-variable) found))))
1123 (error "No saved user options")
1124 (custom-buffer-create (custom-sort-items found t nil)
1125 "*Customize Saved*"))))
1128 (defun customize-apropos (regexp &optional all)
1129 "Customize all user options matching REGEXP.
1130 If ALL is `options', include only options.
1131 If ALL is `faces', include only faces.
1132 If ALL is `groups', include only groups.
1133 If ALL is t (interactively, with prefix arg), include options which are not
1134 user-settable, as well as faces and groups."
1135 (interactive "sCustomize regexp: \nP")
1137 (mapatoms (lambda (symbol)
1138 (when (string-match regexp (symbol-name symbol))
1139 (when (and (not (memq all '(faces options)))
1140 (get symbol 'custom-group))
1141 (push (list symbol 'custom-group) found))
1142 (when (and (not (memq all '(options groups)))
1143 (custom-facep symbol))
1144 (push (list symbol 'custom-face) found))
1145 (when (and (not (memq all '(groups faces)))
1147 (or (get symbol 'saved-value)
1148 (custom-variable-p symbol)
1149 (if (memq all '(nil options))
1150 (user-variable-p symbol)
1151 (get symbol 'variable-documentation))))
1152 (push (list symbol 'custom-variable) found)))))
1154 (error "No matches")
1155 (custom-buffer-create (custom-sort-items found t
1156 custom-buffer-order-groups)
1157 "*Customize Apropos*"))))
1160 (defun customize-apropos-options (regexp &optional arg)
1161 "Customize all user options matching REGEXP.
1162 With prefix arg, include options which are not user-settable."
1163 (interactive "sCustomize regexp: \nP")
1164 (customize-apropos regexp (or arg 'options)))
1167 (defun customize-apropos-faces (regexp)
1168 "Customize all user faces matching REGEXP."
1169 (interactive "sCustomize regexp: \n")
1170 (customize-apropos regexp 'faces))
1173 (defun customize-apropos-groups (regexp)
1174 "Customize all user groups matching REGEXP."
1175 (interactive "sCustomize regexp: \n")
1176 (customize-apropos regexp 'groups))
1180 (defcustom custom-buffer-style 'links
1181 "Control the presentation style for customization buffers.
1182 The value should be a symbol, one of:
1184 brackets: groups nest within each other with big horizontal brackets.
1185 links: groups have links to subgroups."
1186 :type '(radio (const brackets)
1188 :group 'custom-buffer)
1190 ;; If we pass BUFFER to `bury-buffer', the buffer isn't removed from
1192 (defun custom-bury-buffer (buffer)
1195 (defcustom custom-buffer-done-function 'custom-bury-buffer
1196 "*Function called to remove a Custom buffer when the user is done with it.
1197 Called with one argument, the buffer to remove."
1198 :type '(choice (function-item :tag "Bury buffer" custom-bury-buffer)
1199 (function-item :tag "Kill buffer" kill-buffer)
1200 (function :tag "Other"))
1202 :group 'custom-buffer)
1204 (defcustom custom-buffer-indent 3
1205 "Number of spaces to indent nested groups."
1207 :group 'custom-buffer)
1210 (defun custom-buffer-create (options &optional name description)
1211 "Create a buffer containing OPTIONS.
1212 Optional NAME is the name of the buffer.
1213 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1214 SYMBOL is a customization option, and WIDGET is a widget for editing
1216 (unless name (setq name "*Customization*"))
1217 (kill-buffer (get-buffer-create name))
1218 (pop-to-buffer (get-buffer-create name))
1219 (custom-buffer-create-internal options description))
1222 (defun custom-buffer-create-other-window (options &optional name description)
1223 "Create a buffer containing OPTIONS.
1224 Optional NAME is the name of the buffer.
1225 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1226 SYMBOL is a customization option, and WIDGET is a widget for editing
1228 (unless name (setq name "*Customization*"))
1229 (kill-buffer (get-buffer-create name))
1230 (let ((window (selected-window))
1232 (special-display-buffer-names nil)
1233 (special-display-regexps nil)
1234 (same-window-buffer-names nil)
1235 (same-window-regexps nil))
1236 (pop-to-buffer (get-buffer-create name))
1237 (custom-buffer-create-internal options description)
1238 (select-window window)))
1240 (defcustom custom-reset-button-menu nil
1241 "If non-nil, only show a single reset button in customize buffers.
1242 This button will have a menu with all three reset operations."
1244 :group 'custom-buffer)
1246 (defcustom custom-buffer-verbose-help t
1247 "If non-nil, include explanatory text in the customization buffer."
1249 :group 'custom-buffer)
1251 (defun Custom-buffer-done (&rest ignore)
1252 "Remove current buffer by calling `custom-buffer-done-function'."
1254 (funcall custom-buffer-done-function (current-buffer)))
1256 (defcustom custom-raised-buttons (not (equal (face-valid-attribute-values :box)
1257 '(("unspecified" . unspecified))))
1258 "If non-nil, indicate active buttons in a `raised-button' style.
1259 Otherwise use brackets."
1262 :group 'custom-buffer)
1264 (defun custom-buffer-create-internal (options &optional description)
1265 (message "Creating customization buffer...")
1267 (if custom-buffer-verbose-help
1269 (widget-insert "This is a customization buffer")
1271 (widget-insert description))
1272 (widget-insert (format ".
1273 %s show active fields; type RET or click mouse-1
1274 on an active field to invoke its action. Editing an option value
1275 changes the text in the buffer; invoke the State button and
1276 choose the Set operation to set the option value.
1277 Invoke " (if custom-raised-buttons
1279 "Square brackets")))
1280 (widget-create 'info-link
1282 :help-echo "Read the online help."
1283 "(emacs)Easy Customization")
1284 (widget-insert " for more information.\n\n")
1285 (message "Creating customization buttons...")
1286 (widget-insert "Operate on everything in this buffer:\n "))
1287 (widget-insert " "))
1288 (widget-create 'push-button
1289 :tag "Set for Current Session"
1291 Make your editing in this buffer take effect for this session."
1292 :action (lambda (widget &optional event)
1295 (widget-create 'push-button
1296 :tag "Save for Future Sessions"
1298 Make your editing in this buffer take effect for future Emacs sessions."
1299 :action (lambda (widget &optional event)
1301 (if custom-reset-button-menu
1304 (widget-create 'push-button
1306 :help-echo "Show a menu with reset operations."
1307 :mouse-down-action (lambda (&rest junk) t)
1308 :action (lambda (widget &optional event)
1309 (custom-reset event))))
1310 (widget-insert "\n ")
1311 (widget-create 'push-button
1314 Reset all edited text in this buffer to reflect current values."
1315 :action 'Custom-reset-current)
1317 (widget-create 'push-button
1318 :tag "Reset to Saved"
1320 Reset all values in this buffer to their saved settings."
1321 :action 'Custom-reset-saved)
1323 (widget-create 'push-button
1324 :tag "Erase Customization"
1326 Un-customize all values in this buffer. They get their standard settings."
1327 :action 'Custom-reset-standard))
1328 (if (not custom-buffer-verbose-help)
1331 (widget-create 'info-link
1333 :help-echo "Read the online help."
1334 "(emacs)Easy Customization")))
1336 (widget-create 'push-button
1339 (lambda (&rest ignore)
1341 ((eq custom-buffer-done-function
1342 'custom-bury-buffer)
1344 ((eq custom-buffer-done-function 'kill-buffer)
1346 (t "Finish with this buffer")))
1347 :action #'Custom-buffer-done)
1348 (widget-insert "\n\n")
1349 (message "Creating customization items...")
1350 (buffer-disable-undo)
1351 (setq custom-options
1352 (if (= (length options) 1)
1353 (mapcar (lambda (entry)
1354 (widget-create (nth 1 entry)
1355 :documentation-shown t
1356 :custom-state 'unknown
1357 :tag (custom-unlispify-tag-name
1359 :value (nth 0 entry)))
1362 (length (length options)))
1363 (mapcar (lambda (entry)
1365 (message "Creating customization items ...%2d%%"
1366 (/ (* 100.0 count) length))
1367 (widget-create (nth 1 entry)
1368 :tag (custom-unlispify-tag-name
1370 :value (nth 0 entry))
1371 (setq count (1+ count))
1372 (unless (eq (preceding-char) ?\n)
1373 (widget-insert "\n"))
1374 (widget-insert "\n")))
1376 (unless (eq (preceding-char) ?\n)
1377 (widget-insert "\n"))
1378 (message "Creating customization items ...done")
1379 (unless (eq custom-buffer-style 'tree)
1380 (mapc 'custom-magic-reset custom-options))
1381 (message "Creating customization setup...")
1383 (buffer-enable-undo)
1384 (goto-char (point-min))
1385 (message "Creating customization buffer...done"))
1387 ;;; The Tree Browser.
1390 (defun customize-browse (&optional group)
1391 "Create a tree browser for the customize hierarchy."
1394 (setq group 'emacs))
1395 (let ((name "*Customize Browser*"))
1396 (kill-buffer (get-buffer-create name))
1397 (pop-to-buffer (get-buffer-create name)))
1400 Square brackets show active fields; type RET or click mouse-1
1401 on an active field to invoke its action.
1402 Invoke [+] below to expand a group, and [-] to collapse an expanded group.\n")
1403 (if custom-browse-only-groups
1405 Invoke the [Group] button below to edit that item in another window.\n\n")
1406 (widget-insert "Invoke the ")
1407 (widget-create 'item
1410 :tag-glyph "folder")
1411 (widget-insert ", ")
1412 (widget-create 'item
1416 (widget-insert ", and ")
1417 (widget-create 'item
1420 :tag-glyph "option")
1421 (widget-insert " buttons below to edit that
1422 item in another window.\n\n"))
1423 (let ((custom-buffer-style 'tree))
1424 (widget-create 'custom-group
1426 :custom-state 'unknown
1427 :tag (custom-unlispify-tag-name group)
1430 (goto-char (point-min)))
1432 (define-widget 'custom-browse-visibility 'item
1433 "Control visibility of items in the customize tree browser."
1435 :action 'custom-browse-visibility-action)
1437 (defun custom-browse-visibility-action (widget &rest ignore)
1438 (let ((custom-buffer-style 'tree))
1439 (custom-toggle-parent widget)))
1441 (define-widget 'custom-browse-group-tag 'push-button
1442 "Show parent in other window when activated."
1445 :action 'custom-browse-group-tag-action)
1447 (defun custom-browse-group-tag-action (widget &rest ignore)
1448 (let ((parent (widget-get widget :parent)))
1449 (customize-group-other-window (widget-value parent))))
1451 (define-widget 'custom-browse-variable-tag 'push-button
1452 "Show parent in other window when activated."
1455 :action 'custom-browse-variable-tag-action)
1457 (defun custom-browse-variable-tag-action (widget &rest ignore)
1458 (let ((parent (widget-get widget :parent)))
1459 (customize-variable-other-window (widget-value parent))))
1461 (define-widget 'custom-browse-face-tag 'push-button
1462 "Show parent in other window when activated."
1465 :action 'custom-browse-face-tag-action)
1467 (defun custom-browse-face-tag-action (widget &rest ignore)
1468 (let ((parent (widget-get widget :parent)))
1469 (customize-face-other-window (widget-value parent))))
1471 (defconst custom-browse-alist '((" " "space")
1477 (defun custom-browse-insert-prefix (prefix)
1478 "Insert PREFIX. On XEmacs convert it to line graphics."
1479 ;; Fixme: do graphics.
1480 (if nil ; (string-match "XEmacs" emacs-version)
1483 (while (not (string-equal prefix ""))
1484 (let ((entry (substring prefix 0 3)))
1485 (setq prefix (substring prefix 3))
1486 (let ((overlay (make-overlay (1- (point)) (point) nil t nil))
1487 (name (nth 1 (assoc entry custom-browse-alist))))
1488 (overlay-put overlay 'end-glyph (widget-glyph-find name entry))
1489 (overlay-put overlay 'start-open t)
1490 (overlay-put overlay 'end-open t)))))
1493 ;;; Modification of Basic Widgets.
1495 ;; We add extra properties to the basic widgets needed here. This is
1496 ;; fine, as long as we are careful to stay within out own namespace.
1498 ;; We want simple widgets to be displayed by default, but complex
1499 ;; widgets to be hidden.
1501 (widget-put (get 'item 'widget-type) :custom-show t)
1502 (widget-put (get 'editable-field 'widget-type)
1503 :custom-show (lambda (widget value)
1504 (let ((pp (pp-to-string value)))
1505 (cond ((string-match "\n" pp)
1510 (widget-put (get 'menu-choice 'widget-type) :custom-show t)
1512 ;;; The `custom-manual' Widget.
1514 (define-widget 'custom-manual 'info-link
1515 "Link to the manual entry for this customization option."
1516 :help-echo "Read the manual entry for this option."
1519 ;;; The `custom-magic' Widget.
1521 (defgroup custom-magic-faces nil
1522 "Faces used by the magic button."
1523 :group 'custom-faces
1524 :group 'custom-buffer)
1526 (defface custom-invalid-face '((((class color))
1527 (:foreground "yellow" :background "red"))
1529 (:weight bold :slant italic :underline t)))
1530 "Face used when the customize item is invalid."
1531 :group 'custom-magic-faces)
1533 (defface custom-rogue-face '((((class color))
1534 (:foreground "pink" :background "black"))
1537 "Face used when the customize item is not defined for customization."
1538 :group 'custom-magic-faces)
1540 (defface custom-modified-face '((((class color))
1541 (:foreground "white" :background "blue"))
1543 (:slant italic :bold)))
1544 "Face used when the customize item has been modified."
1545 :group 'custom-magic-faces)
1547 (defface custom-set-face '((((class color))
1548 (:foreground "blue" :background "white"))
1551 "Face used when the customize item has been set."
1552 :group 'custom-magic-faces)
1554 (defface custom-changed-face '((((class color))
1555 (:foreground "white" :background "blue"))
1558 "Face used when the customize item has been changed."
1559 :group 'custom-magic-faces)
1561 (defface custom-saved-face '((t (:underline t)))
1562 "Face used when the customize item has been saved."
1563 :group 'custom-magic-faces)
1565 (defconst custom-magic-alist '((nil "#" underline "\
1566 uninitialized, you should not see this.")
1567 (unknown "?" italic "\
1568 unknown, you should not see this.")
1569 (hidden "-" default "\
1570 hidden, invoke \"Show\" in the previous line to show." "\
1571 group now hidden, invoke \"Show\", above, to show contents.")
1572 (invalid "x" custom-invalid-face "\
1573 the value displayed for this %c is invalid and cannot be set.")
1574 (modified "*" custom-modified-face "\
1575 you have edited the value as text, but you have not set the %c." "\
1576 you have edited something in this group, but not set it.")
1577 (set "+" custom-set-face "\
1578 you have set this %c, but not saved it for future sessions." "\
1579 something in this group has been set, but not saved.")
1580 (changed ":" custom-changed-face "\
1581 this %c has been changed outside the customize buffer." "\
1582 something in this group has been changed outside customize.")
1583 (saved "!" custom-saved-face "\
1584 this %c has been set and saved." "\
1585 something in this group has been set and saved.")
1586 (rogue "@" custom-rogue-face "\
1587 this %c has not been changed with customize." "\
1588 something in this group is not prepared for customization.")
1589 (standard " " nil "\
1590 this %c is unchanged from its standard setting." "\
1591 visible group members are all at standard settings."))
1592 "Alist of customize option states.
1593 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1595 STATE is one of the following symbols:
1598 For internal use, should never occur.
1600 For internal use, should never occur.
1602 This item is not being displayed.
1604 This item is modified, but has an invalid form.
1606 This item is modified, and has a valid form.
1608 This item has been set but not saved.
1610 The current value of this item has been changed temporarily.
1612 This item is marked for saving.
1614 This item has no customization information.
1616 This item is unchanged from the standard setting.
1618 MAGIC is a string used to present that state.
1620 FACE is a face used to present the state.
1622 ITEM-DESC is a string describing the state for options.
1624 GROUP-DESC is a string describing the state for groups. If this is
1625 left out, ITEM-DESC will be used.
1627 The string %c in either description will be replaced with the
1628 category of the item. These are `group'. `option', and `face'.
1630 The list should be sorted most significant first.")
1632 (defcustom custom-magic-show 'long
1633 "If non-nil, show textual description of the state.
1634 If `long', show a full-line description, not just one word."
1635 :type '(choice (const :tag "no" nil)
1637 (other :tag "short" short))
1638 :group 'custom-buffer)
1640 (defcustom custom-magic-show-hidden '(option face)
1641 "Control whether the State button is shown for hidden items.
1642 The value should be a list with the custom categories where the State
1643 button should be visible. Possible categories are `group', `option',
1645 :type '(set (const group) (const option) (const face))
1646 :group 'custom-buffer)
1648 (defcustom custom-magic-show-button nil
1649 "Show a \"magic\" button indicating the state of each customization option."
1651 :group 'custom-buffer)
1653 (define-widget 'custom-magic 'default
1654 "Show and manipulate state for a customization option."
1656 :action 'widget-parent-action
1659 :value-create 'custom-magic-value-create
1660 :value-delete 'widget-children-value-delete)
1662 (defun widget-magic-mouse-down-action (widget &optional event)
1663 ;; Non-nil unless hidden.
1664 (not (eq (widget-get (widget-get (widget-get widget :parent) :parent)
1668 (defun custom-magic-value-create (widget)
1669 "Create compact status report for WIDGET."
1670 (let* ((parent (widget-get widget :parent))
1671 (state (widget-get parent :custom-state))
1672 (hidden (eq state 'hidden))
1673 (entry (assq state custom-magic-alist))
1674 (magic (nth 1 entry))
1675 (face (nth 2 entry))
1676 (category (widget-get parent :custom-category))
1677 (text (or (and (eq category 'group)
1680 (form (widget-get parent :custom-form))
1682 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text)
1683 (setq text (concat (match-string 1 text)
1684 (symbol-name category)
1685 (match-string 2 text))))
1686 (when (and custom-magic-show
1688 (memq category custom-magic-show-hidden)))
1690 (when (and (eq category 'group)
1691 (not (and (eq custom-buffer-style 'links)
1692 (> (widget-get parent :custom-level) 1))))
1693 (insert-char ?\ (* custom-buffer-indent
1694 (widget-get parent :custom-level))))
1695 (push (widget-create-child-and-convert
1697 :help-echo "Change the state of this item."
1698 :format (if hidden "%t" "%[%t%]")
1699 :button-prefix 'widget-push-button-prefix
1700 :button-suffix 'widget-push-button-suffix
1701 :mouse-down-action 'widget-magic-mouse-down-action
1705 (let ((start (point)))
1706 (if (eq custom-magic-show 'long)
1708 (insert (symbol-name state)))
1709 (cond ((eq form 'lisp)
1711 ((eq form 'mismatch)
1712 (insert " (mismatch)")))
1713 (put-text-property start (point) 'face 'custom-state-face))
1715 (when (and (eq category 'group)
1716 (not (and (eq custom-buffer-style 'links)
1717 (> (widget-get parent :custom-level) 1))))
1718 (insert-char ?\ (* custom-buffer-indent
1719 (widget-get parent :custom-level))))
1720 (when custom-magic-show-button
1721 (when custom-magic-show
1722 (let ((indent (widget-get parent :indent)))
1724 (insert-char ? indent))))
1725 (push (widget-create-child-and-convert
1727 :mouse-down-action 'widget-magic-mouse-down-action
1731 :help-echo "Change the state."
1732 :format (if hidden "%t" "%[%t%]")
1733 :tag (if (memq form '(lisp mismatch))
1734 (concat "(" magic ")")
1735 (concat "[" magic "]")))
1738 (widget-put widget :children children)))
1740 (defun custom-magic-reset (widget)
1741 "Redraw the :custom-magic property of WIDGET."
1742 (let ((magic (widget-get widget :custom-magic)))
1743 (widget-value-set magic (widget-value magic))))
1745 ;;; The `custom' Widget.
1747 (defface custom-button-face
1748 '((((type x w32 mac) (class color)) ; Like default modeline
1749 (:box (:line-width 2 :style released-button)
1750 :background "lightgrey" :foreground "black"))
1753 "Face used for buttons in customization buffers."
1755 :group 'custom-faces)
1757 (defface custom-button-pressed-face
1758 '((((type x w32 mac) (class color))
1759 (:box (:line-width 2 :style pressed-button)
1760 :background "lightgrey" :foreground "black"))
1762 (:inverse-video t)))
1763 "Face used for buttons in customization buffers."
1765 :group 'custom-faces)
1767 (defface custom-documentation-face nil
1768 "Face used for documentation strings in customization buffers."
1769 :group 'custom-faces)
1771 (defface custom-state-face '((((class color)
1773 (:foreground "lime green"))
1776 (:foreground "dark green"))
1778 "Face used for State descriptions in the customize buffer."
1779 :group 'custom-faces)
1781 (define-widget 'custom 'default
1782 "Customize a user option."
1784 :convert-widget 'custom-convert-widget
1785 :notify 'custom-notify
1788 :custom-state 'hidden
1789 :documentation-property 'widget-subclass-responsibility
1790 :value-create 'widget-subclass-responsibility
1791 :value-delete 'widget-children-value-delete
1792 :value-get 'widget-value-value-get
1793 :validate 'widget-children-validate
1794 :match (lambda (widget value) (symbolp value)))
1796 (defun custom-convert-widget (widget)
1797 "Initialize :value and :tag from :args in WIDGET."
1798 (let ((args (widget-get widget :args)))
1800 (widget-put widget :value (widget-apply widget
1801 :value-to-internal (car args)))
1802 (widget-put widget :tag (custom-unlispify-tag-name (car args)))
1803 (widget-put widget :args nil)))
1806 (defun custom-notify (widget &rest args)
1807 "Keep track of changes."
1808 (let ((state (widget-get widget :custom-state)))
1809 (unless (eq state 'modified)
1810 (unless (memq state '(nil unknown hidden))
1811 (widget-put widget :custom-state 'modified))
1812 (custom-magic-reset widget)
1813 (apply 'widget-default-notify widget args))))
1815 (defun custom-redraw (widget)
1816 "Redraw WIDGET with current settings."
1817 (let ((line (count-lines (point-min) (point)))
1818 (column (current-column))
1820 (from (marker-position (widget-get widget :from)))
1821 (to (marker-position (widget-get widget :to))))
1823 (widget-value-set widget (widget-value widget))
1824 (custom-redraw-magic widget))
1825 (when (and (>= pos from) (<= pos to))
1830 (goto-line (1+ line)))
1831 (move-to-column column))
1834 (defun custom-redraw-magic (widget)
1835 "Redraw WIDGET state with current settings."
1837 (let ((magic (widget-get widget :custom-magic)))
1839 (widget-value-set magic (widget-value magic))
1840 (when (setq widget (widget-get widget :group))
1841 (custom-group-state-update widget)))
1843 (setq widget nil)))))
1846 (defun custom-show (widget value)
1847 "Non-nil if WIDGET should be shown with VALUE by default."
1848 (let ((show (widget-get widget :custom-show)))
1854 (funcall show widget value)))))
1856 (defun custom-load-widget (widget)
1857 "Load all dependencies for WIDGET."
1858 (custom-load-symbol (widget-value widget)))
1860 (defun custom-unloaded-symbol-p (symbol)
1861 "Return non-nil if the dependencies of SYMBOL has not yet been loaded."
1863 (loads (get symbol 'custom-loads))
1866 (setq load (car loads)
1868 (cond ((symbolp load)
1869 (unless (featurep load)
1871 ((assoc load load-history))
1872 ((assoc (locate-library load) load-history)
1878 (defun custom-unloaded-widget-p (widget)
1879 "Return non-nil if the dependencies of WIDGET has not yet been loaded."
1880 (custom-unloaded-symbol-p (widget-value widget)))
1882 (defun custom-toggle-hide (widget)
1883 "Toggle visibility of WIDGET."
1884 (custom-load-widget widget)
1885 (let ((state (widget-get widget :custom-state)))
1886 (cond ((memq state '(invalid modified))
1887 (error "There are unset changes"))
1889 (widget-put widget :custom-state 'unknown))
1891 (widget-put widget :documentation-shown nil)
1892 (widget-put widget :custom-state 'hidden)))
1893 (custom-redraw widget)
1896 (defun custom-toggle-parent (widget &rest ignore)
1897 "Toggle visibility of parent of WIDGET."
1898 (custom-toggle-hide (widget-get widget :parent)))
1900 (defun custom-add-see-also (widget &optional prefix)
1901 "Add `See also ...' to WIDGET if there are any links.
1902 Insert PREFIX first if non-nil."
1903 (let* ((symbol (widget-get widget :value))
1904 (links (get symbol 'custom-links))
1905 (many (> (length links) 2))
1906 (buttons (widget-get widget :buttons))
1907 (indent (widget-get widget :indent)))
1910 (insert-char ?\ indent))
1913 (insert "See also ")
1915 (push (widget-create-child-and-convert widget (car links))
1917 (setq links (cdr links))
1926 (widget-put widget :buttons buttons))))
1928 (defun custom-add-parent-links (widget &optional initial-string)
1929 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
1930 The value if non-nil if any parents were found.
1931 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
1932 (let ((name (widget-value widget))
1933 (type (widget-type widget))
1934 (buttons (widget-get widget :buttons))
1937 (insert (or initial-string "Parent groups:"))
1938 (mapatoms (lambda (symbol)
1939 (let ((entry (assq name (get symbol 'custom-group))))
1940 (when (eq (nth 1 entry) type)
1942 (push (widget-create-child-and-convert
1943 widget 'custom-group-link
1944 :tag (custom-unlispify-tag-name symbol)
1948 (widget-put widget :buttons buttons)
1951 (delete-region start (point)))
1954 ;;; The `custom-comment' Widget.
1956 ;; like the editable field
1957 (defface custom-comment-face '((((class grayscale color)
1959 (:background "gray85"))
1960 (((class grayscale color)
1962 (:background "dim gray"))
1965 "Face used for comments on variables or faces"
1967 :group 'custom-faces)
1969 ;; like font-lock-comment-face
1970 (defface custom-comment-tag-face
1971 '((((class color) (background dark)) (:foreground "gray80"))
1972 (((class color) (background light)) (:foreground "blue4"))
1973 (((class grayscale) (background light))
1974 (:foreground "DimGray" :weight bold :slant italic))
1975 (((class grayscale) (background dark))
1976 (:foreground "LightGray" :weight bold :slant italic))
1978 "Face used for variables or faces comment tags"
1979 :group 'custom-faces)
1981 (define-widget 'custom-comment 'string
1984 :help-echo "Edit a comment here."
1985 :sample-face 'custom-comment-tag-face
1986 :value-face 'custom-comment-face
1988 :create 'custom-comment-create)
1990 (defun custom-comment-create (widget)
1991 (let* ((null-comment (equal "" (widget-value widget))))
1992 (if (or (widget-get (widget-get widget :parent) :comment-shown)
1994 (widget-default-create widget)
1995 ;; `widget-default-delete' expects markers in these slots --
1996 ;; maybe it shouldn't.
1997 (widget-put widget :from (point-marker))
1998 (widget-put widget :to (point-marker)))))
2000 (defun custom-comment-hide (widget)
2001 (widget-put (widget-get widget :parent) :comment-shown nil))
2003 ;; Those functions are for the menu. WIDGET is NOT the comment widget. It's
2004 ;; the global custom one
2005 (defun custom-comment-show (widget)
2006 (widget-put widget :comment-shown t)
2007 (custom-redraw widget)
2010 (defun custom-comment-invisible-p (widget)
2011 (let ((val (widget-value (widget-get widget :comment-widget))))
2013 (not (widget-get widget :comment-shown)))))
2015 ;;; The `custom-variable' Widget.
2017 ;; When this was underlined blue, users confused it with a
2018 ;; Mosaic-style hyperlink...
2019 (defface custom-variable-tag-face
2022 (:foreground "light blue" :weight bold :height 1.2 :inherit variable-pitch))
2025 (:foreground "blue" :weight bold :height 1.2 :inherit variable-pitch))
2027 "Face used for unpushable variable tags."
2028 :group 'custom-faces)
2030 (defface custom-variable-button-face '((t (:underline t :weight bold)))
2031 "Face used for pushable variable tags."
2032 :group 'custom-faces)
2034 (defcustom custom-variable-default-form 'edit
2035 "Default form of displaying variable values."
2036 :type '(choice (const edit)
2038 :group 'custom-buffer
2041 (define-widget 'custom-variable 'custom
2042 "Customize variable."
2044 :help-echo "Set or reset this variable."
2045 :documentation-property 'variable-documentation
2046 :custom-category 'option
2048 :custom-menu 'custom-variable-menu-create
2049 :custom-form nil ; defaults to value of `custom-variable-default-form'
2050 :value-create 'custom-variable-value-create
2051 :action 'custom-variable-action
2052 :custom-set 'custom-variable-set
2053 :custom-save 'custom-variable-save
2054 :custom-reset-current 'custom-redraw
2055 :custom-reset-saved 'custom-variable-reset-saved
2056 :custom-reset-standard 'custom-variable-reset-standard
2057 :custom-standard-value 'custom-variable-standard-value)
2059 (defun custom-variable-type (symbol)
2060 "Return a widget suitable for editing the value of SYMBOL.
2061 If SYMBOL has a `custom-type' property, use that.
2062 Otherwise, look up symbol in `custom-guess-type-alist'."
2063 (let* ((type (or (get symbol 'custom-type)
2064 (and (not (get symbol 'standard-value))
2065 (custom-guess-type symbol))
2067 (options (get symbol 'custom-options))
2068 (tmp (if (listp type)
2069 (copy-sequence type)
2072 (widget-put tmp :options options))
2075 (defun custom-variable-value-create (widget)
2076 "Here is where you edit the variable's value."
2077 (custom-load-widget widget)
2078 (unless (widget-get widget :custom-form)
2079 (widget-put widget :custom-form custom-variable-default-form))
2080 (let* ((buttons (widget-get widget :buttons))
2081 (children (widget-get widget :children))
2082 (form (widget-get widget :custom-form))
2083 (state (widget-get widget :custom-state))
2084 (symbol (widget-get widget :value))
2085 (tag (widget-get widget :tag))
2086 (type (custom-variable-type symbol))
2087 (conv (widget-convert type))
2088 (get (or (get symbol 'custom-get) 'default-value))
2089 (prefix (widget-get widget :custom-prefix))
2090 (last (widget-get widget :custom-last))
2091 (value (if (default-boundp symbol)
2092 (funcall get symbol)
2093 (widget-get conv :value))))
2094 ;; If the widget is new, the child determines whether it is hidden.
2096 ((custom-show type value)
2097 (setq state 'unknown))
2099 (setq state 'hidden)))
2100 ;; If we don't know the state, see if we need to edit it in lisp form.
2101 (when (eq state 'unknown)
2102 (unless (widget-apply conv :match value)
2103 ;; (widget-apply (widget-convert type) :match value)
2104 (setq form 'mismatch)))
2105 ;; Now we can create the child widget.
2106 (cond ((eq custom-buffer-style 'tree)
2107 (insert prefix (if last " `--- " " |--- "))
2108 (push (widget-create-child-and-convert
2109 widget 'custom-browse-variable-tag)
2111 (insert " " tag "\n")
2112 (widget-put widget :buttons buttons))
2114 ;; Indicate hidden value.
2115 (push (widget-create-child-and-convert
2118 :sample-face 'custom-variable-tag-face
2122 (push (widget-create-child-and-convert
2124 :help-echo "Show the value of this option."
2126 :action 'custom-toggle-parent
2129 ((memq form '(lisp mismatch))
2130 ;; In lisp mode edit the saved value when possible.
2131 (let* ((value (cond ((get symbol 'saved-value)
2132 (car (get symbol 'saved-value)))
2133 ((get symbol 'standard-value)
2134 (car (get symbol 'standard-value)))
2135 ((default-boundp symbol)
2136 (custom-quote (funcall get symbol)))
2138 (custom-quote (widget-get conv :value))))))
2139 (insert (symbol-name symbol) ": ")
2140 (push (widget-create-child-and-convert
2142 :help-echo "Hide the value of this option."
2145 :action 'custom-toggle-parent
2149 (push (widget-create-child-and-convert
2151 :button-face 'custom-variable-button-face
2153 :tag (symbol-name symbol)
2159 (let* ((format (widget-get type :format))
2160 tag-format value-format)
2161 (unless (string-match ":" format)
2162 (error "Bad format"))
2163 (setq tag-format (substring format 0 (match-end 0)))
2164 (setq value-format (substring format (match-end 0)))
2165 (push (widget-create-child-and-convert
2168 :action 'custom-tag-action
2169 :help-echo "Change value of this option."
2170 :mouse-down-action 'custom-tag-mouse-down-action
2171 :button-face 'custom-variable-button-face
2172 :sample-face 'custom-variable-tag-face
2176 (push (widget-create-child-and-convert
2178 :help-echo "Hide the value of this option."
2181 :action 'custom-toggle-parent
2184 (push (widget-create-child-and-convert
2186 :format value-format
2189 (unless (eq custom-buffer-style 'tree)
2190 (unless (eq (preceding-char) ?\n)
2191 (widget-insert "\n"))
2192 ;; Create the magic button.
2193 (let ((magic (widget-create-child-and-convert
2194 widget 'custom-magic nil)))
2195 (widget-put widget :custom-magic magic)
2196 (push magic buttons))
2197 ;; ### NOTE: this is ugly!!!! I need to update the :buttons property
2198 ;; before the call to `widget-default-format-handler'. Otherwise, I
2199 ;; loose my current `buttons'. This function shouldn't be called like
2200 ;; this anyway. The doc string widget should be added like the others.
2202 (widget-put widget :buttons buttons)
2204 ;; Insert documentation.
2205 (widget-default-format-handler widget ?h)
2207 ;; The comment field
2208 (unless (eq state 'hidden)
2209 (let* ((comment (get symbol 'variable-comment))
2211 (widget-create-child-and-convert
2212 widget 'custom-comment
2214 :value (or comment ""))))
2215 (widget-put widget :comment-widget comment-widget)
2216 ;; Don't push it !!! Custom assumes that the first child is the
2218 (setq children (append children (list comment-widget)))))
2219 ;; Update the rest of the properties properties.
2220 (widget-put widget :custom-form form)
2221 (widget-put widget :children children)
2222 ;; Now update the state.
2223 (if (eq state 'hidden)
2224 (widget-put widget :custom-state state)
2225 (custom-variable-state-set widget))
2227 (unless (eq state 'hidden)
2228 (when (eq (widget-get widget :custom-level) 1)
2229 (custom-add-parent-links widget))
2230 (custom-add-see-also widget)))))
2232 (defun custom-tag-action (widget &rest args)
2233 "Pass :action to first child of WIDGET's parent."
2234 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
2237 (defun custom-tag-mouse-down-action (widget &rest args)
2238 "Pass :mouse-down-action to first child of WIDGET's parent."
2239 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
2240 :mouse-down-action args))
2242 (defun custom-variable-state-set (widget)
2243 "Set the state of WIDGET."
2244 (let* ((symbol (widget-value widget))
2245 (get (or (get symbol 'custom-get) 'default-value))
2246 (value (if (default-boundp symbol)
2247 (funcall get symbol)
2248 (widget-get widget :value)))
2249 (comment (get symbol 'variable-comment))
2252 (state (cond ((progn (setq tmp (get symbol 'customized-value))
2254 (get symbol 'customized-variable-comment))
2256 (if (condition-case nil
2257 (and (equal value (eval (car tmp)))
2258 (equal comment temp))
2262 ((progn (setq tmp (get symbol 'saved-value))
2263 (setq temp (get symbol 'saved-variable-comment))
2265 (if (condition-case nil
2266 (and (equal value (eval (car tmp)))
2267 (equal comment temp))
2271 ((setq tmp (get symbol 'standard-value))
2272 (if (condition-case nil
2273 (and (equal value (eval (car tmp)))
2274 (equal comment nil))
2279 (widget-put widget :custom-state state)))
2281 (defun custom-variable-standard-value (widget)
2282 (get (widget-value widget) 'standard-value))
2284 (defvar custom-variable-menu
2285 '(("Set for Current Session" custom-variable-set
2287 (eq (widget-get widget :custom-state) 'modified)))
2288 ("Save for Future Sessions" custom-variable-save
2290 (memq (widget-get widget :custom-state) '(modified set changed rogue))))
2291 ("Reset to Current" custom-redraw
2293 (and (default-boundp (widget-value widget))
2294 (memq (widget-get widget :custom-state) '(modified changed)))))
2295 ("Reset to Saved" custom-variable-reset-saved
2297 (and (or (get (widget-value widget) 'saved-value)
2298 (get (widget-value widget) 'saved-variable-comment))
2299 (memq (widget-get widget :custom-state)
2300 '(modified set changed rogue)))))
2301 ("Erase Customization" custom-variable-reset-standard
2303 (and (get (widget-value widget) 'standard-value)
2304 (memq (widget-get widget :custom-state)
2305 '(modified set changed saved rogue)))))
2306 ("Use Backup Value" custom-variable-reset-backup
2308 (get (widget-value widget) 'backup-value)))
2309 ("---" ignore ignore)
2310 ("Add Comment" custom-comment-show custom-comment-invisible-p)
2311 ("---" ignore ignore)
2312 ("Don't show as Lisp expression" custom-variable-edit
2314 (eq (widget-get widget :custom-form) 'lisp)))
2315 ("Show initial Lisp expression" custom-variable-edit-lisp
2317 (eq (widget-get widget :custom-form) 'edit))))
2318 "Alist of actions for the `custom-variable' widget.
2319 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2320 the menu entry, ACTION is the function to call on the widget when the
2321 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2322 widget as an argument, and returns non-nil if ACTION is valid on that
2323 widget. If FILTER is nil, ACTION is always valid.")
2325 (defun custom-variable-action (widget &optional event)
2326 "Show the menu for `custom-variable' WIDGET.
2327 Optional EVENT is the location for the menu."
2328 (if (eq (widget-get widget :custom-state) 'hidden)
2329 (custom-toggle-hide widget)
2330 (unless (eq (widget-get widget :custom-state) 'modified)
2331 (custom-variable-state-set widget))
2332 (custom-redraw-magic widget)
2333 (let* ((completion-ignore-case t)
2334 (answer (widget-choose (concat "Operation on "
2335 (custom-unlispify-tag-name
2336 (widget-get widget :value)))
2337 (custom-menu-filter custom-variable-menu
2341 (funcall answer widget)))))
2343 (defun custom-variable-edit (widget)
2344 "Edit value of WIDGET."
2345 (widget-put widget :custom-state 'unknown)
2346 (widget-put widget :custom-form 'edit)
2347 (custom-redraw widget))
2349 (defun custom-variable-edit-lisp (widget)
2350 "Edit the Lisp representation of the value of WIDGET."
2351 (widget-put widget :custom-state 'unknown)
2352 (widget-put widget :custom-form 'lisp)
2353 (custom-redraw widget))
2355 (defun custom-variable-set (widget)
2356 "Set the current value for the variable being edited by WIDGET."
2357 (let* ((form (widget-get widget :custom-form))
2358 (state (widget-get widget :custom-state))
2359 (child (car (widget-get widget :children)))
2360 (symbol (widget-value widget))
2361 (set (or (get symbol 'custom-set) 'set-default))
2362 (comment-widget (widget-get widget :comment-widget))
2363 (comment (widget-value comment-widget))
2365 (cond ((eq state 'hidden)
2366 (error "Cannot set hidden variable"))
2367 ((setq val (widget-apply child :validate))
2368 (goto-char (widget-get val :from))
2369 (error "%s" (widget-get val :error)))
2370 ((memq form '(lisp mismatch))
2371 (when (equal comment "")
2373 ;; Make the comment invisible by hand if it's empty
2374 (custom-comment-hide comment-widget))
2375 (custom-variable-backup-value widget)
2376 (funcall set symbol (eval (setq val (widget-value child))))
2377 (put symbol 'customized-value (list val))
2378 (put symbol 'variable-comment comment)
2379 (put symbol 'customized-variable-comment comment))
2381 (when (equal comment "")
2383 ;; Make the comment invisible by hand if it's empty
2384 (custom-comment-hide comment-widget))
2385 (custom-variable-backup-value widget)
2386 (funcall set symbol (setq val (widget-value child)))
2387 (put symbol 'customized-value (list (custom-quote val)))
2388 (put symbol 'variable-comment comment)
2389 (put symbol 'customized-variable-comment comment)))
2390 (custom-variable-state-set widget)
2391 (custom-redraw-magic widget)))
2393 (defun custom-variable-save (widget)
2394 "Set and save the value for the variable being edited by WIDGET."
2395 (let* ((form (widget-get widget :custom-form))
2396 (state (widget-get widget :custom-state))
2397 (child (car (widget-get widget :children)))
2398 (symbol (widget-value widget))
2399 (set (or (get symbol 'custom-set) 'set-default))
2400 (comment-widget (widget-get widget :comment-widget))
2401 (comment (widget-value comment-widget))
2403 (cond ((eq state 'hidden)
2404 (error "Cannot set hidden variable"))
2405 ((setq val (widget-apply child :validate))
2406 (goto-char (widget-get val :from))
2407 (error "Saving %s: %s" symbol (widget-get val :error)))
2408 ((memq form '(lisp mismatch))
2409 (when (equal comment "")
2411 ;; Make the comment invisible by hand if it's empty
2412 (custom-comment-hide comment-widget))
2413 (put symbol 'saved-value (list (widget-value child)))
2414 (custom-push-theme 'theme-value symbol 'user
2415 'set (list (widget-value child)))
2416 (funcall set symbol (eval (widget-value child)))
2417 (put symbol 'variable-comment comment)
2418 (put symbol 'saved-variable-comment comment))
2420 (when (equal comment "")
2422 ;; Make the comment invisible by hand if it's empty
2423 (custom-comment-hide comment-widget))
2424 (put symbol 'saved-value
2425 (list (custom-quote (widget-value child))))
2426 (custom-push-theme 'theme-value symbol 'user
2427 'set (list (custom-quote (widget-value
2429 (funcall set symbol (widget-value child))
2430 (put symbol 'variable-comment comment)
2431 (put symbol 'saved-variable-comment comment)))
2432 (put symbol 'customized-value nil)
2433 (put symbol 'customized-variable-comment nil)
2435 (custom-variable-state-set widget)
2436 (custom-redraw-magic widget)))
2438 (defun custom-variable-reset-saved (widget)
2439 "Restore the saved value for the variable being edited by WIDGET.
2440 The value that was current before this operation
2441 becomes the backup value, so you can get it again."
2442 (let* ((symbol (widget-value widget))
2443 (set (or (get symbol 'custom-set) 'set-default))
2444 (comment-widget (widget-get widget :comment-widget))
2445 (value (get symbol 'saved-value))
2446 (comment (get symbol 'saved-variable-comment)))
2447 (cond ((or value comment)
2448 (put symbol 'variable-comment comment)
2449 (custom-variable-backup-value widget)
2451 (funcall set symbol (eval (car value)))
2454 (error "No saved value for %s" symbol)))
2455 (put symbol 'customized-value nil)
2456 (put symbol 'customized-variable-comment nil)
2457 (widget-put widget :custom-state 'unknown)
2458 ;; This call will possibly make the comment invisible
2459 (custom-redraw widget)))
2461 (defun custom-variable-reset-standard (widget)
2462 "Restore the standard setting for the variable being edited by WIDGET.
2463 This operation eliminates any saved setting for the variable,
2464 restoring it to the state of a variable that has never been customized.
2465 The value that was current before this operation
2466 becomes the backup value, so you can get it again."
2467 (let* ((symbol (widget-value widget))
2468 (set (or (get symbol 'custom-set) 'set-default))
2469 (comment-widget (widget-get widget :comment-widget)))
2470 (if (get symbol 'standard-value)
2472 (custom-variable-backup-value widget)
2473 (funcall set symbol (eval (car (get symbol 'standard-value)))))
2474 (error "No standard setting known for %S" symbol))
2475 (put symbol 'variable-comment nil)
2476 (put symbol 'customized-value nil)
2477 (put symbol 'customized-variable-comment nil)
2478 (when (or (get symbol 'saved-value) (get symbol 'saved-variable-comment))
2479 (put symbol 'saved-value nil)
2480 (custom-push-theme 'theme-value symbol 'user 'reset 'standard)
2481 ;; As a special optimizations we do not (explictly)
2482 ;; save resets to standard when no theme set the value.
2483 (if (null (cdr (get symbol 'theme-value)))
2484 (put symbol 'theme-value nil))
2485 (put symbol 'saved-variable-comment nil)
2487 (widget-put widget :custom-state 'unknown)
2488 ;; This call will possibly make the comment invisible
2489 (custom-redraw widget)))
2491 (defun custom-variable-backup-value (widget)
2492 "Back up the current value for WIDGET's variable.
2493 The backup value is kept in the car of the `backup-value' property."
2494 (let* ((symbol (widget-value widget))
2495 (get (or (get symbol 'custom-get) 'default-value))
2496 (type (custom-variable-type symbol))
2497 (conv (widget-convert type))
2498 (value (if (default-boundp symbol)
2499 (funcall get symbol)
2500 (widget-get conv :value))))
2501 (put symbol 'backup-value (list value))))
2503 (defun custom-variable-reset-backup (widget)
2504 "Restore the backup value for the variable being edited by WIDGET.
2505 The value that was current before this operation
2506 becomes the backup value, so you can use this operation repeatedly
2507 to switch between two values."
2508 (let* ((symbol (widget-value widget))
2509 (set (or (get symbol 'custom-set) 'set-default))
2510 (value (get symbol 'backup-value))
2511 (comment-widget (widget-get widget :comment-widget))
2512 (comment (widget-value comment-widget)))
2515 (custom-variable-backup-value widget)
2517 (funcall set symbol (car value))
2519 (error "No backup value for %s" symbol))
2520 (put symbol 'customized-value (list (car value)))
2521 (put symbol 'variable-comment comment)
2522 (put symbol 'customized-variable-comment comment)
2523 (custom-variable-state-set widget)
2524 ;; This call will possibly make the comment invisible
2525 (custom-redraw widget)))
2527 ;;; The `custom-face-edit' Widget.
2529 (define-widget 'custom-face-edit 'checklist
2530 "Edit face attributes."
2534 :button-args '(:help-echo "Control whether this attribute has any effect.")
2535 :value-to-internal 'custom-face-edit-fix-value
2536 :match (lambda (widget value)
2537 (widget-checklist-match widget
2538 (custom-face-edit-fix-value widget value)))
2539 :convert-widget 'custom-face-edit-convert-widget
2540 :args (mapcar (lambda (att)
2543 :sibling-args (widget-get (nth 1 att) :sibling-args)
2544 (list 'const :format "" :value (nth 0 att))
2546 custom-face-attributes))
2548 (defun custom-face-edit-fix-value (widget value)
2549 "Ignoring WIDGET, convert :bold and :italic in VALUE to new form.
2550 Also change :reverse-video to :inverse-video."
2554 (let ((key (car value))
2555 (val (car (cdr value))))
2556 (cond ((eq key :italic)
2557 (push :slant result)
2558 (push (if val 'italic 'normal) result))
2560 (push :weight result)
2561 (push (if val 'bold 'normal) result))
2562 ((eq key :reverse-video)
2563 (push :inverse-video result)
2567 (push val result))))
2568 (setq value (cdr (cdr value))))
2569 (setq result (nreverse result))
2573 (defun custom-face-edit-convert-widget (widget)
2574 "Convert :args as widget types in WIDGET."
2577 :args (mapcar (lambda (arg)
2579 :deactivate 'custom-face-edit-deactivate
2580 :activate 'custom-face-edit-activate
2581 :delete 'custom-face-edit-delete))
2582 (widget-get widget :args)))
2585 (defun custom-face-edit-deactivate (widget)
2586 "Make face widget WIDGET inactive for user modifications."
2587 (unless (widget-get widget :inactive)
2588 (let ((tag (custom-face-edit-attribute-tag widget))
2589 (from (copy-marker (widget-get widget :from)))
2590 (to (widget-get widget :to))
2591 (value (widget-value widget))
2592 (inhibit-read-only t)
2593 (inhibit-modification-hooks t))
2596 (widget-default-delete widget)
2597 (insert tag ": *\n")
2598 (widget-put widget :inactive
2599 (cons value (cons from (- (point) from))))))))
2601 (defun custom-face-edit-activate (widget)
2602 "Make face widget WIDGET inactive for user modifications."
2603 (let ((inactive (widget-get widget :inactive))
2604 (inhibit-read-only t)
2605 (inhibit-modification-hooks t))
2606 (when (consp inactive)
2608 (goto-char (car (cdr inactive)))
2609 (delete-region (point) (+ (point) (cdr (cdr inactive))))
2610 (widget-put widget :inactive nil)
2611 (widget-apply widget :create)
2612 (widget-value-set widget (car inactive))
2615 (defun custom-face-edit-delete (widget)
2616 "Remove widget from the buffer."
2617 (let ((inactive (widget-get widget :inactive))
2618 (inhibit-read-only t)
2619 (inhibit-modification-hooks t))
2621 ;; Widget is alive, we don't have to do anything special
2622 (widget-default-delete widget)
2623 ;; WIDGET is already deleted because we did so to inactivate it;
2624 ;; now just get rid of the label we put in its place.
2625 (delete-region (car (cdr inactive))
2626 (+ (car (cdr inactive)) (cdr (cdr inactive))))
2627 (widget-put widget :inactive nil))))
2630 (defun custom-face-edit-attribute-tag (widget)
2631 "Returns the first :tag property in WIDGET or one of its children."
2632 (let ((tag (widget-get widget :tag)))
2633 (or (and (not (equal tag "")) tag)
2634 (let ((children (widget-get widget :children)))
2635 (while (and (null tag) children)
2636 (setq tag (custom-face-edit-attribute-tag (pop children))))
2639 ;;; The `custom-display' Widget.
2641 (define-widget 'custom-display 'menu-choice
2642 "Select a display type."
2645 :help-echo "Specify frames where the face attributes should be used."
2646 :args '((const :tag "all" t)
2650 :args ((group :sibling-args (:help-echo "\
2651 Only match the specified window systems.")
2652 (const :format "Type: "
2654 (checklist :inline t
2657 :sibling-args (:help-echo "\
2658 The X11 Window System.")
2660 (const :format "PM "
2661 :sibling-args (:help-echo "\
2662 OS/2 Presentation Manager.")
2664 (const :format "W32 "
2665 :sibling-args (:help-echo "\
2668 (const :format "MAC "
2669 :sibling-args (:help-echo "\
2672 (const :format "DOS "
2673 :sibling-args (:help-echo "\
2676 (const :format "TTY%n"
2677 :sibling-args (:help-echo "\
2678 Plain text terminals.")
2680 (group :sibling-args (:help-echo "\
2681 Only match the frames with the specified color support.")
2682 (const :format "Class: "
2684 (checklist :inline t
2686 (const :format "Color "
2687 :sibling-args (:help-echo "\
2688 Match color frames.")
2690 (const :format "Grayscale "
2691 :sibling-args (:help-echo "\
2692 Match grayscale frames.")
2694 (const :format "Monochrome%n"
2695 :sibling-args (:help-echo "\
2696 Match frames with no color support.")
2698 (group :sibling-args (:help-echo "\
2699 Only match frames with the specified intensity.")
2701 Background brightness: "
2703 (checklist :inline t
2705 (const :format "Light "
2706 :sibling-args (:help-echo "\
2707 Match frames with light backgrounds.")
2709 (const :format "Dark\n"
2710 :sibling-args (:help-echo "\
2711 Match frames with dark backgrounds.")
2713 (group :sibling-args (:help-echo "\
2714 Only match frames that support the specified face attributes.")
2715 (const :format "Supports attributes:" supports)
2716 (custom-face-edit :inline t :format "%n%v"))))))
2718 ;;; The `custom-face' Widget.
2720 (defface custom-face-tag-face
2721 `((t (:weight bold :height 1.2 :inherit variable-pitch)))
2722 "Face used for face tags."
2723 :group 'custom-faces)
2725 (defcustom custom-face-default-form 'selected
2726 "Default form of displaying face definition."
2727 :type '(choice (const all)
2730 :group 'custom-buffer
2733 (define-widget 'custom-face 'custom
2735 :sample-face 'custom-face-tag-face
2736 :help-echo "Set or reset this face."
2737 :documentation-property #'face-doc-string
2738 :value-create 'custom-face-value-create
2739 :action 'custom-face-action
2740 :custom-category 'face
2741 :custom-form nil ; defaults to value of `custom-face-default-form'
2742 :custom-set 'custom-face-set
2743 :custom-save 'custom-face-save
2744 :custom-reset-current 'custom-redraw
2745 :custom-reset-saved 'custom-face-reset-saved
2746 :custom-reset-standard 'custom-face-reset-standard
2747 :custom-standard-value 'custom-face-standard-value
2748 :custom-menu 'custom-face-menu-create)
2750 (define-widget 'custom-face-all 'editable-list
2751 "An editable list of display specifications and attributes."
2752 :entry-format "%i %d %v"
2753 :insert-button-args '(:help-echo "Insert new display specification here.")
2754 :append-button-args '(:help-echo "Append new display specification here.")
2755 :delete-button-args '(:help-echo "Delete this display specification.")
2756 :args '((group :format "%v" custom-display custom-face-edit)))
2758 (defconst custom-face-all (widget-convert 'custom-face-all)
2759 "Converted version of the `custom-face-all' widget.")
2761 (define-widget 'custom-display-unselected 'item
2762 "A display specification that doesn't match the selected display."
2763 :match 'custom-display-unselected-match)
2765 (defun custom-display-unselected-match (widget value)
2766 "Non-nil if VALUE is an unselected display specification."
2767 (not (face-spec-set-match-display value (selected-frame))))
2769 (define-widget 'custom-face-selected 'group
2770 "Edit the attributes of the selected display in a face specification."
2771 :args '((repeat :format ""
2773 (group custom-display-unselected sexp))
2774 (group (sexp :format "") custom-face-edit)
2779 (defconst custom-face-selected (widget-convert 'custom-face-selected)
2780 "Converted version of the `custom-face-selected' widget.")
2782 (defun custom-filter-face-spec (spec filter-index &optional default-filter)
2783 "Return a canonicalized version of SPEC using.
2784 FILTER-INDEX is the index in the entry for each attribute in
2785 `custom-face-attributes' at which the appropriate filter function can be
2786 found, and DEFAULT-FILTER is the filter to apply for attributes that
2788 (mapcar (lambda (entry)
2789 ;; Filter a single face-spec entry
2790 (let ((tests (car entry))
2792 ;; Handle both old- and new-style attribute syntax
2793 (if (listp (car (cdr entry)))
2796 (filtered-attrs nil))
2797 ;; Filter each face attribute
2798 (while unfiltered-attrs
2799 (let* ((attr (pop unfiltered-attrs))
2800 (pre-filtered-value (pop unfiltered-attrs))
2802 (or (nth filter-index (assq attr custom-face-attributes))
2806 (funcall filter pre-filtered-value)
2807 pre-filtered-value)))
2808 (push filtered-value filtered-attrs)
2809 (push attr filtered-attrs)))
2811 (list tests filtered-attrs)))
2814 (defun custom-pre-filter-face-spec (spec)
2815 "Return SPEC changed as necessary for editing by the face customization widget.
2816 SPEC must be a full face spec."
2817 (custom-filter-face-spec spec 2))
2819 (defun custom-post-filter-face-spec (spec)
2820 "Return the customized SPEC in a form suitable for setting the face."
2821 (custom-filter-face-spec spec 3))
2823 (defun custom-face-value-create (widget)
2824 "Create a list of the display specifications for WIDGET."
2825 (let ((buttons (widget-get widget :buttons))
2827 (symbol (widget-get widget :value))
2828 (tag (widget-get widget :tag))
2829 (state (widget-get widget :custom-state))
2831 (is-last (widget-get widget :custom-last))
2832 (prefix (widget-get widget :custom-prefix)))
2834 (setq tag (prin1-to-string symbol)))
2835 (cond ((eq custom-buffer-style 'tree)
2836 (insert prefix (if is-last " `--- " " |--- "))
2837 (push (widget-create-child-and-convert
2838 widget 'custom-browse-face-tag)
2840 (insert " " tag "\n")
2841 (widget-put widget :buttons buttons))
2845 (widget-specify-sample widget begin (point))
2846 (if (eq custom-buffer-style 'face)
2848 (if (string-match "face\\'" tag)
2850 (insert " face: ")))
2852 (push (widget-create-child-and-convert widget 'item
2859 (push (widget-create-child-and-convert
2861 :help-echo "Hide or show this face."
2864 :action 'custom-toggle-parent
2865 (not (eq state 'hidden)))
2869 (let ((magic (widget-create-child-and-convert
2870 widget 'custom-magic nil)))
2871 (widget-put widget :custom-magic magic)
2872 (push magic buttons))
2874 (widget-put widget :buttons buttons)
2875 ;; Insert documentation.
2876 (widget-default-format-handler widget ?h)
2877 ;; The comment field
2878 (unless (eq state 'hidden)
2879 (let* ((comment (get symbol 'face-comment))
2881 (widget-create-child-and-convert
2882 widget 'custom-comment
2884 :value (or comment ""))))
2885 (widget-put widget :comment-widget comment-widget)
2886 (push comment-widget children)))
2888 (unless (eq state 'hidden)
2889 (when (eq (widget-get widget :custom-level) 1)
2890 (custom-add-parent-links widget))
2891 (custom-add-see-also widget))
2893 (unless (eq (preceding-char) ?\n)
2895 (unless (eq state 'hidden)
2896 (message "Creating face editor...")
2897 (custom-load-widget widget)
2898 (unless (widget-get widget :custom-form)
2899 (widget-put widget :custom-form custom-face-default-form))
2900 (let* ((symbol (widget-value widget))
2901 (spec (or (get symbol 'customized-face)
2902 (get symbol 'saved-face)
2903 (get symbol 'face-defface-spec)
2904 ;; Attempt to construct it.
2905 (list (list t (custom-face-attributes-get
2906 symbol (selected-frame))))))
2907 (form (widget-get widget :custom-form))
2908 (indent (widget-get widget :indent))
2910 ;; If the user has changed this face in some other way,
2911 ;; edit it as the user has specified it.
2912 (if (not (face-spec-match-p symbol spec (selected-frame)))
2913 (setq spec (list (list t (face-attr-construct symbol (selected-frame))))))
2914 (setq spec (custom-pre-filter-face-spec spec))
2915 (setq edit (widget-create-child-and-convert
2917 (cond ((and (eq form 'selected)
2918 (widget-apply custom-face-selected
2920 (when indent (insert-char ?\ indent))
2921 'custom-face-selected)
2922 ((and (not (eq form 'lisp))
2923 (widget-apply custom-face-all
2927 (when indent (insert-char ?\ indent))
2930 (custom-face-state-set widget)
2931 (push edit children)
2932 (widget-put widget :children children))
2933 (message "Creating face editor...done"))))))
2935 (defvar custom-face-menu
2936 '(("Set for Current Session" custom-face-set)
2937 ("Save for Future Sessions" custom-face-save-command)
2938 ("Reset to Saved" custom-face-reset-saved
2940 (or (get (widget-value widget) 'saved-face)
2941 (get (widget-value widget) 'saved-face-comment))))
2942 ("Erase Customization" custom-face-reset-standard
2944 (get (widget-value widget) 'face-defface-spec)))
2945 ("---" ignore ignore)
2946 ("Add Comment" custom-comment-show custom-comment-invisible-p)
2947 ("---" ignore ignore)
2948 ("Show all display specs" custom-face-edit-all
2950 (not (eq (widget-get widget :custom-form) 'all))))
2951 ("Just current attributes" custom-face-edit-selected
2953 (not (eq (widget-get widget :custom-form) 'selected))))
2954 ("Show as Lisp expression" custom-face-edit-lisp
2956 (not (eq (widget-get widget :custom-form) 'lisp)))))
2957 "Alist of actions for the `custom-face' widget.
2958 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2959 the menu entry, ACTION is the function to call on the widget when the
2960 menu is selected, and FILTER is a predicate which takes a `custom-face'
2961 widget as an argument, and returns non-nil if ACTION is valid on that
2962 widget. If FILTER is nil, ACTION is always valid.")
2964 (defun custom-face-edit-selected (widget)
2965 "Edit selected attributes of the value of WIDGET."
2966 (widget-put widget :custom-state 'unknown)
2967 (widget-put widget :custom-form 'selected)
2968 (custom-redraw widget))
2970 (defun custom-face-edit-all (widget)
2971 "Edit all attributes of the value of WIDGET."
2972 (widget-put widget :custom-state 'unknown)
2973 (widget-put widget :custom-form 'all)
2974 (custom-redraw widget))
2976 (defun custom-face-edit-lisp (widget)
2977 "Edit the Lisp representation of the value of WIDGET."
2978 (widget-put widget :custom-state 'unknown)
2979 (widget-put widget :custom-form 'lisp)
2980 (custom-redraw widget))
2982 (defun custom-face-state-set (widget)
2983 "Set the state of WIDGET."
2984 (let* ((symbol (widget-value widget))
2985 (comment (get symbol 'face-comment))
2987 (widget-put widget :custom-state
2989 (setq tmp (get symbol 'customized-face))
2990 (setq temp (get symbol 'customized-face-comment))
2992 (if (equal temp comment)
2996 (setq tmp (get symbol 'saved-face))
2997 (setq temp (get symbol 'saved-face-comment))
2999 (if (equal temp comment)
3002 ((get symbol 'face-defface-spec)
3003 (if (equal comment nil)
3009 (defun custom-face-action (widget &optional event)
3010 "Show the menu for `custom-face' WIDGET.
3011 Optional EVENT is the location for the menu."
3012 (if (eq (widget-get widget :custom-state) 'hidden)
3013 (custom-toggle-hide widget)
3014 (let* ((completion-ignore-case t)
3015 (symbol (widget-get widget :value))
3016 (answer (widget-choose (concat "Operation on "
3017 (custom-unlispify-tag-name symbol))
3018 (custom-menu-filter custom-face-menu
3022 (funcall answer widget)))))
3024 (defun custom-face-set (widget)
3025 "Make the face attributes in WIDGET take effect."
3026 (let* ((symbol (widget-value widget))
3027 (child (car (widget-get widget :children)))
3028 (value (custom-post-filter-face-spec (widget-value child)))
3029 (comment-widget (widget-get widget :comment-widget))
3030 (comment (widget-value comment-widget)))
3031 (when (equal comment "")
3033 ;; Make the comment invisible by hand if it's empty
3034 (custom-comment-hide comment-widget))
3035 (put symbol 'customized-face value)
3036 (if (face-spec-choose value)
3037 (face-spec-set symbol value)
3038 ;; face-set-spec ignores empty attribute lists, so just give it
3039 ;; something harmless instead.
3040 (face-spec-set symbol '((t :foreground unspecified))))
3041 (put symbol 'customized-face-comment comment)
3042 (put symbol 'face-comment comment)
3043 (custom-face-state-set widget)
3044 (custom-redraw-magic widget)))
3046 (defun custom-face-save-command (widget)
3047 "Save in `.emacs' the face attributes in WIDGET."
3048 (custom-face-save widget)
3051 (defun custom-face-save (widget)
3052 "Prepare for saving WIDGET's face attributes, but don't write `.emacs'."
3053 (let* ((symbol (widget-value widget))
3054 (child (car (widget-get widget :children)))
3055 (value (custom-post-filter-face-spec (widget-value child)))
3056 (comment-widget (widget-get widget :comment-widget))
3057 (comment (widget-value comment-widget)))
3058 (when (equal comment "")
3060 ;; Make the comment invisible by hand if it's empty
3061 (custom-comment-hide comment-widget))
3062 (if (face-spec-choose value)
3063 (face-spec-set symbol value)
3064 ;; face-set-spec ignores empty attribute lists, so just give it
3065 ;; something harmless instead.
3066 (face-spec-set symbol '((t :foreground unspecified))))
3067 (unless (eq (widget-get widget :custom-state) 'standard)
3068 (put symbol 'saved-face value))
3069 (custom-push-theme 'theme-face symbol 'user 'set value)
3070 (put symbol 'customized-face nil)
3071 (put symbol 'face-comment comment)
3072 (put symbol 'customized-face-comment nil)
3073 (put symbol 'saved-face-comment comment)
3075 (custom-face-state-set widget)
3076 (custom-redraw-magic widget)))
3078 (defun custom-face-reset-saved (widget)
3079 "Restore WIDGET to the face's default attributes."
3080 (let* ((symbol (widget-value widget))
3081 (child (car (widget-get widget :children)))
3082 (value (get symbol 'saved-face))
3083 (comment (get symbol 'saved-face-comment))
3084 (comment-widget (widget-get widget :comment-widget)))
3085 (unless (or value comment)
3086 (error "No saved value for this face"))
3087 (put symbol 'customized-face nil)
3088 (put symbol 'customized-face-comment nil)
3089 (face-spec-set symbol value)
3090 (put symbol 'face-comment comment)
3091 (widget-value-set child value)
3092 ;; This call manages the comment visibility
3093 (widget-value-set comment-widget (or comment ""))
3094 (custom-face-state-set widget)
3095 (custom-redraw-magic widget)))
3097 (defun custom-face-standard-value (widget)
3098 (get (widget-value widget) 'face-defface-spec))
3100 (defun custom-face-reset-standard (widget)
3101 "Restore WIDGET to the face's standard settings.
3102 This operation eliminates any saved setting for the face,
3103 restoring it to the state of a face that has never been customized."
3104 (let* ((symbol (widget-value widget))
3105 (child (car (widget-get widget :children)))
3106 (value (get symbol 'face-defface-spec))
3107 (comment-widget (widget-get widget :comment-widget)))
3109 (error "No standard setting for this face"))
3110 (put symbol 'customized-face nil)
3111 (put symbol 'customized-face-comment nil)
3112 (when (or (get symbol 'saved-face) (get symbol 'saved-face-comment))
3113 (put symbol 'saved-face nil)
3114 (custom-push-theme 'theme-face symbol 'user 'reset 'standard)
3115 ;; Do not explictly save resets to standards without themes.
3116 (if (null (cdr (get symbol 'theme-face)))
3117 (put symbol 'theme-face nil))
3118 (put symbol 'saved-face-comment nil)
3120 (face-spec-set symbol value)
3121 (put symbol 'face-comment nil)
3122 (widget-value-set child value)
3123 ;; This call manages the comment visibility
3124 (widget-value-set comment-widget "")
3125 (custom-face-state-set widget)
3126 (custom-redraw-magic widget)))
3128 ;;; The `face' Widget.
3130 (define-widget 'face 'default
3131 "Select and customize a face."
3132 :convert-widget 'widget-value-convert-widget
3133 :button-prefix 'widget-push-button-prefix
3134 :button-suffix 'widget-push-button-suffix
3135 :format "%{%t%}: %[select face%] %v"
3138 :value-create 'widget-face-value-create
3139 :value-delete 'widget-face-value-delete
3140 :value-get 'widget-value-value-get
3141 :validate 'widget-children-validate
3142 :action 'widget-face-action
3143 :match (lambda (widget value) (symbolp value)))
3145 (defun widget-face-value-create (widget)
3146 "Create a `custom-face' child."
3147 (let* ((symbol (widget-value widget))
3148 (custom-buffer-style 'face)
3149 (child (widget-create-child-and-convert
3153 (custom-magic-reset child)
3154 (setq custom-options (cons child custom-options))
3155 (widget-put widget :children (list child))))
3157 (defun widget-face-value-delete (widget)
3158 "Remove the child from the options."
3159 (let ((child (car (widget-get widget :children))))
3160 (setq custom-options (delq child custom-options))
3161 (widget-children-value-delete widget)))
3163 (defvar face-history nil
3164 "History of entered face names.")
3166 (defun widget-face-action (widget &optional event)
3167 "Prompt for a face."
3168 (let ((answer (completing-read "Face: "
3169 (mapcar (lambda (face)
3170 (list (symbol-name face)))
3174 (unless (zerop (length answer))
3175 (widget-value-set widget (intern answer))
3176 (widget-apply widget :notify widget event)
3179 ;;; The `hook' Widget.
3181 (define-widget 'hook 'list
3183 :value-to-internal (lambda (widget value)
3184 (if (and value (symbolp value))
3187 :match (lambda (widget value)
3189 (widget-group-match widget value)))
3190 ;; Avoid adding undefined functions to the hook, especially for
3191 ;; things like `find-file-hook' or even more basic ones, to avoid
3193 :set (lambda (symbol value)
3196 (add-hook symbol elt))))
3197 :convert-widget 'custom-hook-convert-widget
3200 (defun custom-hook-convert-widget (widget)
3201 ;; Handle `:options'.
3202 (let* ((options (widget-get widget :options))
3203 (other `(editable-list :inline t
3204 :entry-format "%i %d%v"
3205 (function :format " %v")))
3207 (list `(checklist :inline t
3208 ,@(mapcar (lambda (entry)
3209 `(function-item ,entry))
3213 (widget-put widget :args args)
3216 ;;; The `custom-group-link' Widget.
3218 (define-widget 'custom-group-link 'link
3219 "Show parent in other window when activated."
3220 :help-echo "Create customization buffer for this group."
3221 :action 'custom-group-link-action)
3223 (defun custom-group-link-action (widget &rest ignore)
3224 (customize-group (widget-value widget)))
3226 ;;; The `custom-group' Widget.
3228 (defcustom custom-group-tag-faces nil
3229 ;; In XEmacs, this ought to play games with font size.
3230 ;; Fixme: make it do so in Emacs.
3231 "Face used for group tags.
3232 The first member is used for level 1 groups, the second for level 2,
3233 and so forth. The remaining group tags are shown with
3234 `custom-group-tag-face'."
3235 :type '(repeat face)
3236 :group 'custom-faces)
3238 (defface custom-group-tag-face-1
3241 (:foreground "pink" :weight bold :height 1.2 :inherit variable-pitch))
3244 (:foreground "red" :weight bold :height 1.2 :inherit variable-pitch))
3246 "Face used for group tags."
3247 :group 'custom-faces)
3249 (defface custom-group-tag-face
3252 (:foreground "light blue" :weight bold :height 1.2))
3255 (:foreground "blue" :weight bold :height 1.2))
3257 "Face used for low level group tags."
3258 :group 'custom-faces)
3260 (define-widget 'custom-group 'custom
3263 :sample-face-get 'custom-group-sample-face-get
3264 :documentation-property 'group-documentation
3265 :help-echo "Set or reset all members of this group."
3266 :value-create 'custom-group-value-create
3267 :action 'custom-group-action
3268 :custom-category 'group
3269 :custom-set 'custom-group-set
3270 :custom-save 'custom-group-save
3271 :custom-reset-current 'custom-group-reset-current
3272 :custom-reset-saved 'custom-group-reset-saved
3273 :custom-reset-standard 'custom-group-reset-standard
3274 :custom-menu 'custom-group-menu-create)
3276 (defun custom-group-sample-face-get (widget)
3277 ;; Use :sample-face.
3278 (or (nth (1- (widget-get widget :custom-level)) custom-group-tag-faces)
3279 'custom-group-tag-face))
3281 (define-widget 'custom-group-visibility 'visibility
3282 "An indicator and manipulator for hidden group contents."
3283 :create 'custom-group-visibility-create)
3285 (defun custom-group-visibility-create (widget)
3286 (let ((visible (widget-value widget)))
3288 (insert "--------")))
3289 (widget-default-create widget))
3291 (defun custom-group-members (symbol groups-only)
3292 "Return SYMBOL's custom group members.
3293 If GROUPS-ONLY non-nil, return only those members that are groups."
3294 (if (not groups-only)
3295 (get symbol 'custom-group)
3297 (dolist (entry (get symbol 'custom-group))
3298 (when (eq (nth 1 entry) 'custom-group)
3299 (push entry members)))
3300 (nreverse members))))
3302 (defun custom-group-value-create (widget)
3303 "Insert a customize group for WIDGET in the current buffer."
3304 (let* ((state (widget-get widget :custom-state))
3305 (level (widget-get widget :custom-level))
3306 ;; (indent (widget-get widget :indent))
3307 (prefix (widget-get widget :custom-prefix))
3308 (buttons (widget-get widget :buttons))
3309 (tag (widget-get widget :tag))
3310 (symbol (widget-value widget))
3311 (members (custom-group-members symbol
3312 (and (eq custom-buffer-style 'tree)
3313 custom-browse-only-groups))))
3314 (cond ((and (eq custom-buffer-style 'tree)
3316 (or members (custom-unloaded-widget-p widget)))
3317 (custom-browse-insert-prefix prefix)
3318 (push (widget-create-child-and-convert
3319 widget 'custom-browse-visibility
3320 ;; :tag-glyph "plus"
3324 ;; (widget-glyph-insert nil "-- " "horizontal")
3325 (push (widget-create-child-and-convert
3326 widget 'custom-browse-group-tag)
3328 (insert " " tag "\n")
3329 (widget-put widget :buttons buttons))
3330 ((and (eq custom-buffer-style 'tree)
3331 (zerop (length members)))
3332 (custom-browse-insert-prefix prefix)
3334 ;; (widget-glyph-insert nil "[ ]" "empty")
3335 ;; (widget-glyph-insert nil "-- " "horizontal")
3336 (push (widget-create-child-and-convert
3337 widget 'custom-browse-group-tag)
3339 (insert " " tag "\n")
3340 (widget-put widget :buttons buttons))
3341 ((eq custom-buffer-style 'tree)
3342 (custom-browse-insert-prefix prefix)
3343 (custom-load-widget widget)
3344 (if (zerop (length members))
3346 (custom-browse-insert-prefix prefix)
3348 ;; (widget-glyph-insert nil "[ ]" "empty")
3349 ;; (widget-glyph-insert nil "-- " "horizontal")
3350 (push (widget-create-child-and-convert
3351 widget 'custom-browse-group-tag)
3353 (insert " " tag "\n")
3354 (widget-put widget :buttons buttons))
3355 (push (widget-create-child-and-convert
3356 widget 'custom-browse-visibility
3357 ;; :tag-glyph "minus"
3361 ;; (widget-glyph-insert nil "-\\ " "top")
3362 (push (widget-create-child-and-convert
3363 widget 'custom-browse-group-tag)
3365 (insert " " tag "\n")
3366 (widget-put widget :buttons buttons)
3367 (message "Creating group...")
3368 (let* ((members (custom-sort-items members
3369 custom-browse-sort-alphabetically
3370 custom-browse-order-groups))
3371 (prefixes (widget-get widget :custom-prefixes))
3372 (custom-prefix-list (custom-prefix-add symbol prefixes))
3373 (extra-prefix (if (widget-get widget :custom-last)
3376 (prefix (concat prefix extra-prefix))
3379 (setq entry (car members)
3380 members (cdr members))
3381 (push (widget-create-child-and-convert
3382 widget (nth 1 entry)
3384 :tag (custom-unlispify-tag-name (nth 0 entry))
3385 :custom-prefixes custom-prefix-list
3386 :custom-level (1+ level)
3387 :custom-last (null members)
3388 :value (nth 0 entry)
3389 :custom-prefix prefix)
3391 (widget-put widget :children (reverse children)))
3392 (message "Creating group...done")))
3395 ;; Create level indicator.
3396 (unless (eq custom-buffer-style 'links)
3397 (insert-char ?\ (* custom-buffer-indent (1- level)))
3400 (let ((begin (point)))
3402 (widget-specify-sample widget begin (point)))
3404 ;; Create link/visibility indicator.
3405 (if (eq custom-buffer-style 'links)
3406 (push (widget-create-child-and-convert
3407 widget 'custom-group-link
3411 (push (widget-create-child-and-convert
3412 widget 'custom-group-visibility
3413 :help-echo "Show members of this group."
3414 :action 'custom-toggle-parent
3415 (not (eq state 'hidden)))
3418 ;; Create magic button.
3419 (let ((magic (widget-create-child-and-convert
3420 widget 'custom-magic nil)))
3421 (widget-put widget :custom-magic magic)
3422 (push magic buttons))
3424 (widget-put widget :buttons buttons)
3425 ;; Insert documentation.
3426 (if (and (eq custom-buffer-style 'links) (> level 1))
3427 (widget-put widget :documentation-indent 0))
3428 (widget-default-format-handler widget ?h))
3431 ;; Add parent groups references above the group.
3432 (if t ;;; This should test that the buffer
3433 ;;; was made to display a group.
3435 (if (custom-add-parent-links widget
3436 "Go to parent group:")
3438 ;; Create level indicator.
3439 (insert-char ?\ (* custom-buffer-indent (1- level)))
3442 (let ((start (point)))
3444 (widget-specify-sample widget start (point)))
3446 ;; Create visibility indicator.
3447 (unless (eq custom-buffer-style 'links)
3449 (push (widget-create-child-and-convert
3451 :help-echo "Hide members of this group."
3452 :action 'custom-toggle-parent
3453 (not (eq state 'hidden)))
3456 ;; Create more dashes.
3457 ;; Use 76 instead of 75 to compensate for the temporary "<"
3458 ;; added by `widget-insert'.
3459 (insert-char ?- (- 76 (current-column)
3460 (* custom-buffer-indent level)))
3462 ;; Create magic button.
3463 (let ((magic (widget-create-child-and-convert
3464 widget 'custom-magic
3467 (widget-put widget :custom-magic magic)
3468 (push magic buttons))
3470 (widget-put widget :buttons buttons)
3471 ;; Insert documentation.
3472 (widget-default-format-handler widget ?h)
3474 (if nil ;;; This should test that the buffer
3475 ;;; was not made to display a group.
3477 (insert-char ?\ custom-buffer-indent)
3478 (custom-add-parent-links widget)))
3479 (custom-add-see-also widget
3480 (make-string (* custom-buffer-indent level)
3483 (message "Creating group...")
3484 (custom-load-widget widget)
3485 (let* ((members (custom-sort-items members
3486 custom-buffer-sort-alphabetically
3487 custom-buffer-order-groups))
3488 (prefixes (widget-get widget :custom-prefixes))
3489 (custom-prefix-list (custom-prefix-add symbol prefixes))
3490 (length (length members))
3492 (children (mapcar (lambda (entry)
3493 (widget-insert "\n")
3495 Creating group members... %2d%%"
3496 (/ (* 100.0 count) length))
3497 (setq count (1+ count))
3499 (widget-create-child-and-convert
3500 widget (nth 1 entry)
3502 :tag (custom-unlispify-tag-name
3504 :custom-prefixes custom-prefix-list
3505 :custom-level (1+ level)
3506 :value (nth 0 entry))
3507 (unless (eq (preceding-char) ?\n)
3508 (widget-insert "\n"))))
3510 (message "Creating group magic...")
3511 (mapc 'custom-magic-reset children)
3512 (message "Creating group state...")
3513 (widget-put widget :children children)
3514 (custom-group-state-update widget)
3515 (message "Creating group... done"))
3518 (insert-char ?\ (* custom-buffer-indent (1- level)))
3519 (insert "\\- " (widget-get widget :tag) " group end ")
3520 (insert-char ?- (- 75 (current-column) (* custom-buffer-indent level)))
3523 (defvar custom-group-menu
3524 '(("Set for Current Session" custom-group-set
3526 (eq (widget-get widget :custom-state) 'modified)))
3527 ("Save for Future Sessions" custom-group-save
3529 (memq (widget-get widget :custom-state) '(modified set))))
3530 ("Reset to Current" custom-group-reset-current
3532 (memq (widget-get widget :custom-state) '(modified))))
3533 ("Reset to Saved" custom-group-reset-saved
3535 (memq (widget-get widget :custom-state) '(modified set))))
3536 ("Reset to standard setting" custom-group-reset-standard
3538 (memq (widget-get widget :custom-state) '(modified set saved)))))
3539 "Alist of actions for the `custom-group' widget.
3540 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3541 the menu entry, ACTION is the function to call on the widget when the
3542 menu is selected, and FILTER is a predicate which takes a `custom-group'
3543 widget as an argument, and returns non-nil if ACTION is valid on that
3544 widget. If FILTER is nil, ACTION is always valid.")
3546 (defun custom-group-action (widget &optional event)
3547 "Show the menu for `custom-group' WIDGET.
3548 Optional EVENT is the location for the menu."
3549 (if (eq (widget-get widget :custom-state) 'hidden)
3550 (custom-toggle-hide widget)
3551 (let* ((completion-ignore-case t)
3552 (answer (widget-choose (concat "Operation on "
3553 (custom-unlispify-tag-name
3554 (widget-get widget :value)))
3555 (custom-menu-filter custom-group-menu
3559 (funcall answer widget)))))
3561 (defun custom-group-set (widget)
3562 "Set changes in all modified group members."
3563 (let ((children (widget-get widget :children)))
3564 (mapc (lambda (child)
3565 (when (eq (widget-get child :custom-state) 'modified)
3566 (widget-apply child :custom-set)))
3569 (defun custom-group-save (widget)
3570 "Save all modified group members."
3571 (let ((children (widget-get widget :children)))
3572 (mapc (lambda (child)
3573 (when (memq (widget-get child :custom-state) '(modified set))
3574 (widget-apply child :custom-save)))
3577 (defun custom-group-reset-current (widget)
3578 "Reset all modified group members."
3579 (let ((children (widget-get widget :children)))
3580 (mapc (lambda (child)
3581 (when (eq (widget-get child :custom-state) 'modified)
3582 (widget-apply child :custom-reset-current)))
3585 (defun custom-group-reset-saved (widget)
3586 "Reset all modified or set group members."
3587 (let ((children (widget-get widget :children)))
3588 (mapc (lambda (child)
3589 (when (memq (widget-get child :custom-state) '(modified set))
3590 (widget-apply child :custom-reset-saved)))
3593 (defun custom-group-reset-standard (widget)
3594 "Reset all modified, set, or saved group members."
3595 (let ((children (widget-get widget :children)))
3596 (mapc (lambda (child)
3597 (when (memq (widget-get child :custom-state)
3598 '(modified set saved))
3599 (widget-apply child :custom-reset-standard)))
3602 (defun custom-group-state-update (widget)
3604 (unless (eq (widget-get widget :custom-state) 'hidden)
3605 (let* ((children (widget-get widget :children))
3606 (states (mapcar (lambda (child)
3607 (widget-get child :custom-state))
3609 (magics custom-magic-alist)
3612 (let ((magic (car (car magics))))
3613 (if (and (not (eq magic 'hidden))
3614 (memq magic states))
3617 (setq magics (cdr magics)))))
3618 (widget-put widget :custom-state found)))
3619 (custom-magic-reset widget))
3621 ;;; The `custom-save-all' Function.
3623 (defcustom custom-file nil
3624 "File used for storing customization information.
3625 The default is nil, which means to use your init file
3626 as specified by `user-init-file'. If you specify some other file,
3627 you need to explicitly load that file for the settings to take effect.
3629 When you change this variable, look in the previous custom file
3630 \(usually your init file) for the forms `(custom-set-variables ...)'
3631 and `(custom-set-faces ...)', and copy them (whichever ones you find)
3632 to the new custom file. This will preserve your existing customizations."
3633 :type '(choice (const :tag "Your Emacs init file" nil) file)
3636 (defun custom-file ()
3637 "Return the file name for saving customizations."
3640 (let ((user-init-file user-init-file)
3642 (if (eq system-type 'ms-dos) "~/_emacs" "~/.emacs")))
3643 (when (null user-init-file)
3644 (if (or (file-exists-p default-init-file)
3645 (and (eq system-type 'windows-nt)
3646 (file-exists-p "~/_emacs")))
3647 ;; Started with -q, i.e. the file containing
3648 ;; Custom settings hasn't been read. Saving
3649 ;; settings there would overwrite other settings.
3650 (error "Saving settings from \"emacs -q\" would overwrite existing customizations"))
3651 (setq user-init-file default-init-file))
3654 (defun custom-save-delete (symbol)
3655 "Visit `custom-file' and delete all calls to SYMBOL from it.
3656 Leave point at the old location of the first such call,
3657 or (if there were none) at the end of the buffer."
3658 (let ((default-major-mode 'emacs-lisp-mode))
3659 (set-buffer (find-file-noselect (custom-file))))
3660 (goto-char (point-min))
3661 ;; Skip all whitespace and comments.
3662 (while (forward-comment 1))
3664 (save-excursion (forward-sexp (buffer-size)))) ; Test for scan errors.
3667 (while t ;; We exit this loop only via throw.
3668 ;; Skip all whitespace and comments.
3669 (while (forward-comment 1))
3670 (let ((start (point))
3671 (sexp (condition-case nil
3672 (read (current-buffer))
3673 (end-of-file (throw 'found nil)))))
3674 (when (and (listp sexp)
3675 (eq (car sexp) symbol))
3676 (delete-region start (point))
3678 (setq first (point)))))))
3681 ;; Move in front of local variables, otherwise long Custom
3682 ;; entries would make them ineffective.
3683 (let ((pos (point-max))
3684 (case-fold-search t))
3686 (goto-char (point-max))
3687 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
3689 (when (search-forward "Local Variables:" nil t)
3690 (setq pos (line-beginning-position))))
3693 (defun custom-save-variables ()
3694 "Save all customized variables in `custom-file'."
3696 (custom-save-delete 'custom-load-themes)
3697 (custom-save-delete 'custom-reset-variables)
3698 (custom-save-delete 'custom-set-variables)
3699 (custom-save-loaded-themes)
3700 (custom-save-resets 'theme-value 'custom-reset-variables nil)
3701 (let ((standard-output (current-buffer))
3702 (saved-list (make-list 1 0))
3704 ;; First create a sorted list of saved variables.
3707 (if (get symbol 'saved-value)
3708 (nconc saved-list (list symbol)))))
3709 (setq saved-list (sort (cdr saved-list) 'string<))
3712 (princ "(custom-set-variables
3713 ;; custom-set-variables was added by Custom.
3714 ;; If you edit it by hand, you could mess it up, so be careful.
3715 ;; Your init file should contain only one such instance.
3716 ;; If there is more than one, they won't work right.\n")
3719 (let ((spec (car-safe (get symbol 'theme-value)))
3720 (value (get symbol 'saved-value))
3721 (requests (get symbol 'custom-requests))
3722 (now (not (or (custom-variable-p symbol)
3723 (and (not (boundp symbol))
3724 (not (eq (get symbol 'force-value)
3726 (comment (get symbol 'saved-variable-comment))
3729 (eq (nth 0 spec) 'user)
3730 (eq (nth 1 spec) 'set))
3738 (cond ((or now requests comment)
3743 (cond ((or requests comment)
3762 (unless (looking-at "\n")
3765 (defun custom-save-faces ()
3766 "Save all customized faces in `custom-file'."
3768 (custom-save-delete 'custom-reset-faces)
3769 (custom-save-delete 'custom-set-faces)
3770 (custom-save-resets 'theme-face 'custom-reset-faces '(default))
3771 (let ((standard-output (current-buffer))
3772 (saved-list (make-list 1 0))
3774 ;; First create a sorted list of saved faces.
3777 (if (get symbol 'saved-face)
3778 (nconc saved-list (list symbol)))))
3779 (setq saved-list (sort (cdr saved-list) 'string<))
3780 ;; The default face must be first, since it affects the others.
3781 (if (memq 'default saved-list)
3782 (setq saved-list (cons 'default (delq 'default saved-list))))
3785 (princ "(custom-set-faces
3786 ;; custom-set-faces was added by Custom.
3787 ;; If you edit it by hand, you could mess it up, so be careful.
3788 ;; Your init file should contain only one such instance.
3789 ;; If there is more than one, they won't work right.\n")
3792 (let ((theme-spec (car-safe (get symbol 'theme-face)))
3793 (value (get symbol 'saved-face))
3794 (now (not (or (get symbol 'face-defface-spec)
3795 (and (not (custom-facep symbol))
3796 (not (get symbol 'force-face))))))
3797 (comment (get symbol 'saved-face-comment)))
3798 (when (or (and theme-spec
3799 (eq (nth 0 theme-spec) 'user)
3800 (eq (nth 1 theme-spec) 'set))
3802 ;; Don't print default face here.
3809 (cond ((or now comment)
3826 (unless (looking-at "\n")
3829 (defun custom-save-resets (property setter special)
3830 (let (started-writing ignored-special)
3831 ;; (custom-save-delete setter) Done by caller
3832 (let ((standard-output (current-buffer))
3833 (mapper `(lambda (object)
3834 (let ((spec (car-safe (get object (quote ,property)))))
3835 (when (and (not (memq object ignored-special))
3836 (eq (nth 0 spec) 'user)
3837 (eq (nth 1 spec) 'reset))
3838 ;; Do not write reset statements unless necessary.
3839 (unless started-writing
3840 (setq started-writing t)
3844 (princ (quote ,setter))
3848 (prin1 (nth 3 spec))
3850 (mapc mapper special)
3851 (setq ignored-special special)
3853 (when started-writing
3856 (defun custom-save-loaded-themes ()
3857 (let ((themes (reverse (get 'user 'theme-loads-themes)))
3858 (standard-output (current-buffer)))
3860 (unless (bolp) (princ "\n"))
3861 (princ "(custom-load-themes")
3862 (mapc (lambda (theme)
3864 (prin1 theme)) themes)
3868 (defun customize-save-customized ()
3869 "Save all user options which have been set in this session."
3871 (mapatoms (lambda (symbol)
3872 (let ((face (get symbol 'customized-face))
3873 (value (get symbol 'customized-value))
3874 (face-comment (get symbol 'customized-face-comment))
3876 (get symbol 'customized-variable-comment)))
3878 (put symbol 'saved-face face)
3879 (custom-push-theme 'theme-face symbol 'user 'set value)
3880 (put symbol 'customized-face nil))
3882 (put symbol 'saved-value value)
3883 (custom-push-theme 'theme-value symbol 'user 'set value)
3884 (put symbol 'customized-value nil))
3885 (when variable-comment
3886 (put symbol 'saved-variable-comment variable-comment)
3887 (put symbol 'customized-variable-comment nil))
3889 (put symbol 'saved-face-comment face-comment)
3890 (put symbol 'customized-face-comment nil)))))
3891 ;; We really should update all custom buffers here.
3895 (defun custom-save-all ()
3896 "Save all customizations in `custom-file'."
3897 (let ((inhibit-read-only t))
3898 (custom-save-variables)
3901 (let ((default-major-mode nil))
3902 (set-buffer (find-file-noselect (custom-file))))
3903 (let ((file-precious-flag t))
3906 ;;; The Customize Menu.
3910 (defcustom custom-menu-nesting 2
3911 "Maximum nesting in custom menus."
3913 :group 'custom-menu)
3915 (defun custom-face-menu-create (widget symbol)
3916 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
3917 (vector (custom-unlispify-menu-entry symbol)
3918 `(customize-face ',symbol)
3921 (defun custom-variable-menu-create (widget symbol)
3922 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
3923 (let ((type (get symbol 'custom-type)))
3924 (unless (listp type)
3925 (setq type (list type)))
3926 (if (and type (widget-get type :custom-menu))
3927 (widget-apply type :custom-menu symbol)
3928 (vector (custom-unlispify-menu-entry symbol)
3929 `(customize-variable ',symbol)
3932 ;; Add checkboxes to boolean variable entries.
3933 (widget-put (get 'boolean 'widget-type)
3934 :custom-menu (lambda (widget symbol)
3935 (vector (custom-unlispify-menu-entry symbol)
3936 `(customize-variable ',symbol)
3938 ':selected symbol)))
3940 (defun custom-group-menu-create (widget symbol)
3941 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
3942 `( ,(custom-unlispify-menu-entry symbol t)
3943 :filter (lambda (&rest junk)
3944 (let ((menu (custom-menu-create ',symbol)))
3945 (if (consp menu) (cdr menu) menu)))))
3948 (defun custom-menu-create (symbol)
3949 "Create menu for customization group SYMBOL.
3950 The menu is in a format applicable to `easy-menu-define'."
3951 (let* ((item (vector (custom-unlispify-menu-entry symbol)
3952 `(customize-group ',symbol)
3954 (if (and (or (not (boundp 'custom-menu-nesting))
3955 (>= custom-menu-nesting 0))
3956 (< (length (get symbol 'custom-group)) widget-menu-max-size))
3957 (let ((custom-prefix-list (custom-prefix-add symbol
3958 custom-prefix-list))
3959 (members (custom-sort-items (get symbol 'custom-group)
3960 custom-menu-sort-alphabetically
3961 custom-menu-order-groups)))
3962 (custom-load-symbol symbol)
3963 `(,(custom-unlispify-menu-entry symbol t)
3966 ,@(mapcar (lambda (entry)
3967 (widget-apply (if (listp (nth 1 entry))
3969 (list (nth 1 entry)))
3970 :custom-menu (nth 0 entry)))
3975 (defun customize-menu-create (symbol &optional name)
3976 "Return a customize menu for customization group SYMBOL.
3977 If optional NAME is given, use that as the name of the menu.
3978 Otherwise the menu will be named `Customize'.
3979 The format is suitable for use with `easy-menu-define'."
3981 (setq name "Customize"))
3983 :filter (lambda (&rest junk)
3984 (let ((menu (custom-menu-create ',symbol)))
3985 (if (consp menu) (cdr menu) menu)))))
3987 ;;; The Custom Mode.
3989 (defvar custom-mode-map nil
3990 "Keymap for `custom-mode'.")
3992 (unless custom-mode-map
3993 ;; This keymap should be dense, but a dense keymap would prevent inheriting
3994 ;; "\r" bindings from the parent map.
3995 (setq custom-mode-map (make-sparse-keymap))
3996 (set-keymap-parent custom-mode-map widget-keymap)
3997 (suppress-keymap custom-mode-map)
3998 (define-key custom-mode-map " " 'scroll-up)
3999 (define-key custom-mode-map "\177" 'scroll-down)
4000 (define-key custom-mode-map "q" 'Custom-buffer-done)
4001 (define-key custom-mode-map "u" 'Custom-goto-parent)
4002 (define-key custom-mode-map "n" 'widget-forward)
4003 (define-key custom-mode-map "p" 'widget-backward)
4004 (define-key custom-mode-map [mouse-1] 'Custom-move-and-invoke))
4006 (defun Custom-move-and-invoke (event)
4007 "Move to where you click, and if it is an active field, invoke it."
4009 (mouse-set-point event)
4010 (if (widget-event-point event)
4011 (let* ((pos (widget-event-point event))
4012 (button (get-char-property pos 'button)))
4014 (widget-button-click event)))))
4016 (easy-menu-define Custom-mode-menu
4018 "Menu used in customization buffers."
4020 ,(customize-menu-create 'customize)
4021 ["Set" Custom-set t]
4022 ["Save" Custom-save t]
4023 ["Reset to Current" Custom-reset-current t]
4024 ["Reset to Saved" Custom-reset-saved t]
4025 ["Reset to Standard Settings" Custom-reset-standard t]
4026 ["Info" (Info-goto-node "(emacs)Easy Customization") t]))
4028 (defun Custom-goto-parent ()
4029 "Go to the parent group listed at the top of this buffer.
4030 If several parents are listed, go to the first of them."
4033 (goto-char (point-min))
4034 (if (search-forward "\nGo to parent group: " nil t)
4035 (let* ((button (get-char-property (point) 'button))
4036 (parent (downcase (widget-get button :tag))))
4037 (customize-group parent)))))
4039 (defcustom custom-mode-hook nil
4040 "Hook called when entering Custom mode."
4042 :group 'custom-buffer )
4044 (defun custom-state-buffer-message (widget)
4045 (if (eq (widget-get (widget-get widget :parent) :custom-state) 'modified)
4046 (message "To install your edits, invoke [State] and choose the Set operation")))
4048 (defun custom-mode ()
4049 "Major mode for editing customization buffers.
4051 The following commands are available:
4053 Move to next button or editable field. \\[widget-forward]
4054 Move to previous button or editable field. \\[widget-backward]
4055 \\<widget-field-keymap>\
4056 Complete content of editable text field. \\[widget-complete]
4057 \\<custom-mode-map>\
4058 Invoke button under the mouse pointer. \\[Custom-move-and-invoke]
4059 Invoke button under point. \\[widget-button-press]
4060 Set all modifications. \\[Custom-set]
4061 Make all modifications default. \\[Custom-save]
4062 Reset all modified options. \\[Custom-reset-current]
4063 Reset all modified or set options. \\[Custom-reset-saved]
4064 Reset all options. \\[Custom-reset-standard]
4066 Entry to this mode calls the value of `custom-mode-hook'
4067 if that value is non-nil."
4068 (kill-all-local-variables)
4069 (setq major-mode 'custom-mode
4071 (use-local-map custom-mode-map)
4072 (easy-menu-add Custom-mode-menu)
4073 (make-local-variable 'custom-options)
4074 (make-local-variable 'widget-documentation-face)
4075 (setq widget-documentation-face 'custom-documentation-face)
4076 (make-local-variable 'widget-button-face)
4077 (setq widget-button-face 'custom-button-face)
4078 (set (make-local-variable 'widget-button-pressed-face)
4079 'custom-button-pressed-face)
4080 (set (make-local-variable 'widget-mouse-face)
4081 'custom-button-pressed-face) ; buttons `depress' when moused
4082 ;; When possible, use relief for buttons, not bracketing. This test
4083 ;; may not be optimal.
4084 (when custom-raised-buttons
4085 (set (make-local-variable 'widget-push-button-prefix) "")
4086 (set (make-local-variable 'widget-push-button-suffix) "")
4087 (set (make-local-variable 'widget-link-prefix) "")
4088 (set (make-local-variable 'widget-link-suffix) ""))
4089 (add-hook 'widget-edit-functions 'custom-state-buffer-message nil t)
4090 (run-hooks 'custom-mode-hook))
4092 (put 'custom-mode 'mode-class 'special)
4095 'debug-ignored-errors
4096 "^No user options have changed defaults in recent Emacs versions$")
4102 ;;; cus-edit.el ends here