1 ;;; cus-edit.el --- Tools for customizating Emacs and Lisp packages.
3 ;; Copyright (C) 1996, 1997 Free Software Foundation, Inc.
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
6 ;; Maintainer: Hrvoje Niksic <hniksic@srce.hr>
7 ;; Keywords: help, faces
9 ;; X-URL: http://www.dina.kvl.dk/~abraham/custom/
11 ;; This file is part of XEmacs.
13 ;; XEmacs is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
18 ;; XEmacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with XEmacs; see the file COPYING. If not, write to the
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
26 ;; Boston, MA 02111-1307, USA.
30 ;; This file implements the code to create and edit customize buffers.
34 ;; No commands should have names starting with `custom-' because
35 ;; that interferes with completion. Use `customize-' for commands
36 ;; that the user will run with M-x, and `Custom-' for interactive commands.
38 ;; NOTE: In many places within this file we use `mapatoms', which is
39 ;; very slow in an average XEmacs because of the large number of
40 ;; symbols requiring a large number of funcalls -- XEmacs with Gnus
41 ;; can grow to some 17000 symbols without ever doing anything fancy.
42 ;; It would probably pay off to make a hash table of symbols known to
43 ;; Custom, similar to custom-group-hash-table.
45 ;; This is not top priority, because none of the functions that do
46 ;; mapatoms are speed-critical (the one that was now uses
47 ;; custom-group-hash-table), but it would be nice to have.
59 ;; Huh? This looks dirty!
60 (put 'custom-define-hook 'custom-type 'hook)
61 (put 'custom-define-hook 'standard-value '(nil))
62 (custom-add-to-group 'customize 'custom-define-hook 'custom-variable)
64 ;;; Customization Groups.
67 "Customization of the One True Editor."
68 :link '(custom-manual "(XEmacs)Top"))
70 ;; Most of these groups are stolen from `finder.el',
72 "Basic text editing facilities."
75 (defgroup matching nil
76 "Various sorts of searching and matching."
79 (defgroup emulations nil
80 "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 programming nil
97 "Support for programming in other languages."
100 (defgroup languages nil
101 "Specialized modes for editing programming languages."
104 ;; #### This should be in cc-vars.el
106 "Support for the C language and related languages."
114 "Support for object-oriented programming."
117 (defgroup applications nil
118 "Applications written in Emacs."
121 ;; #### This should be in calendar.el
122 (defgroup calendar nil
123 "Calendar and time management support."
124 :group 'applications)
127 "Modes for electronic-mail handling."
128 :group 'applications)
131 "Support for netnews reading and posting."
132 :group 'applications)
135 "Games, jokes and amusements."
136 :group 'applications)
138 (defgroup development nil
139 "Support for further development of Emacs."
143 "Support for Emacs documentation."
146 (defgroup extensions nil
147 "Emacs Lisp language extensions."
150 (defgroup internal nil
151 "Code for Emacs internals, build process, defaults."
155 "Maintenance aids for the Emacs development group."
159 (defgroup environment nil
160 "Fitting Emacs with its environment."
164 "Communications, networking, remote access to files."
168 (defgroup hardware nil
169 "Support for interfacing with exotic hardware."
172 (defgroup terminals nil
173 "Support for terminal types."
177 "Front-ends/assistants for, or emulators of, UNIX features."
181 "Internationalization and alternate character-set support."
186 "Support editing files of data."
194 "Code related to the TeX formatter."
197 (defgroup hypermedia nil
198 "Support for links between text or other media types."
202 "Code local to your site."
205 (defgroup customize '((widgets custom-group))
206 "Customization of the Customization support."
207 :link '(custom-manual "(custom)Top")
208 :link '(url-link :tag "Development Page"
209 "http://www.dina.kvl.dk/~abraham/custom/")
213 (defgroup custom-faces nil
214 "Faces used by customize."
218 (defgroup custom-browse nil
219 "Control customize browser."
223 (defgroup custom-buffer nil
224 "Control customize buffers."
228 (defgroup custom-menu nil
229 "Control customize menus."
234 "Storage allocation and gc for GNU Emacs Lisp interpreter."
235 :tag "Storage Allocation"
239 "Undoing changes in buffers."
242 (defgroup editing-basics nil
243 "Most basic editing facilities."
246 (defgroup display nil
247 "How characters are displayed in buffers."
250 (defgroup installation nil
251 "The Emacs installation."
255 "Internal Emacs limits."
259 "Debugging Emacs itself."
263 "Mule XEmacs internationalization."
269 (defun custom-quote (sexp)
270 "Quote SEXP iff it is not self quoting."
271 (if (or (memq sexp '(t nil))
273 (eq (car-safe sexp) 'lambda)
282 (defun custom-split-regexp-maybe (regexp)
283 "If REGEXP is a string, split it to a list at `\\|'.
284 You can get the original back with from the result with:
285 (mapconcat #'identity result \"\\|\")
287 IF REGEXP is not a string, return it unchanged."
289 (split-string regexp "\\\\|")
292 (defun custom-variable-prompt ()
293 ;; Code stolen from `help.el'.
294 "Prompt for a variable, defaulting to the variable at point.
295 Return a list suitable for use in `interactive'."
296 (let ((v (variable-at-point))
297 (enable-recursive-minibuffers t)
299 (setq val (completing-read
301 (format "Customize variable: (default %s) " v)
302 "Customize variable: ")
303 obarray (lambda (symbol)
305 (or (get symbol 'custom-type)
306 (user-variable-p symbol)))) t))
307 (list (if (equal val "")
308 (if (symbolp v) v nil)
311 ;; Here we take not only the actual groups, but the loads, too.
312 (defun custom-group-prompt (prompt)
313 "Read group from minibuffer."
314 (let ((completion-ignore-case t))
315 (list (completing-read
318 (or (get symbol 'custom-group)
319 (get symbol 'custom-loads)))
322 (defun custom-menu-filter (menu widget)
323 "Convert MENU to the form used by `widget-choose'.
324 MENU should be in the same format as `custom-variable-menu'.
325 WIDGET is the widget to apply the filter entries of MENU on."
327 current name action filter)
329 (setq current (car menu)
331 action (nth 1 current)
332 filter (nth 2 current)
334 (if (or (null filter) (funcall filter widget))
335 (push (cons name action) result)
342 (defvar custom-prefix-list nil
343 "List of prefixes that should be ignored by `custom-unlispify'")
345 (defcustom custom-unlispify-menu-entries t
346 "Display menu entries as words instead of symbols if non nil."
350 (defcustom custom-unlispify-remove-prefixes t
351 "Non-nil means remove group prefixes from option names in buffers and menus.
352 This only has an effect when `custom-unlispify-tag-names' or
353 `custom-unlispify-menu-entries' is on."
357 (defun custom-unlispify-menu-entry (symbol &optional no-suffix)
358 "Convert symbol into a menu entry."
359 (cond ((not custom-unlispify-menu-entries)
360 (symbol-name symbol))
361 ((get symbol 'custom-tag)
363 (get symbol 'custom-tag)
364 (concat (get symbol 'custom-tag) "...")))
366 (with-current-buffer (get-buffer-create " *Custom-Work*")
368 (princ symbol (current-buffer))
369 (goto-char (point-min))
370 (when (and (eq (get symbol 'custom-type) 'boolean)
371 (re-search-forward "-p\\'" nil t))
372 (replace-match "" t t)
373 (goto-char (point-min)))
374 (when custom-unlispify-remove-prefixes
375 (let ((prefixes custom-prefix-list)
378 (setq prefix (car prefixes))
379 (if (search-forward prefix (+ (point) (length prefix)) t)
382 (delete-region (point-min) (point)))
383 (setq prefixes (cdr prefixes))))))
384 (subst-char-in-region (point-min) (point-max) ?- ?\ t)
385 (capitalize-region (point-min) (point-max))
387 (goto-char (point-max))
391 (defcustom custom-unlispify-tag-names t
392 "Display tag names as words instead of symbols if non nil."
393 :group 'custom-buffer
396 (defun custom-unlispify-tag-name (symbol)
397 "Convert symbol into a menu entry."
398 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names))
399 (custom-unlispify-menu-entry symbol t)))
401 (defun custom-prefix-add (symbol prefixes)
402 ;; Addd SYMBOL to list of ignored PREFIXES.
403 (cons (or (get symbol 'custom-prefix)
404 (concat (symbol-name symbol) "-"))
410 (defcustom custom-guess-name-alist
415 ("-function\\'" function)
416 ("-functions\\'" (repeat function))
417 ("-list\\'" (repeat sexp))
418 ("-alist\\'" (repeat (cons sexp sexp))))
419 "Alist of (MATCH TYPE).
421 MATCH should be a regexp matching the name of a symbol, and TYPE should
422 be a widget suitable for editing the value of that symbol. The TYPE
423 of the first entry where MATCH matches the name of the symbol will be
426 This is used for guessing the type of variables not declared with
428 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
431 (defcustom custom-guess-doc-alist
432 '(("\\`\\*?Non-nil " boolean))
433 "Alist of (MATCH TYPE).
435 MATCH should be a regexp matching a documentation string, and TYPE
436 should be a widget suitable for editing the value of a variable with
437 that documentation string. The TYPE of the first entry where MATCH
438 matches the name of the symbol will be used.
440 This is used for guessing the type of variables not declared with
442 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
445 (defun custom-guess-type (symbol)
446 "Guess a widget suitable for editing the value of SYMBOL.
447 This is done by matching SYMBOL with `custom-guess-name-alist' and
448 if that fails, the doc string with `custom-guess-doc-alist'."
449 (let ((name (symbol-name symbol))
450 (names custom-guess-name-alist)
453 (setq current (car names)
455 (when (string-match (nth 0 current) name)
456 (setq found (nth 1 current)
459 (let ((doc (documentation-property symbol 'variable-documentation))
460 (docs custom-guess-doc-alist))
463 (setq current (car docs)
465 (when (string-match (nth 0 current) doc)
466 (setq found (nth 1 current)
473 (defcustom custom-browse-sort-alphabetically nil
474 "If non-nil, sort members of each customization group alphabetically."
476 :group 'custom-browse)
478 (defcustom custom-browse-order-groups nil
479 "If non-nil, order group members within each customization group.
480 If `first', order groups before non-groups.
481 If `last', order groups after non-groups."
482 :type '(choice (const first)
484 (const :tag "none" nil))
485 :group 'custom-browse)
487 (defcustom custom-browse-only-groups nil
488 "If non-nil, show group members only within each customization group."
490 :group 'custom-browse)
492 (defcustom custom-buffer-sort-alphabetically nil
493 "If non-nil, sort members of each customization group alphabetically."
495 :group 'custom-buffer)
497 (defcustom custom-buffer-order-groups 'last
498 "If non-nil, order group members within each customization group.
499 If `first', order groups before non-groups.
500 If `last', order groups after non-groups."
501 :type '(choice (const first)
503 (const :tag "none" nil))
504 :group 'custom-buffer)
506 (defcustom custom-menu-sort-alphabetically nil
507 "If non-nil, sort members of each customization group alphabetically."
511 (defcustom custom-menu-order-groups 'first
512 "If non-nil, order group members within each customization group.
513 If `first', order groups before non-groups.
514 If `last', order groups after non-groups."
515 :type '(choice (const first)
517 (const :tag "none" nil))
520 (defun custom-sort-items (items sort-alphabetically order-groups)
521 "Return a sorted copy of ITEMS.
522 ITEMS should be a `custom-group' property.
523 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
524 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
525 groups after non-groups, if nil do not order groups at all."
526 (sort (copy-sequence items)
528 (let ((typea (nth 1 a)) (typeb (nth 1 b))
529 (namea (symbol-name (nth 0 a))) (nameb (symbol-name (nth 0 b))))
530 (cond ((not order-groups)
531 ;; Since we don't care about A and B order, maybe sort.
532 (when sort-alphabetically
533 (string-lessp namea nameb)))
534 ((eq typea 'custom-group)
535 ;; If B is also a group, maybe sort. Otherwise, order A and B.
536 (if (eq typeb 'custom-group)
537 (when sort-alphabetically
538 (string-lessp namea nameb))
539 (eq order-groups 'first)))
540 ((eq typeb 'custom-group)
541 ;; Since A cannot be a group, order A and B.
542 (eq order-groups 'last))
544 ;; Since A and B cannot be groups, sort.
545 (string-lessp namea nameb)))))))
548 ;;; Custom Mode Commands.
550 (defvar custom-options nil
551 "Customization widgets in the current buffer.")
554 "Set changes in all modified options."
556 (let ((children custom-options))
557 (mapc (lambda (child)
558 (when (eq (widget-get child :custom-state) 'modified)
559 (widget-apply child :custom-set)))
562 (defun Custom-save ()
563 "Set all modified group members and save them."
565 (let ((children custom-options))
566 (mapc (lambda (child)
567 (when (memq (widget-get child :custom-state) '(modified set))
568 (widget-apply child :custom-save)))
572 (defvar custom-reset-menu
573 '(("Current" . Custom-reset-current)
574 ("Saved" . Custom-reset-saved)
575 ("Standard Settings" . Custom-reset-standard))
576 "Alist of actions for the `Reset' button.
577 The key is a string containing the name of the action, the value is a
578 lisp function taking the widget as an element which will be called
579 when the action is chosen.")
581 (defun custom-reset (event)
582 "Select item from reset menu."
583 (let* ((completion-ignore-case t)
584 (answer (widget-choose "Reset to"
590 (defun Custom-reset-current (&rest ignore)
591 "Reset all modified group members to their current value."
593 (let ((children custom-options))
594 (mapc (lambda (child)
595 (when (eq (widget-get child :custom-state) 'modified)
596 (widget-apply child :custom-reset-current)))
599 (defun Custom-reset-saved (&rest ignore)
600 "Reset all modified or set group members to their saved value."
602 (let ((children custom-options))
603 (mapc (lambda (child)
604 (when (eq (widget-get child :custom-state) 'modified)
605 (widget-apply child :custom-reset-saved)))
608 (defun Custom-reset-standard (&rest ignore)
609 "Reset all modified, set, or saved group members to their standard settings."
611 (let ((children custom-options))
612 (mapc (lambda (child)
613 (when (eq (widget-get child :custom-state) 'modified)
614 (widget-apply child :custom-reset-standard)))
618 ;;; The Customize Commands
620 (defun custom-prompt-variable (prompt-var prompt-val &optional comment)
621 "Prompt for a variable and a value and return them as a list.
622 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
623 prompt for the value. The %s escape in PROMPT-VAL is replaced with
624 the name of the variable.
626 If the variable has a `variable-interactive' property, that is used as if
627 it were the arg to `interactive' (which see) to interactively read the value.
629 If the variable has a `custom-type' property, it must be a widget and the
630 `:prompt-value' property of that widget will be used for reading the value.
632 If optional COMMENT argument is non nil, also prompt for a comment and return
633 it as the third element in the list."
634 (let* ((var (read-variable prompt-var))
635 (minibuffer-help-form '(describe-variable var))
637 (let ((prop (get var 'variable-interactive))
638 (type (get var 'custom-type))
639 (prompt (format prompt-val var)))
641 (setq type (list type)))
643 ;; Use VAR's `variable-interactive' property
644 ;; as an interactive spec for prompting.
645 (call-interactively (list 'lambda '(arg)
646 (list 'interactive prop)
649 (widget-prompt-value type
655 (eval-minibuffer prompt))))))
658 (read-string "Comment: " (get var 'variable-comment)))
663 (defun customize-set-value (var val &optional comment)
664 "Set VARIABLE to VALUE. VALUE is a Lisp object.
666 If VARIABLE has a `variable-interactive' property, that is used as if
667 it were the arg to `interactive' (which see) to interactively read the value.
669 If VARIABLE has a `custom-type' property, it must be a widget and the
670 `:prompt-value' property of that widget will be used for reading the value.
672 If given a prefix (or a COMMENT argument), also prompt for a comment."
673 (interactive (custom-prompt-variable "Set variable: "
678 (cond ((string= comment "")
679 (put var 'variable-comment nil))
681 (put var 'variable-comment comment))))
684 (defun customize-set-variable (var val &optional comment)
685 "Set the default for VARIABLE to VALUE. VALUE is a Lisp object.
687 If VARIABLE has a `custom-set' property, that is used for setting
688 VARIABLE, otherwise `set-default' is used.
690 The `customized-value' property of the VARIABLE will be set to a list
691 with a quoted VALUE as its sole list member.
693 If VARIABLE has a `variable-interactive' property, that is used as if
694 it were the arg to `interactive' (which see) to interactively read the value.
696 If VARIABLE has a `custom-type' property, it must be a widget and the
697 `:prompt-value' property of that widget will be used for reading the value.
699 If given a prefix (or a COMMENT argument), also prompt for a comment."
700 (interactive (custom-prompt-variable "Set variable: "
701 "Set customized value for %s to: "
703 (funcall (or (get var 'custom-set) 'set-default) var val)
704 (put var 'customized-value (list (custom-quote val)))
705 (cond ((string= comment "")
706 (put var 'variable-comment nil)
707 (put var 'customized-variable-comment nil))
709 (put var 'variable-comment comment)
710 (put var 'customized-variable-comment comment))))
714 (defun customize-save-variable (var val &optional comment)
715 "Set the default for VARIABLE to VALUE, and save it for future sessions.
716 If VARIABLE has a `custom-set' property, that is used for setting
717 VARIABLE, otherwise `set-default' is used.
719 The `customized-value' property of the VARIABLE will be set to a list
720 with a quoted VALUE as its sole list member.
722 If VARIABLE has a `variable-interactive' property, that is used as if
723 it were the arg to `interactive' (which see) to interactively read the value.
725 If VARIABLE has a `custom-type' property, it must be a widget and the
726 `:prompt-value' property of that widget will be used for reading the value.
728 If given a prefix (or a COMMENT argument), also prompt for a comment."
729 (interactive (custom-prompt-variable "Set and ave variable: "
730 "Set and save value for %s as: "
732 (funcall (or (get var 'custom-set) 'set-default) var val)
733 (put var 'saved-value (list (custom-quote val)))
734 (custom-push-theme 'theme-value var 'user 'set (list (custom-quote val)))
735 (cond ((string= comment "")
736 (put var 'variable-comment nil)
737 (put var 'saved-variable-comment nil))
739 (put var 'variable-comment comment)
740 (put var 'saved-variable-comment comment)))
744 (defun customize (group)
745 "Select a customization buffer which you can use to set user options.
746 User options are structured into \"groups\".
747 The default group is `Emacs'."
748 (interactive (custom-group-prompt
749 "Customize group: (default emacs) "))
750 (when (stringp group)
751 (if (string-equal "" group)
753 (setq group (intern group))))
754 (let ((name (format "*Customize Group: %s*"
755 (custom-unlispify-tag-name group))))
756 (if (get-buffer name)
757 (switch-to-buffer name)
758 (custom-buffer-create (list (list group 'custom-group))
760 (concat " for group "
761 (custom-unlispify-tag-name group))))))
764 (defalias 'customize-group 'customize)
767 (defun customize-other-window (symbol)
768 "Customize SYMBOL, which must be a customization group."
769 (interactive (custom-group-prompt
770 "Customize group: (default emacs) "))
771 (when (stringp symbol)
772 (if (string-equal "" symbol)
774 (setq symbol (intern symbol))))
775 (custom-buffer-create-other-window
776 (list (list symbol 'custom-group))
777 (format "*Customize Group: %s*" (custom-unlispify-tag-name symbol))))
780 (defalias 'customize-group-other-window 'customize-other-window)
783 (defalias 'customize-option 'customize-variable)
786 (defun customize-variable (symbol)
787 "Customize SYMBOL, which must be a user option variable."
788 (interactive (custom-variable-prompt))
789 (custom-buffer-create (list (list symbol 'custom-variable))
790 (format "*Customize Variable: %s*"
791 (custom-unlispify-tag-name symbol))))
794 (defun customize-changed-options (since-version)
795 "Customize all user option variables whose default values changed recently.
796 This means, in other words, variables defined with a `:version' keyword."
797 (interactive "sCustomize options changed, since version (default all versions): ")
798 (if (equal since-version "")
799 (setq since-version nil))
801 (mapatoms (lambda (symbol)
803 (let ((version (get symbol 'custom-version)))
805 (or (null since-version)
806 (customize-version-lessp since-version version))))
807 (push (list symbol 'custom-variable) found))))
809 (error "No user options have changed defaults %s"
811 (format "since XEmacs %s" since-version)
812 "in recent Emacs versions")))
813 (custom-buffer-create (custom-sort-items found t nil)
814 "*Customize Changed Options*")))
816 (defun customize-version-lessp (version1 version2)
817 (let (major1 major2 minor1 minor2)
818 (string-match "\\([0-9]+\\)[.]\\([0-9]+\\)" version1)
819 (setq major1 (read (match-string 1 version1)))
820 (setq minor1 (read (match-string 2 version1)))
821 (string-match "\\([0-9]+\\)[.]\\([0-9]+\\)" version2)
822 (setq major2 (read (match-string 1 version2)))
823 (setq minor2 (read (match-string 2 version2)))
824 (or (< major1 major2)
825 (and (= major1 major2)
826 (< minor1 minor2)))))
829 (defalias 'customize-variable-other-window 'customize-option-other-window)
832 (defun customize-option-other-window (symbol)
833 "Customize SYMBOL, which must be a user option variable.
834 Show the buffer in another window, but don't select it."
835 (interactive (custom-variable-prompt))
836 (custom-buffer-create-other-window
837 (list (list symbol 'custom-variable))
838 (format "*Customize Option: %s*" (custom-unlispify-tag-name symbol))))
841 (defun customize-face (&optional symbol)
842 "Customize SYMBOL, which should be a face name or nil.
843 If SYMBOL is nil, customize all faces."
844 (interactive (list (completing-read "Customize face: (default all) "
845 obarray 'find-face)))
846 (if (or (null symbol) (and (stringp symbol) (zerop (length symbol))))
847 (custom-buffer-create (custom-sort-items
848 (mapcar (lambda (symbol)
849 (list symbol 'custom-face))
853 (when (stringp symbol)
854 (setq symbol (intern symbol)))
855 (check-argument-type 'symbolp symbol)
856 (custom-buffer-create (list (list symbol 'custom-face))
857 (format "*Customize Face: %s*"
858 (custom-unlispify-tag-name symbol)))))
861 (defun customize-face-other-window (&optional symbol)
862 "Show customization buffer for FACE in other window."
863 (interactive (list (completing-read "Customize face: "
864 obarray 'find-face)))
865 (if (or (null symbol) (and (stringp symbol) (zerop (length symbol))))
868 (setq symbol (intern symbol)))
869 (check-argument-type 'symbolp symbol)
870 (custom-buffer-create-other-window
871 (list (list symbol 'custom-face))
872 (format "*Customize Face: %s*" (custom-unlispify-tag-name symbol)))))
875 (defun customize-customized ()
876 "Customize all user options set since the last save in this session."
879 (mapatoms (lambda (symbol)
880 (and (or (get symbol 'customized-face)
881 (get symbol 'customized-face-comment))
883 (push (list symbol 'custom-face) found))
884 (and (or (get symbol 'customized-value)
885 (get symbol 'customized-variable-comment))
887 (push (list symbol 'custom-variable) found))))
889 (error "No customized user options")
890 (custom-buffer-create (custom-sort-items found t nil)
891 "*Customize Customized*"))))
894 (defun customize-saved ()
895 "Customize all already saved user options."
898 (mapatoms (lambda (symbol)
899 (and (or (get symbol 'saved-face)
900 (get symbol 'saved-face-comment))
902 (push (list symbol 'custom-face) found))
903 (and (or (get symbol 'saved-value)
904 (get symbol 'saved-variable-comment))
906 (push (list symbol 'custom-variable) found))))
908 (error "No saved user options")
909 (custom-buffer-create (custom-sort-items found t nil)
910 "*Customize Saved*"))))
913 (defun customize-apropos (regexp &optional all)
914 "Customize all user options matching REGEXP.
915 If ALL is `options', include only options.
916 If ALL is `faces', include only faces.
917 If ALL is `groups', include only groups.
918 If ALL is t (interactively, with prefix arg), include options which are not
919 user-settable, as well as faces and groups."
920 (interactive "sCustomize regexp: \nP")
922 (mapatoms (lambda (symbol)
923 (when (string-match regexp (symbol-name symbol))
924 (when (and (not (memq all '(faces options)))
925 (get symbol 'custom-group))
926 (push (list symbol 'custom-group) found))
927 (when (and (not (memq all '(options groups)))
929 (push (list symbol 'custom-face) found))
930 (when (and (not (memq all '(groups faces)))
932 (or (get symbol 'saved-value)
933 (get symbol 'standard-value)
934 (if (memq all '(nil options))
935 (user-variable-p symbol)
936 (get symbol 'variable-documentation))))
937 (push (list symbol 'custom-variable) found)))))
940 (custom-buffer-create (custom-sort-items found t
941 custom-buffer-order-groups)
942 "*Customize Apropos*"))))
945 (defun customize-apropos-options (regexp &optional arg)
946 "Customize all user options matching REGEXP.
947 With prefix arg, include options which are not user-settable."
948 (interactive "sCustomize regexp: \nP")
949 (customize-apropos regexp (or arg 'options)))
952 (defun customize-apropos-faces (regexp)
953 "Customize all user faces matching REGEXP."
954 (interactive "sCustomize regexp: \n")
955 (customize-apropos regexp 'faces))
958 (defun customize-apropos-groups (regexp)
959 "Customize all user groups matching REGEXP."
960 (interactive "sCustomize regexp: \n")
961 (customize-apropos regexp 'groups))
966 (defcustom custom-buffer-style 'links
967 "*Control the presentation style for customization buffers.
968 The value should be a symbol, one of:
970 brackets: groups nest within each other with big horizontal brackets.
971 links: groups have links to subgroups."
972 :type '(radio (const :tag "brackets: Groups nest within each others" brackets)
973 (const :tag "links: Group have links to subgroups" links))
974 :group 'custom-buffer)
976 (defcustom custom-buffer-done-function 'kill-buffer
977 "*Function to be used to remove the buffer when the user is done with it.
978 Choices include `kill-buffer' (the default) and `bury-buffer'.
979 The function will be called with one argument, the buffer to remove."
980 :type '(radio (function-item kill-buffer)
981 (function-item bury-buffer)
982 (function :tag "Other" nil))
983 :group 'custom-buffer)
985 (defcustom custom-buffer-indent 3
986 "Number of spaces to indent nested groups."
988 :group 'custom-buffer)
991 (defun custom-buffer-create (options &optional name description)
992 "Create a buffer containing OPTIONS.
993 Optional NAME is the name of the buffer.
994 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
995 SYMBOL is a customization option, and WIDGET is a widget for editing
997 (unless name (setq name "*Customization*"))
998 (kill-buffer (get-buffer-create name))
999 (switch-to-buffer (get-buffer-create name))
1000 (custom-buffer-create-internal options description))
1003 (defun custom-buffer-create-other-window (options &optional name description)
1004 "Create a buffer containing OPTIONS.
1005 Optional NAME is the name of the buffer.
1006 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1007 SYMBOL is a customization option, and WIDGET is a widget for editing
1009 (unless name (setq name "*Customization*"))
1010 (kill-buffer (get-buffer-create name))
1011 (let ((window (selected-window)))
1012 (switch-to-buffer-other-window (get-buffer-create name))
1013 (custom-buffer-create-internal options description)
1014 (select-window window)))
1016 (defcustom custom-reset-button-menu t
1017 "If non-nil, only show a single reset button in customize buffers.
1018 This button will have a menu with all three reset operations."
1020 :group 'custom-buffer)
1022 (defconst custom-skip-messages 5)
1024 (defun Custom-buffer-done ()
1025 "Remove current buffer.
1026 This works by calling the function specified by
1027 `custom-buffer-done-function'."
1029 (funcall custom-buffer-done-function (current-buffer)))
1031 (defun custom-buffer-create-buttons ()
1032 (message "Creating customization buttons...")
1033 (widget-insert "\nOperate on everything in this buffer:\n ")
1034 (widget-create 'push-button
1036 :tag-glyph '("set-up" "set-down")
1038 Make your editing in this buffer take effect for this session"
1039 :action (lambda (widget &optional event)
1042 (widget-create 'push-button
1044 :tag-glyph '("save-up" "save-down")
1046 Make your editing in this buffer take effect for future Emacs sessions"
1047 :action (lambda (widget &optional event)
1049 (if custom-reset-button-menu
1052 (widget-create 'push-button
1054 :tag-glyph '("reset-up" "reset-down")
1055 :help-echo "Show a menu with reset operations"
1056 :mouse-down-action (lambda (&rest junk) t)
1057 :action (lambda (widget &optional event)
1058 (custom-reset event))))
1060 (widget-create 'push-button
1063 Reset all edited text in this buffer to reflect current values"
1064 :action 'Custom-reset-current)
1066 (widget-create 'push-button
1067 :tag "Reset to Saved"
1069 Reset all values in this buffer to their saved settings"
1070 :action 'Custom-reset-saved)
1072 (widget-create 'push-button
1073 :tag "Reset to Standard"
1075 Reset all values in this buffer to their standard settings"
1076 :action 'Custom-reset-standard))
1078 (widget-create 'push-button
1080 :tag-glyph '("done-up" "done-down")
1081 :help-echo "Remove the buffer"
1082 :action (lambda (widget &optional event)
1083 (Custom-buffer-done)))
1084 (widget-insert "\n"))
1086 (defcustom custom-novice t
1087 "If non-nil, show help message at top of customize buffers."
1089 :group 'custom-buffer)
1091 (defcustom custom-display-global-buttons 'top
1092 "If `nil' don't display the global buttons. If `top' display at the
1093 beginning of custom buffers. If `bottom', display at the end."
1094 :type '(choice (const top)
1096 (const :tag "don't" nil))
1097 :group 'custom-buffer)
1099 (defun custom-buffer-create-internal (options &optional description)
1100 (message "Creating customization buffer...")
1102 (widget-insert "This is a customization buffer")
1104 (widget-insert description))
1106 (widget-insert ".\n\
1107 Type RET or click button2 on an active field to invoke its action.
1109 (widget-create 'info-link
1111 :help-echo "Read the online help"
1112 "(XEmacs)Easy Customization")
1113 (widget-insert " for more information."))
1114 (widget-insert "\n")
1115 (if (equal custom-display-global-buttons 'top)
1116 (custom-buffer-create-buttons))
1117 (widget-insert "\n")
1118 (message "Creating customization items...")
1119 (setq custom-options
1120 (if (= (length options) 1)
1121 (mapcar (lambda (entry)
1122 (widget-create (nth 1 entry)
1123 :documentation-shown t
1124 :custom-state 'unknown
1125 :tag (custom-unlispify-tag-name
1127 :value (nth 0 entry)))
1130 (length (length options)))
1131 (mapcar (lambda (entry)
1135 (format "Creating customization items %2d%%..."
1136 (/ (* 100.0 count) length)))
1137 (widget-create (nth 1 entry)
1138 :tag (custom-unlispify-tag-name
1140 :value (nth 0 entry))
1142 (unless (eq (preceding-char) ?\n)
1143 (widget-insert "\n"))
1144 (widget-insert "\n")))
1146 (unless (eq (preceding-char) ?\n)
1147 (widget-insert "\n"))
1148 (if (equal custom-display-global-buttons 'bottom)
1149 (custom-buffer-create-buttons))
1150 (display-message 'progress
1152 "Creating customization items %2d%%...done" 100))
1153 (unless (eq custom-buffer-style 'tree)
1154 (mapc 'custom-magic-reset custom-options))
1155 (message "Creating customization setup...")
1157 (goto-char (point-min))
1158 (message "Creating customization buffer...done"))
1161 ;;; The Tree Browser.
1164 (defun customize-browse (&optional group)
1165 "Create a tree browser for the customize hierarchy."
1168 (setq group 'emacs))
1169 (let ((name "*Customize Browser*"))
1170 (kill-buffer (get-buffer-create name))
1171 (switch-to-buffer (get-buffer-create name)))
1174 Square brackets show active fields; type RET or click button2
1175 on an active field to invoke its action.
1176 Invoke [+] below to expand a group, and [-] to collapse an expanded group.\n")
1177 (if custom-browse-only-groups
1179 Invoke the [Group] button below to edit that item in another window.\n\n")
1180 (widget-insert "Invoke the ")
1181 (widget-create 'item
1184 :tag-glyph "folder")
1185 (widget-insert ", ")
1186 (widget-create 'item
1190 (widget-insert ", and ")
1191 (widget-create 'item
1194 :tag-glyph "option")
1195 (widget-insert " buttons below to edit that
1196 item in another window.\n\n"))
1197 (let ((custom-buffer-style 'tree))
1198 (widget-create 'custom-group
1200 :custom-state 'unknown
1201 :tag (custom-unlispify-tag-name group)
1204 (goto-char (point-min)))
1206 (define-widget 'custom-browse-visibility 'item
1207 "Control visibility of of items in the customize tree browser."
1209 :action 'custom-browse-visibility-action)
1211 (defun custom-browse-visibility-action (widget &rest ignore)
1212 (let ((custom-buffer-style 'tree))
1213 (custom-toggle-parent widget)))
1215 (define-widget 'custom-browse-group-tag 'push-button
1216 "Show parent in other window when activated."
1219 :action 'custom-browse-group-tag-action)
1221 (defun custom-browse-group-tag-action (widget &rest ignore)
1222 (let ((parent (widget-get widget :parent)))
1223 (customize-group-other-window (widget-value parent))))
1225 (define-widget 'custom-browse-variable-tag 'push-button
1226 "Show parent in other window when activated."
1229 :action 'custom-browse-variable-tag-action)
1231 (defun custom-browse-variable-tag-action (widget &rest ignore)
1232 (let ((parent (widget-get widget :parent)))
1233 (customize-variable-other-window (widget-value parent))))
1235 (define-widget 'custom-browse-face-tag 'push-button
1236 "Show parent in other window when activated."
1239 :action 'custom-browse-face-tag-action)
1241 (defun custom-browse-face-tag-action (widget &rest ignore)
1242 (let ((parent (widget-get widget :parent)))
1243 (customize-face-other-window (widget-value parent))))
1245 (defconst custom-browse-alist '((" " "space")
1251 (defun custom-browse-insert-prefix (prefix)
1252 "Insert PREFIX. On XEmacs convert it to line graphics."
1254 (if nil ; (string-match "XEmacs" emacs-version)
1257 (while (not (string-equal prefix ""))
1258 (let ((entry (substring prefix 0 3)))
1259 (setq prefix (substring prefix 3))
1260 (let ((overlay (make-overlay (1- (point)) (point) nil t nil))
1261 (name (nth 1 (assoc entry custom-browse-alist))))
1262 (overlay-put overlay 'end-glyph (widget-glyph-find name entry))
1263 (overlay-put overlay 'start-open t)
1264 (overlay-put overlay 'end-open t)))))
1268 ;;; Modification of Basic Widgets.
1270 ;; We add extra properties to the basic widgets needed here. This is
1271 ;; fine, as long as we are careful to stay within out own namespace.
1273 ;; We want simple widgets to be displayed by default, but complex
1274 ;; widgets to be hidden.
1276 (widget-put (get 'item 'widget-type) :custom-show t)
1277 (widget-put (get 'editable-field 'widget-type)
1278 :custom-show (lambda (widget value)
1279 ;; This used to call pp-to-string
1280 (let ((pp (widget-prettyprint-to-string value)))
1281 (cond ((string-match "\n" pp)
1286 (widget-put (get 'menu-choice 'widget-type) :custom-show t)
1288 ;;; The `custom-manual' Widget.
1290 (define-widget 'custom-manual 'info-link
1291 "Link to the manual entry for this customization option."
1294 ;;; The `custom-magic' Widget.
1296 (defgroup custom-magic-faces nil
1297 "Faces used by the magic button."
1298 :group 'custom-faces
1299 :group 'custom-buffer)
1301 (defface custom-invalid-face '((((class color))
1302 (:foreground "yellow" :background "red"))
1304 (:bold t :italic t :underline t)))
1305 "Face used when the customize item is invalid."
1306 :group 'custom-magic-faces)
1308 (defface custom-rogue-face '((((class color))
1309 (:foreground "pink" :background "black"))
1312 "Face used when the customize item is not defined for customization."
1313 :group 'custom-magic-faces)
1315 (defface custom-modified-face '((((class color))
1316 (:foreground "white" :background "blue"))
1319 "Face used when the customize item has been modified."
1320 :group 'custom-magic-faces)
1322 (defface custom-set-face '((((class color))
1323 (:foreground "blue" :background "white"))
1326 "Face used when the customize item has been set."
1327 :group 'custom-magic-faces)
1329 (defface custom-changed-face '((((class color))
1330 (:foreground "white" :background "blue"))
1333 "Face used when the customize item has been changed."
1334 :group 'custom-magic-faces)
1336 (defface custom-saved-face '((t (:underline t)))
1337 "Face used when the customize item has been saved."
1338 :group 'custom-magic-faces)
1340 (defconst custom-magic-alist '((nil "#" underline "\
1341 uninitialized, you should not see this.")
1342 (unknown "?" italic "\
1343 unknown, you should not see this.")
1344 (hidden "-" default "\
1345 hidden, invoke \"Show\" button in the previous line to show." "\
1346 group now hidden, invoke the above \"Show\" button to show contents.")
1347 (invalid "x" custom-invalid-face "\
1348 the value displayed for this %c is invalid and cannot be set.")
1349 (modified "*" custom-modified-face "\
1350 you have edited the value as text, but you have not set the %c." "\
1351 you have edited something in this group, but not set it.")
1352 (set "+" custom-set-face "\
1353 you have set this %c, but not saved it for future sessions." "\
1354 something in this group has been set, but not saved.")
1355 (changed ":" custom-changed-face "\
1356 this %c has been changed outside the customize buffer." "\
1357 something in this group has been changed outside customize.")
1358 (saved "!" custom-saved-face "\
1359 this %c has been set and saved." "\
1360 something in this group has been set and saved.")
1361 (rogue "@" custom-rogue-face "\
1362 this %c has not been changed with customize." "\
1363 something in this group is not prepared for customization.")
1364 (standard " " nil "\
1365 this %c is unchanged from its standard setting." "\
1366 visible group members are all at standard settings."))
1367 "Alist of customize option states.
1368 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1370 STATE is one of the following symbols:
1373 For internal use, should never occur.
1375 For internal use, should never occur.
1377 This item is not being displayed.
1379 This item is modified, but has an invalid form.
1381 This item is modified, and has a valid form.
1383 This item has been set but not saved.
1385 The current value of this item has been changed temporarily.
1387 This item is marked for saving.
1389 This item has no customization information.
1391 This item is unchanged from the standard setting.
1393 MAGIC is a string used to present that state.
1395 FACE is a face used to present the state.
1397 ITEM-DESC is a string describing the state for options.
1399 GROUP-DESC is a string describing the state for groups. If this is
1400 left out, ITEM-DESC will be used.
1402 The string %c in either description will be replaced with the
1403 category of the item. These are `group'. `option', and `face'.
1405 The list should be sorted most significant first.")
1407 (defcustom custom-magic-show 'long
1408 "If non-nil, show textual description of the state.
1409 If `long', show a full-line description, not just one word."
1410 :type '(choice (const :tag "no" nil)
1413 :group 'custom-buffer)
1415 (defcustom custom-magic-show-hidden '(option face)
1416 "Control whether the State button is shown for hidden items.
1417 The value should be a list with the custom categories where the State
1418 button should be visible. Possible categories are `group', `option',
1420 :type '(set (const group) (const option) (const face))
1421 :group 'custom-buffer)
1423 (defcustom custom-magic-show-button nil
1424 "Show a \"magic\" button indicating the state of each customization option."
1426 :group 'custom-buffer)
1428 (define-widget 'custom-magic 'default
1429 "Show and manipulate state for a customization option."
1431 :action 'widget-parent-action
1434 :value-create 'custom-magic-value-create
1435 :value-delete 'widget-children-value-delete)
1437 (defun widget-magic-mouse-down-action (widget &optional event)
1438 ;; Non-nil unless hidden.
1439 (not (eq (widget-get (widget-get (widget-get widget :parent) :parent)
1443 (defun custom-magic-value-create (widget)
1444 ;; Create compact status report for WIDGET.
1445 (let* ((parent (widget-get widget :parent))
1446 (state (widget-get parent :custom-state))
1447 (hidden (eq state 'hidden))
1448 (entry (assq state custom-magic-alist))
1449 (magic (nth 1 entry))
1450 (face (nth 2 entry))
1451 (category (widget-get parent :custom-category))
1452 (text (or (and (eq category 'group)
1455 (form (widget-get parent :custom-form))
1457 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text)
1458 (setq text (concat (match-string 1 text)
1459 (symbol-name category)
1460 (match-string 2 text))))
1461 (when (and custom-magic-show
1463 (memq category custom-magic-show-hidden)))
1465 (when (and (eq category 'group)
1466 (not (and (eq custom-buffer-style 'links)
1467 (> (widget-get parent :custom-level) 1))))
1468 (insert-char ?\ (* custom-buffer-indent
1469 (widget-get parent :custom-level))))
1470 (push (widget-create-child-and-convert
1472 :help-echo "Change the state of this item"
1473 :format (if hidden "%t" "%[%t%]")
1474 :button-prefix 'widget-push-button-prefix
1475 :button-suffix 'widget-push-button-suffix
1476 :mouse-down-action 'widget-magic-mouse-down-action
1478 ;;:tag-glyph (or hidden '("state-up" "state-down"))
1482 (let ((start (point)))
1483 (if (eq custom-magic-show 'long)
1485 (insert (symbol-name state)))
1486 (cond ((eq form 'lisp)
1488 ((eq form 'mismatch)
1489 (insert " (mismatch)")))
1490 (put-text-property start (point) 'face 'custom-state-face))
1492 (when (and (eq category 'group)
1493 (not (and (eq custom-buffer-style 'links)
1494 (> (widget-get parent :custom-level) 1))))
1495 (insert-char ?\ (* custom-buffer-indent
1496 (widget-get parent :custom-level))))
1497 (when custom-magic-show-button
1498 (when custom-magic-show
1499 (let ((indent (widget-get parent :indent)))
1501 (insert-char ?\ indent))))
1502 (push (widget-create-child-and-convert
1504 :mouse-down-action 'widget-magic-mouse-down-action
1508 :help-echo "Change the state"
1509 :format (if hidden "%t" "%[%t%]")
1510 :tag (if (memq form '(lisp mismatch))
1511 (concat "(" magic ")")
1512 (concat "[" magic "]")))
1515 (widget-put widget :children children)))
1517 (defun custom-magic-reset (widget)
1518 "Redraw the :custom-magic property of WIDGET."
1519 (let ((magic (widget-get widget :custom-magic)))
1520 (widget-value-set magic (widget-value magic))))
1522 ;;; The `custom' Widget.
1524 (defface custom-button-face '((t (:bold t)))
1525 "Face used for buttons in customization buffers."
1526 :group 'custom-faces)
1528 (defface custom-documentation-face nil
1529 "Face used for documentation strings in customization buffers."
1530 :group 'custom-faces)
1532 (defface custom-state-face '((((class color)
1534 (:foreground "lime green"))
1537 (:foreground "dark green"))
1539 "Face used for State descriptions in the customize buffer."
1540 :group 'custom-faces)
1542 (define-widget 'custom 'default
1543 "Customize a user option."
1545 :convert-widget 'custom-convert-widget
1546 :notify 'custom-notify
1549 :custom-state 'hidden
1550 :documentation-property 'widget-subclass-responsibility
1551 :value-create 'widget-subclass-responsibility
1552 :value-delete 'widget-children-value-delete
1553 :value-get 'widget-value-value-get
1554 :validate 'widget-children-validate
1555 :match (lambda (widget value) (symbolp value)))
1557 (defun custom-convert-widget (widget)
1558 ;; Initialize :value and :tag from :args in WIDGET.
1559 (let ((args (widget-get widget :args)))
1561 (widget-put widget :value (widget-apply widget
1562 :value-to-internal (car args)))
1563 (widget-put widget :tag (custom-unlispify-tag-name (car args)))
1564 (widget-put widget :args nil)))
1567 (defun custom-notify (widget &rest args)
1568 "Keep track of changes."
1569 (let ((state (widget-get widget :custom-state)))
1570 (unless (eq state 'modified)
1571 (unless (memq state '(nil unknown hidden))
1572 (widget-put widget :custom-state 'modified))
1573 (custom-magic-reset widget)
1574 (apply 'widget-default-notify widget args))))
1576 (defun custom-redraw (widget)
1577 "Redraw WIDGET with current settings."
1578 (let ((line (count-lines (point-min) (point)))
1579 (column (current-column))
1581 (from (marker-position (widget-get widget :from)))
1582 (to (marker-position (widget-get widget :to))))
1584 (widget-value-set widget (widget-value widget))
1585 (custom-redraw-magic widget))
1586 (when (and (>= pos from) (<= pos to))
1591 (goto-line (1+ line)))
1592 (move-to-column column))
1595 (defun custom-redraw-magic (widget)
1596 "Redraw WIDGET state with current settings."
1598 (let ((magic (widget-get widget :custom-magic)))
1600 (widget-value-set magic (widget-value magic))
1601 (when (setq widget (widget-get widget :group))
1602 (custom-group-state-update widget)))
1604 (setq widget nil)))))
1607 (defun custom-show (widget value)
1608 "Non-nil if WIDGET should be shown with VALUE by default."
1609 (let ((show (widget-get widget :custom-show)))
1615 (funcall show widget value)))))
1617 (defvar custom-load-recursion nil
1618 "Hack to avoid recursive dependencies.")
1620 (defun custom-load-symbol (symbol)
1621 "Load all dependencies for SYMBOL."
1622 (unless custom-load-recursion
1623 (let ((custom-load-recursion t)
1624 (loads (get symbol 'custom-loads))
1627 (setq load (car loads)
1629 (cond ((symbolp load)
1633 ;; Don't reload a file already loaded.
1634 ((and (boundp 'preloaded-file-list)
1635 (member load preloaded-file-list)))
1636 ((assoc load load-history))
1637 ((assoc (locate-library load) load-history))
1640 ;; Without this, we would load cus-edit recursively.
1641 ;; We are still loading it when we call this,
1642 ;; and it is not in load-history yet.
1643 (or (equal load "cus-edit")
1644 (load-library load))
1647 (defun custom-load-widget (widget)
1648 "Load all dependencies for WIDGET."
1649 (custom-load-symbol (widget-value widget)))
1651 (defun custom-unloaded-symbol-p (symbol)
1652 "Return non-nil if the dependencies of SYMBOL has not yet been loaded."
1654 (loads (get symbol 'custom-loads))
1657 (setq load (car loads)
1659 (cond ((symbolp load)
1660 (unless (featurep load)
1662 ((assoc load load-history))
1663 ((assoc (locate-library load) load-history)
1670 (defun custom-unloaded-widget-p (widget)
1671 "Return non-nil if the dependencies of WIDGET has not yet been loaded."
1672 (custom-unloaded-symbol-p (widget-value widget)))
1674 (defun custom-toggle-hide (widget)
1675 "Toggle visibility of WIDGET."
1676 (custom-load-widget widget)
1677 (let ((state (widget-get widget :custom-state)))
1678 (cond ((memq state '(invalid modified))
1679 (error "There are unset changes"))
1681 (widget-put widget :custom-state 'unknown))
1683 (widget-put widget :documentation-shown nil)
1684 (widget-put widget :custom-state 'hidden)))
1685 (custom-redraw widget)
1688 (defun custom-toggle-parent (widget &rest ignore)
1689 "Toggle visibility of parent of WIDGET."
1690 (custom-toggle-hide (widget-get widget :parent)))
1692 (defun custom-add-see-also (widget &optional prefix)
1693 "Add `See also ...' to WIDGET if there are any links.
1694 Insert PREFIX first if non-nil."
1695 (let* ((symbol (widget-get widget :value))
1696 (links (get symbol 'custom-links))
1697 (many (> (length links) 2))
1698 (buttons (widget-get widget :buttons))
1699 (indent (widget-get widget :indent)))
1702 (insert-char ?\ indent))
1705 (insert "See also ")
1707 (push (widget-create-child-and-convert widget (car links))
1709 (setq links (cdr links))
1718 (widget-put widget :buttons buttons))))
1720 (defun custom-add-parent-links (widget &optional initial-string)
1721 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
1722 The value if non-nil if any parents were found.
1723 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
1724 (let ((name (widget-value widget))
1725 (type (widget-type widget))
1726 (buttons (widget-get widget :buttons))
1729 (insert (or initial-string "Parent groups:"))
1730 (maphash (lambda (group ignore)
1731 (let ((entry (assq name (get group 'custom-group))))
1732 (when (eq (nth 1 entry) type)
1734 (push (widget-create-child-and-convert
1735 widget 'custom-group-link
1736 :tag (custom-unlispify-tag-name group)
1740 custom-group-hash-table)
1741 (widget-put widget :buttons buttons)
1744 (delete-region start (point)))
1747 ;;; The `custom-comment' Widget.
1749 ;; like the editable field
1750 (defface custom-comment-face '((((class grayscale color)
1752 (:background "gray85"))
1753 (((class grayscale color)
1755 (:background "dim gray"))
1758 "Face used for comments on variables or faces"
1759 :group 'custom-faces)
1761 ;; like font-lock-comment-face
1762 (defface custom-comment-tag-face
1763 '((((class color) (background dark)) (:foreground "gray80"))
1764 (((class color) (background light)) (:foreground "blue4"))
1765 (((class grayscale) (background light))
1766 (:foreground "DimGray" :bold t :italic t))
1767 (((class grayscale) (background dark))
1768 (:foreground "LightGray" :bold t :italic t))
1770 "Face used for variables or faces comment tags"
1771 :group 'custom-faces)
1773 (define-widget 'custom-comment 'string
1776 :help-echo "Edit a comment here"
1777 :sample-face 'custom-comment-tag-face
1778 :value-face 'custom-comment-face
1779 :value-set 'custom-comment-value-set
1780 :create 'custom-comment-create
1781 :delete 'custom-comment-delete)
1783 (defun custom-comment-create (widget)
1785 (widget-default-create widget)
1786 (widget-put widget :comment-extent
1787 (setq ext (make-extent (widget-get widget :from)
1788 (widget-get widget :to))))
1789 (set-extent-property ext 'start-open t)
1790 (when (equal (widget-get widget :value) "")
1791 (set-extent-property ext 'invisible t))
1794 (defun custom-comment-delete (widget)
1795 (widget-default-delete widget)
1796 (delete-extent (widget-get widget :comment-extent)))
1798 (defun custom-comment-value-set (widget value)
1799 (widget-default-value-set widget value)
1800 (if (equal value "")
1801 (set-extent-property (widget-get widget :comment-extent)
1803 (set-extent-property (widget-get widget :comment-extent)
1806 ;; Those functions are for the menu. WIDGET is NOT the comment widget. It's
1807 ;; the global custom one
1808 (defun custom-comment-show (widget)
1809 (set-extent-property
1810 (widget-get (widget-get widget :comment-widget) :comment-extent)
1813 (defun custom-comment-invisible-p (widget)
1815 (widget-get (widget-get widget :comment-widget) :comment-extent)
1818 ;;; The `custom-variable' Widget.
1820 (defface custom-variable-tag-face '((((class color)
1822 (:foreground "light blue" :underline t))
1825 (:foreground "blue" :underline t))
1827 "Face used for unpushable variable tags."
1828 :group 'custom-faces)
1830 (defface custom-variable-button-face '((t (:underline t :bold t)))
1831 "Face used for pushable variable tags."
1832 :group 'custom-faces)
1834 (defcustom custom-variable-default-form 'edit
1835 "Default form of displaying variable values."
1836 :type '(choice (const edit)
1838 :group 'custom-buffer)
1840 (define-widget 'custom-variable 'custom
1841 "Customize variable."
1843 :help-echo "Set or reset this variable"
1844 :documentation-property 'variable-documentation
1845 :custom-category 'option
1847 :custom-menu 'custom-variable-menu-create
1848 :custom-form nil ; defaults to value of `custom-variable-default-form'
1849 :value-create 'custom-variable-value-create
1850 :action 'custom-variable-action
1851 :custom-set 'custom-variable-set
1852 :custom-save 'custom-variable-save
1853 :custom-reset-current 'custom-redraw
1854 :custom-reset-saved 'custom-variable-reset-saved
1855 :custom-reset-standard 'custom-variable-reset-standard)
1857 (defun custom-variable-type (symbol)
1858 "Return a widget suitable for editing the value of SYMBOL.
1859 If SYMBOL has a `custom-type' property, use that.
1860 Otherwise, look up symbol in `custom-guess-type-alist'."
1861 (let* ((type (or (get symbol 'custom-type)
1862 (and (not (get symbol 'standard-value))
1863 (custom-guess-type symbol))
1865 (options (get symbol 'custom-options))
1866 (tmp (if (listp type)
1867 (copy-sequence type)
1870 (widget-put tmp :options options))
1873 (defun custom-variable-value-create (widget)
1874 "Here is where you edit the variables value."
1875 (custom-load-widget widget)
1876 (unless (widget-get widget :custom-form)
1877 (widget-put widget :custom-form custom-variable-default-form))
1878 (let* ((buttons (widget-get widget :buttons))
1879 (children (widget-get widget :children))
1880 (form (widget-get widget :custom-form))
1881 (state (widget-get widget :custom-state))
1882 (symbol (widget-get widget :value))
1883 (tag (widget-get widget :tag))
1884 (type (custom-variable-type symbol))
1885 (conv (widget-convert type))
1886 (get (or (get symbol 'custom-get) 'default-value))
1887 (prefix (widget-get widget :custom-prefix))
1888 (last (widget-get widget :custom-last))
1889 (value (if (default-boundp symbol)
1890 (funcall get symbol)
1891 (widget-get conv :value))))
1892 ;; If the widget is new, the child determine whether it is hidden.
1894 ((custom-show type value)
1895 (setq state 'unknown))
1897 (setq state 'hidden)))
1898 ;; If we don't know the state, see if we need to edit it in lisp form.
1899 (when (eq state 'unknown)
1900 (unless (widget-apply conv :match value)
1901 ;; (widget-apply (widget-convert type) :match value)
1902 (setq form 'mismatch)))
1903 ;; Now we can create the child widget.
1904 (cond ((eq custom-buffer-style 'tree)
1905 (insert prefix (if last " `--- " " |--- "))
1906 (push (widget-create-child-and-convert
1907 widget 'custom-browse-variable-tag)
1909 (insert " " tag "\n")
1910 (widget-put widget :buttons buttons))
1912 ;; Indicate hidden value.
1913 (push (widget-create-child-and-convert
1916 :sample-face 'custom-variable-tag-face
1920 (push (widget-create-child-and-convert
1922 :help-echo "Show the value of this option"
1923 :action 'custom-toggle-parent
1926 ((memq form '(lisp mismatch))
1927 ;; In lisp mode edit the saved value when possible.
1928 (let* ((value (cond ((get symbol 'saved-value)
1929 (car (get symbol 'saved-value)))
1930 ((get symbol 'standard-value)
1931 (car (get symbol 'standard-value)))
1932 ((default-boundp symbol)
1933 (custom-quote (funcall get symbol)))
1935 (custom-quote (widget-get conv :value))))))
1936 (insert (symbol-name symbol) ": ")
1937 (push (widget-create-child-and-convert
1939 :help-echo "Hide the value of this option"
1940 :action 'custom-toggle-parent
1944 (push (widget-create-child-and-convert
1946 :button-face 'custom-variable-button-face
1948 :tag (symbol-name symbol)
1954 (let* ((format (widget-get type :format))
1955 tag-format value-format)
1956 (while (not (string-match ":" format))
1957 (setq format (signal 'error (list "Bad format" format))))
1958 (setq tag-format (substring format 0 (match-end 0)))
1959 (setq value-format (substring format (match-end 0)))
1960 (push (widget-create-child-and-convert
1963 :action 'custom-tag-action
1964 :help-echo "Change value of this option"
1965 :mouse-down-action 'custom-tag-mouse-down-action
1966 :button-face 'custom-variable-button-face
1967 :sample-face 'custom-variable-tag-face
1971 (push (widget-create-child-and-convert
1973 :help-echo "Hide the value of this option"
1974 :action 'custom-toggle-parent
1977 (push (widget-create-child-and-convert
1979 :format value-format
1982 (unless (eq custom-buffer-style 'tree)
1983 (unless (eq (preceding-char) ?\n)
1984 (widget-insert "\n"))
1985 ;; Create the magic button.
1986 (let ((magic (widget-create-child-and-convert
1987 widget 'custom-magic nil)))
1988 (widget-put widget :custom-magic magic)
1989 (push magic buttons))
1990 ;; Insert documentation.
1991 ;; ### NOTE: this is ugly!!!! I need to do update the :buttons property
1992 ;; before the call to `widget-default-format-handler'. Otherwise, I
1993 ;; loose my current `buttons'. This function shouldn't be called like
1994 ;; this anyway. The doc string widget should be added like the others.
1996 (widget-put widget :buttons buttons)
1997 (widget-default-format-handler widget ?h)
1998 ;; The comment field
1999 (unless (eq state 'hidden)
2000 (let* ((comment (get symbol 'variable-comment))
2002 (widget-create-child-and-convert
2003 widget 'custom-comment
2005 :value (or comment ""))))
2006 (widget-put widget :comment-widget comment-widget)
2007 ;; Don't push it !!! Custom assumes that the first child is the
2009 (setq children (append children (list comment-widget)))))
2010 ;; Update the rest of the properties properties.
2011 (widget-put widget :custom-form form)
2012 (widget-put widget :children children)
2013 ;; Now update the state.
2014 (if (eq state 'hidden)
2015 (widget-put widget :custom-state state)
2016 (custom-variable-state-set widget))
2018 (unless (eq state 'hidden)
2019 (when (eq (widget-get widget :custom-level) 1)
2020 (custom-add-parent-links widget))
2021 (custom-add-see-also widget)))))
2023 (defun custom-tag-action (widget &rest args)
2024 "Pass :action to first child of WIDGET's parent."
2025 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
2028 (defun custom-tag-mouse-down-action (widget &rest args)
2029 "Pass :mouse-down-action to first child of WIDGET's parent."
2030 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
2031 :mouse-down-action args))
2033 (defun custom-variable-state-set (widget)
2034 "Set the state of WIDGET."
2035 (let* ((symbol (widget-value widget))
2036 (get (or (get symbol 'custom-get) 'default-value))
2037 (value (if (default-boundp symbol)
2038 (funcall get symbol)
2039 (widget-get widget :value)))
2040 (comment (get symbol 'variable-comment))
2043 (state (cond ((progn (setq tmp (get symbol 'customized-value))
2045 (get symbol 'customized-variable-comment))
2047 (if (condition-case nil
2048 (and (equal value (eval (car tmp)))
2049 (equal comment temp))
2053 ((progn (setq tmp (get symbol 'saved-value))
2054 (setq temp (get symbol 'saved-variable-comment))
2056 (if (condition-case nil
2057 (and (equal value (eval (car tmp)))
2058 (equal comment temp))
2062 ((setq tmp (get symbol 'standard-value))
2063 (if (condition-case nil
2064 (and (equal value (eval (car tmp)))
2065 (equal comment nil))
2070 (widget-put widget :custom-state state)))
2072 (defvar custom-variable-menu
2073 '(("Set for Current Session" custom-variable-set
2075 (eq (widget-get widget :custom-state) 'modified)))
2076 ("Save for Future Sessions" custom-variable-save
2078 (memq (widget-get widget :custom-state) '(modified set changed rogue))))
2079 ("Reset to Current" custom-redraw
2081 (and (default-boundp (widget-value widget))
2082 (memq (widget-get widget :custom-state) '(modified changed)))))
2083 ("Reset to Saved" custom-variable-reset-saved
2085 (and (or (get (widget-value widget) 'saved-value)
2086 (get (widget-value widget) 'saved-variable-comment))
2087 (memq (widget-get widget :custom-state)
2088 '(modified set changed rogue)))))
2089 ("Reset to Standard Settings" custom-variable-reset-standard
2091 (and (get (widget-value widget) 'standard-value)
2092 (memq (widget-get widget :custom-state)
2093 '(modified set changed saved rogue)))))
2094 ("---" ignore ignore)
2095 ("Add Comment" custom-comment-show custom-comment-invisible-p)
2096 ("---" ignore ignore)
2097 ("Don't show as Lisp expression" custom-variable-edit
2099 (eq (widget-get widget :custom-form) 'lisp)))
2100 ("Show as Lisp expression" custom-variable-edit-lisp
2102 (eq (widget-get widget :custom-form) 'edit))))
2103 "Alist of actions for the `custom-variable' widget.
2104 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2105 the menu entry, ACTION is the function to call on the widget when the
2106 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2107 widget as an argument, and returns non-nil if ACTION is valid on that
2108 widget. If FILTER is nil, ACTION is always valid.")
2110 (defun custom-variable-action (widget &optional event)
2111 "Show the menu for `custom-variable' WIDGET.
2112 Optional EVENT is the location for the menu."
2113 (if (eq (widget-get widget :custom-state) 'hidden)
2114 (custom-toggle-hide widget)
2115 (unless (eq (widget-get widget :custom-state) 'modified)
2116 (custom-variable-state-set widget))
2117 ;; Redrawing magic also depresses the state glyph.
2118 ;(custom-redraw-magic widget)
2119 (let* ((completion-ignore-case t)
2120 (answer (widget-choose (concat "Operation on "
2121 (custom-unlispify-tag-name
2122 (widget-get widget :value)))
2123 (custom-menu-filter custom-variable-menu
2127 (funcall answer widget)))))
2129 (defun custom-variable-edit (widget)
2130 "Edit value of WIDGET."
2131 (widget-put widget :custom-state 'unknown)
2132 (widget-put widget :custom-form 'edit)
2133 (custom-redraw widget))
2135 (defun custom-variable-edit-lisp (widget)
2136 "Edit the lisp representation of the value of WIDGET."
2137 (widget-put widget :custom-state 'unknown)
2138 (widget-put widget :custom-form 'lisp)
2139 (custom-redraw widget))
2141 (defun custom-variable-set (widget)
2142 "Set the current value for the variable being edited by WIDGET."
2143 (let* ((form (widget-get widget :custom-form))
2144 (state (widget-get widget :custom-state))
2145 (child (car (widget-get widget :children)))
2146 (symbol (widget-value widget))
2147 (set (or (get symbol 'custom-set) 'set-default))
2148 (comment-widget (widget-get widget :comment-widget))
2149 (comment (widget-value comment-widget))
2151 (cond ((eq state 'hidden)
2152 (error "Cannot set hidden variable"))
2153 ((setq val (widget-apply child :validate))
2154 (goto-char (widget-get val :from))
2155 (error "%s" (widget-get val :error)))
2156 ((memq form '(lisp mismatch))
2157 (when (equal comment "")
2159 ;; Make the comment invisible by hand if it's empty
2160 (set-extent-property (widget-get comment-widget :comment-extent)
2162 (funcall set symbol (eval (setq val (widget-value child))))
2163 (put symbol 'customized-value (list val))
2164 (put symbol 'variable-comment comment)
2165 (put symbol 'customized-variable-comment comment))
2167 (when (equal comment "")
2169 ;; Make the comment invisible by hand if it's empty
2170 (set-extent-property (widget-get comment-widget :comment-extent)
2172 (funcall set symbol (setq val (widget-value child)))
2173 (put symbol 'customized-value (list (custom-quote val)))
2174 (put symbol 'variable-comment comment)
2175 (put symbol 'customized-variable-comment comment)))
2176 (custom-variable-state-set widget)
2177 (custom-redraw-magic widget)))
2179 (defun custom-variable-save (widget)
2180 "Set and save the value for the variable being edited by WIDGET."
2181 (let* ((form (widget-get widget :custom-form))
2182 (state (widget-get widget :custom-state))
2183 (child (car (widget-get widget :children)))
2184 (symbol (widget-value widget))
2185 (set (or (get symbol 'custom-set) 'set-default))
2186 (comment-widget (widget-get widget :comment-widget))
2187 (comment (widget-value comment-widget))
2189 (cond ((eq state 'hidden)
2190 (error "Cannot set hidden variable"))
2191 ((setq val (widget-apply child :validate))
2192 (goto-char (widget-get val :from))
2193 (error "%s" (widget-get val :error)))
2194 ((memq form '(lisp mismatch))
2195 (when (equal comment "")
2197 ;; Make the comment invisible by hand if it's empty
2198 (set-extent-property (widget-get comment-widget :comment-extent)
2200 (put symbol 'saved-value (list (widget-value child)))
2201 (custom-push-theme 'theme-value symbol 'user
2202 'set (list (widget-value child)))
2203 (funcall set symbol (eval (widget-value child)))
2204 (put symbol 'variable-comment comment)
2205 (put symbol 'saved-variable-comment comment))
2207 (when (equal comment "")
2209 ;; Make the comment invisible by hand if it's empty
2210 (set-extent-property (widget-get comment-widget :comment-extent)
2213 'saved-value (list (custom-quote (widget-value
2215 (custom-push-theme 'theme-value symbol 'user
2216 'set (list (custom-quote (widget-value
2218 (funcall set symbol (widget-value child))
2219 (put symbol 'variable-comment comment)
2220 (put symbol 'saved-variable-comment comment)))
2221 (put symbol 'customized-value nil)
2222 (put symbol 'customized-variable-comment nil)
2224 (custom-variable-state-set widget)
2225 (custom-redraw-magic widget)))
2227 (defun custom-variable-reset-saved (widget)
2228 "Restore the saved value for the variable being edited by WIDGET."
2229 (let* ((symbol (widget-value widget))
2230 (set (or (get symbol 'custom-set) 'set-default))
2231 (comment-widget (widget-get widget :comment-widget))
2232 (value (get symbol 'saved-value))
2233 (comment (get symbol 'saved-variable-comment)))
2234 (cond ((or value comment)
2235 (put symbol 'variable-comment comment)
2237 (funcall set symbol (eval (car value)))
2240 (signal 'error (list "No saved value for variable" symbol))))
2241 (put symbol 'customized-value nil)
2242 (put symbol 'customized-variable-comment nil)
2243 (widget-put widget :custom-state 'unknown)
2244 ;; This call will possibly make the comment invisible
2245 (custom-redraw widget)))
2247 (defun custom-variable-reset-standard (widget)
2248 "Restore the standard setting for the variable being edited by WIDGET."
2249 (let* ((symbol (widget-value widget))
2250 (set (or (get symbol 'custom-set) 'set-default))
2251 (comment-widget (widget-get widget :comment-widget)))
2252 (if (get symbol 'standard-value)
2253 (funcall set symbol (eval (car (get symbol 'standard-value))))
2254 (signal 'error (list "No standard setting known for variable" symbol)))
2255 (put symbol 'variable-comment nil)
2256 (put symbol 'customized-value nil)
2257 (put symbol 'customized-variable-comment nil)
2258 (when (or (get symbol 'saved-value) (get symbol 'saved-variable-comment))
2259 (put symbol 'saved-value nil)
2260 (custom-push-theme 'theme-value symbol 'user 'reset 'standard)
2261 ;; As a special optimizations we do not (explictly)
2262 ;; save resets to standard when no theme set the value.
2263 (if (null (cdr (get symbol 'theme-value)))
2264 (put symbol 'theme-value nil))
2265 (put symbol 'saved-variable-comment nil)
2267 (widget-put widget :custom-state 'unknown)
2268 ;; This call will possibly make the comment invisible
2269 (custom-redraw widget)))
2271 ;;; The `custom-face-edit' Widget.
2273 (define-widget 'custom-face-edit 'checklist
2274 "Edit face attributes."
2278 :button-args '(:help-echo "Control whether this attribute have any effect")
2279 :args (mapcar (lambda (att)
2282 :sibling-args (widget-get (nth 1 att) :sibling-args)
2283 (list 'const :format "" :value (nth 0 att))
2285 custom-face-attributes))
2287 ;;; The `custom-display' Widget.
2289 (define-widget 'custom-display 'menu-choice
2290 "Select a display type."
2293 :help-echo "Specify frames where the face attributes should be used"
2294 :args '((const :tag "all" t)
2298 :args ((group :sibling-args (:help-echo "\
2299 Only match the specified window systems")
2300 (const :format "Type: "
2302 (checklist :inline t
2305 :sibling-args (:help-echo "\
2306 The X11 Window System")
2308 (const :format "PM "
2309 :sibling-args (:help-echo "\
2310 OS/2 Presentation Manager")
2312 (const :format "MSWindows "
2313 :sibling-args (:help-echo "\
2316 (const :format "DOS "
2317 :sibling-args (:help-echo "\
2320 (const :format "TTY%n"
2321 :sibling-args (:help-echo "\
2322 Plain text terminals")
2324 (group :sibling-args (:help-echo "\
2325 Only match the frames with the specified color support")
2326 (const :format "Class: "
2328 (checklist :inline t
2330 (const :format "Color "
2331 :sibling-args (:help-echo "\
2332 Match color frames")
2334 (const :format "Grayscale "
2335 :sibling-args (:help-echo "\
2336 Match grayscale frames")
2338 (const :format "Monochrome%n"
2339 :sibling-args (:help-echo "\
2340 Match frames with no color support")
2342 (group :sibling-args (:help-echo "\
2343 Only match frames with the specified intensity")
2345 Background brightness: "
2347 (checklist :inline t
2349 (const :format "Light "
2350 :sibling-args (:help-echo "\
2351 Match frames with light backgrounds")
2353 (const :format "Dark\n"
2354 :sibling-args (:help-echo "\
2355 Match frames with dark backgrounds")
2358 ;;; The `custom-face' Widget.
2360 (defface custom-face-tag-face '((t (:underline t)))
2361 "Face used for face tags."
2362 :group 'custom-faces)
2364 (defcustom custom-face-default-form 'selected
2365 "Default form of displaying face definition."
2366 :type '(choice (const all)
2369 :group 'custom-buffer)
2371 (define-widget 'custom-face 'custom
2373 :sample-face 'custom-face-tag-face
2374 :help-echo "Set or reset this face"
2375 :documentation-property '(lambda (face)
2376 (face-doc-string face))
2377 :value-create 'custom-face-value-create
2378 :action 'custom-face-action
2379 :custom-category 'face
2380 :custom-form nil ; defaults to value of `custom-face-default-form'
2381 :custom-set 'custom-face-set
2382 :custom-save 'custom-face-save
2383 :custom-reset-current 'custom-redraw
2384 :custom-reset-saved 'custom-face-reset-saved
2385 :custom-reset-standard 'custom-face-reset-standard
2386 :custom-menu 'custom-face-menu-create)
2388 (define-widget 'custom-face-all 'editable-list
2389 "An editable list of display specifications and attributes."
2390 :entry-format "%i %d %v"
2391 :insert-button-args '(:help-echo "Insert new display specification here")
2392 :append-button-args '(:help-echo "Append new display specification here")
2393 :delete-button-args '(:help-echo "Delete this display specification")
2394 :args '((group :format "%v" custom-display custom-face-edit)))
2396 (defconst custom-face-all (widget-convert 'custom-face-all)
2397 "Converted version of the `custom-face-all' widget.")
2399 (define-widget 'custom-display-unselected 'item
2400 "A display specification that doesn't match the selected display."
2401 :match 'custom-display-unselected-match)
2403 (defun custom-display-unselected-match (widget value)
2404 "Non-nil if VALUE is an unselected display specification."
2405 (not (face-spec-set-match-display value (selected-frame))))
2407 (define-widget 'custom-face-selected 'group
2408 "Edit the attributes of the selected display in a face specification."
2409 :args '((repeat :format ""
2411 (group custom-display-unselected sexp))
2412 (group (sexp :format "") custom-face-edit)
2417 (defconst custom-face-selected (widget-convert 'custom-face-selected)
2418 "Converted version of the `custom-face-selected' widget.")
2420 (defun custom-face-value-create (widget)
2421 "Create a list of the display specifications for WIDGET."
2422 (let ((buttons (widget-get widget :buttons))
2424 (symbol (widget-get widget :value))
2425 (tag (widget-get widget :tag))
2426 (state (widget-get widget :custom-state))
2428 (is-last (widget-get widget :custom-last))
2429 (prefix (widget-get widget :custom-prefix)))
2431 (setq tag (prin1-to-string symbol)))
2432 (cond ((eq custom-buffer-style 'tree)
2433 (insert prefix (if is-last " `--- " " |--- "))
2434 (push (widget-create-child-and-convert
2435 widget 'custom-browse-face-tag)
2437 (insert " " tag "\n")
2438 (widget-put widget :buttons buttons))
2442 (if (eq custom-buffer-style 'face)
2444 (widget-specify-sample widget begin (point))
2447 (and (not (find-face symbol))
2448 ;; XEmacs cannot display uninitialized faces.
2450 (push (widget-create-child-and-convert widget 'item
2457 (push (widget-create-child-and-convert
2459 :help-echo "Hide or show this face"
2460 :action 'custom-toggle-parent
2461 (not (eq state 'hidden)))
2465 (let ((magic (widget-create-child-and-convert
2466 widget 'custom-magic nil)))
2467 (widget-put widget :custom-magic magic)
2468 (push magic buttons))
2470 (widget-put widget :buttons buttons)
2471 ;; Insert documentation.
2472 (widget-default-format-handler widget ?h)
2473 ;; The comment field
2474 (unless (eq state 'hidden)
2475 (let* ((comment (get symbol 'face-comment))
2477 (widget-create-child-and-convert
2478 widget 'custom-comment
2480 :value (or comment ""))))
2481 (widget-put widget :comment-widget comment-widget)
2482 (push comment-widget children)))
2484 (unless (eq state 'hidden)
2485 (when (eq (widget-get widget :custom-level) 1)
2486 (custom-add-parent-links widget))
2487 (custom-add-see-also widget))
2489 (unless (eq (preceding-char) ?\n)
2491 (unless (eq state 'hidden)
2492 (message "Creating face editor...")
2493 (custom-load-widget widget)
2494 (unless (widget-get widget :custom-form)
2495 (widget-put widget :custom-form custom-face-default-form))
2496 (let* ((symbol (widget-value widget))
2497 (spec (custom-face-get-spec symbol))
2498 (form (widget-get widget :custom-form))
2499 (indent (widget-get widget :indent))
2500 (edit (widget-create-child-and-convert
2502 (cond ((and (eq form 'selected)
2503 (widget-apply custom-face-selected
2505 (when indent (insert-char ?\ indent))
2506 'custom-face-selected)
2507 ((and (not (eq form 'lisp))
2508 (widget-apply custom-face-all
2512 (when indent (insert-char ?\ indent))
2515 (custom-face-state-set widget)
2516 (push edit children)
2517 (widget-put widget :children children))
2518 (message "Creating face editor...done"))))))
2520 (defvar custom-face-menu
2521 '(("Set for Current Session" custom-face-set)
2522 ("Save for Future Sessions" custom-face-save)
2523 ("Reset to Saved" custom-face-reset-saved
2525 (or (get (widget-value widget) 'saved-face)
2526 (get (widget-value widget) 'saved-face-comment))))
2527 ("Reset to Standard Setting" custom-face-reset-standard
2529 (get (widget-value widget) 'face-defface-spec)))
2530 ("---" ignore ignore)
2531 ("Add Comment" custom-comment-show custom-comment-invisible-p)
2532 ("---" ignore ignore)
2533 ("Show all display specs" custom-face-edit-all
2535 (not (eq (widget-get widget :custom-form) 'all))))
2536 ("Just current attributes" custom-face-edit-selected
2538 (not (eq (widget-get widget :custom-form) 'selected))))
2539 ("Show as Lisp expression" custom-face-edit-lisp
2541 (not (eq (widget-get widget :custom-form) 'lisp)))))
2542 "Alist of actions for the `custom-face' widget.
2543 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2544 the menu entry, ACTION is the function to call on the widget when the
2545 menu is selected, and FILTER is a predicate which takes a `custom-face'
2546 widget as an argument, and returns non-nil if ACTION is valid on that
2547 widget. If FILTER is nil, ACTION is always valid.")
2549 (defun custom-face-edit-selected (widget)
2550 "Edit selected attributes of the value of WIDGET."
2551 (widget-put widget :custom-state 'unknown)
2552 (widget-put widget :custom-form 'selected)
2553 (custom-redraw widget))
2555 (defun custom-face-edit-all (widget)
2556 "Edit all attributes of the value of WIDGET."
2557 (widget-put widget :custom-state 'unknown)
2558 (widget-put widget :custom-form 'all)
2559 (custom-redraw widget))
2561 (defun custom-face-edit-lisp (widget)
2562 "Edit the lisp representation of the value of WIDGET."
2563 (widget-put widget :custom-state 'unknown)
2564 (widget-put widget :custom-form 'lisp)
2565 (custom-redraw widget))
2567 (defun custom-face-state-set (widget)
2568 "Set the state of WIDGET."
2569 (let* ((symbol (widget-value widget))
2570 (comment (get symbol 'face-comment))
2572 (widget-put widget :custom-state
2574 (setq tmp (get symbol 'customized-face))
2575 (setq temp (get symbol 'customized-face-comment))
2577 (if (equal temp comment)
2581 (setq tmp (get symbol 'saved-face))
2582 (setq temp (get symbol 'saved-face-comment))
2584 (if (equal temp comment)
2587 ((get symbol 'face-defface-spec)
2588 (if (equal comment nil)
2594 (defun custom-face-action (widget &optional event)
2595 "Show the menu for `custom-face' WIDGET.
2596 Optional EVENT is the location for the menu."
2597 (if (eq (widget-get widget :custom-state) 'hidden)
2598 (custom-toggle-hide widget)
2599 (let* ((completion-ignore-case t)
2600 (symbol (widget-get widget :value))
2601 (answer (widget-choose (concat "Operation on "
2602 (custom-unlispify-tag-name symbol))
2603 (custom-menu-filter custom-face-menu
2607 (funcall answer widget)))))
2609 (defun custom-face-set (widget)
2610 "Make the face attributes in WIDGET take effect."
2611 (let* ((symbol (widget-value widget))
2612 (child (car (widget-get widget :children)))
2613 (value (widget-value child))
2614 (comment-widget (widget-get widget :comment-widget))
2615 (comment (widget-value comment-widget)))
2616 (when (equal comment "")
2618 ;; Make the comment invisible by hand if it's empty
2619 (set-extent-property (widget-get comment-widget :comment-extent)
2621 (put symbol 'customized-face value)
2622 (face-spec-set symbol value nil '(custom))
2623 (put symbol 'customized-face-comment comment)
2624 (put symbol 'face-comment comment)
2625 (custom-face-state-set widget)
2626 (custom-redraw-magic widget)))
2628 (defun custom-face-save (widget)
2629 "Make the face attributes in WIDGET default."
2630 (let* ((symbol (widget-value widget))
2631 (child (car (widget-get widget :children)))
2632 (value (widget-value child))
2633 (comment-widget (widget-get widget :comment-widget))
2634 (comment (widget-value comment-widget)))
2635 (when (equal comment "")
2637 ;; Make the comment invisible by hand if it's empty
2638 (set-extent-property (widget-get comment-widget :comment-extent)
2640 (face-spec-set symbol value nil '(custom))
2641 (put symbol 'saved-face value)
2642 (custom-push-theme 'theme-face symbol 'user 'set value)
2643 (put symbol 'customized-face nil)
2644 (put symbol 'face-comment comment)
2645 (put symbol 'customized-face-comment nil)
2646 (put symbol 'saved-face-comment comment)
2648 (custom-face-state-set widget)
2649 (custom-redraw-magic widget)))
2651 (defun custom-face-reset-saved (widget)
2652 "Restore WIDGET to the face's default attributes."
2653 (let* ((symbol (widget-value widget))
2654 (child (car (widget-get widget :children)))
2655 (value (get symbol 'saved-face))
2656 (comment (get symbol 'saved-face-comment))
2657 (comment-widget (widget-get widget :comment-widget)))
2658 (unless (or value comment)
2659 (signal 'error (list "No saved value for this face" symbol)))
2660 (put symbol 'customized-face nil)
2661 (put symbol 'customized-face-comment nil)
2662 (face-spec-set symbol value nil '(custom))
2663 (put symbol 'face-comment comment)
2664 (widget-value-set child value)
2665 ;; This call manages the comment visibility
2666 (widget-value-set comment-widget (or comment ""))
2667 (custom-face-state-set widget)
2668 (custom-redraw-magic widget)))
2670 (defun custom-face-reset-standard (widget)
2671 "Restore WIDGET to the face's standard settings."
2672 (let* ((symbol (widget-value widget))
2673 (child (car (widget-get widget :children)))
2674 (value (get symbol 'face-defface-spec))
2675 (comment-widget (widget-get widget :comment-widget)))
2677 (signal 'error (list "No standard setting for this face" symbol)))
2678 (put symbol 'customized-face nil)
2679 (put symbol 'customized-face-comment nil)
2680 (when (or (get symbol 'saved-face) (get symbol 'saved-face-comment))
2681 (put symbol 'saved-face nil)
2682 (custom-push-theme 'theme-face symbol 'user 'reset 'standard)
2683 ;; Do not explictly save resets to standards without themes.
2684 (if (null (cdr (get symbol 'theme-face)))
2685 (put symbol 'theme-face nil))
2686 (put symbol 'saved-face-comment nil)
2688 (face-spec-set symbol value nil '(custom))
2689 (put symbol 'face-comment nil)
2690 (widget-value-set child value)
2691 ;; This call manages the comment visibility
2692 (widget-value-set comment-widget "")
2693 (custom-face-state-set widget)
2694 (custom-redraw-magic widget)))
2696 ;;; The `face' Widget.
2698 (define-widget 'face 'default
2699 "Select and customize a face."
2700 :convert-widget 'widget-value-convert-widget
2701 :button-prefix 'widget-push-button-prefix
2702 :button-suffix 'widget-push-button-suffix
2703 :format "%t: %[select face%] %v"
2706 :value-create 'widget-face-value-create
2707 :value-delete 'widget-face-value-delete
2708 :value-get 'widget-value-value-get
2709 :validate 'widget-children-validate
2710 :action 'widget-face-action
2711 :match (lambda (widget value) (symbolp value)))
2713 (defun widget-face-value-create (widget)
2714 ;; Create a `custom-face' child.
2715 (let* ((symbol (widget-value widget))
2716 (custom-buffer-style 'face)
2717 (child (widget-create-child-and-convert
2721 (custom-magic-reset child)
2722 (setq custom-options (cons child custom-options))
2723 (widget-put widget :children (list child))))
2725 (defun widget-face-value-delete (widget)
2726 ;; Remove the child from the options.
2727 (let ((child (car (widget-get widget :children))))
2728 (setq custom-options (delq child custom-options))
2729 (widget-children-value-delete widget)))
2731 (defvar face-history nil
2732 "History of entered face names.")
2734 (defun widget-face-action (widget &optional event)
2735 "Prompt for a face."
2736 (let ((answer (completing-read "Face: "
2737 (mapcar (lambda (face)
2738 (list (symbol-name face)))
2742 (unless (zerop (length answer))
2743 (widget-value-set widget (intern answer))
2744 (widget-apply widget :notify widget event)
2747 ;;; The `hook' Widget.
2749 (define-widget 'hook 'list
2751 :value-to-internal (lambda (widget value)
2755 :match (lambda (widget value)
2757 (widget-group-match widget value)))
2758 :convert-widget 'custom-hook-convert-widget
2761 (defun custom-hook-convert-widget (widget)
2762 ;; Handle `:custom-options'.
2763 (let* ((options (widget-get widget :options))
2764 (other `(editable-list :inline t
2765 :entry-format "%i %d%v"
2766 (function :format " %v")))
2768 (list `(checklist :inline t
2769 ,@(mapcar (lambda (entry)
2770 `(function-item ,entry))
2774 (widget-put widget :args args)
2777 ;;; The `plist' Widget.
2779 (define-widget 'plist 'list
2781 :match (lambda (widget value)
2782 (valid-plist-p value))
2783 :convert-widget 'custom-plist-convert-widget
2784 :tag "Property List")
2786 ;; #### Should handle options better.
2787 (defun custom-plist-convert-widget (widget)
2788 (let* ((options (widget-get widget :options))
2789 (other `(editable-list :inline t
2791 (symbol :format "%t: %v "
2794 (sexp :tag "Value"))))
2797 `((checklist :inline t
2798 ,@(mapcar 'custom-plist-process-option options))
2801 (widget-put widget :args args)
2804 (defun custom-plist-process-option (entry)
2806 (const :tag "Property"
2810 (sexp :tag "Value")))
2812 ;;; The `custom-group-link' Widget.
2814 (define-widget 'custom-group-link 'link
2815 "Show parent in other window when activated."
2816 :help-echo 'custom-group-link-help-echo
2817 :action 'custom-group-link-action)
2819 (defun custom-group-link-help-echo (widget)
2820 (concat "Create customization buffer for the `"
2821 (custom-unlispify-tag-name (widget-value widget))
2824 (defun custom-group-link-action (widget &rest ignore)
2825 (customize-group (widget-value widget)))
2827 ;;; The `custom-group' Widget.
2829 (defcustom custom-group-tag-faces nil
2830 ;; In XEmacs, this ought to play games with font size.
2831 "Face used for group tags.
2832 The first member is used for level 1 groups, the second for level 2,
2833 and so forth. The remaining group tags are shown with
2834 `custom-group-tag-face'."
2835 :type '(repeat face)
2836 :group 'custom-faces)
2838 (defface custom-group-tag-face-1 '((((class color)
2840 (:foreground "pink" :underline t))
2843 (:foreground "red" :underline t))
2845 "Face used for group tags.")
2847 (defface custom-group-tag-face '((((class color)
2849 (:foreground "light blue" :underline t))
2852 (:foreground "blue" :underline t))
2854 "Face used for low level group tags."
2855 :group 'custom-faces)
2857 (define-widget 'custom-group 'custom
2860 :sample-face-get 'custom-group-sample-face-get
2861 :documentation-property 'group-documentation
2862 :help-echo "Set or reset all members of this group"
2863 :value-create 'custom-group-value-create
2864 :action 'custom-group-action
2865 :custom-category 'group
2866 :custom-set 'custom-group-set
2867 :custom-save 'custom-group-save
2868 :custom-reset-current 'custom-group-reset-current
2869 :custom-reset-saved 'custom-group-reset-saved
2870 :custom-reset-standard 'custom-group-reset-standard
2871 :custom-menu 'custom-group-menu-create)
2873 (defun custom-group-sample-face-get (widget)
2874 ;; Use :sample-face.
2875 (or (nth (1- (widget-get widget :custom-level)) custom-group-tag-faces)
2876 'custom-group-tag-face))
2878 (define-widget 'custom-group-visibility 'visibility
2879 "An indicator and manipulator for hidden group contents."
2880 :create 'custom-group-visibility-create)
2882 (defun custom-group-visibility-create (widget)
2883 (let ((visible (widget-value widget)))
2885 (insert "--------")))
2886 (widget-default-create widget))
2888 (defun custom-group-members (symbol groups-only)
2889 "Return SYMBOL's custom group members.
2890 If GROUPS-ONLY non-nil, return only those members that are groups."
2891 (if (not groups-only)
2892 (get symbol 'custom-group)
2894 (dolist (entry (get symbol 'custom-group) (nreverse members))
2895 (when (eq (nth 1 entry) 'custom-group)
2896 (push entry members))))))
2898 (defun custom-group-value-create (widget)
2899 "Insert a customize group for WIDGET in the current buffer."
2900 (let* ((state (widget-get widget :custom-state))
2901 (level (widget-get widget :custom-level))
2902 ;; (indent (widget-get widget :indent))
2903 (prefix (widget-get widget :custom-prefix))
2904 (buttons (widget-get widget :buttons))
2905 (tag (widget-get widget :tag))
2906 (symbol (widget-value widget))
2907 (members (custom-group-members symbol
2908 (and (eq custom-buffer-style 'tree)
2909 custom-browse-only-groups))))
2910 (cond ((and (eq custom-buffer-style 'tree)
2912 (or members (custom-unloaded-widget-p widget)))
2913 (custom-browse-insert-prefix prefix)
2914 (push (widget-create-child-and-convert
2915 widget 'custom-browse-visibility
2916 ;; :tag-glyph "plus"
2920 ;; (widget-glyph-insert nil "-- " "horizontal")
2921 (push (widget-create-child-and-convert
2922 widget 'custom-browse-group-tag)
2924 (insert " " tag "\n")
2925 (widget-put widget :buttons buttons))
2926 ((and (eq custom-buffer-style 'tree)
2927 (zerop (length members)))
2928 (custom-browse-insert-prefix prefix)
2930 ;; (widget-glyph-insert nil "[ ]" "empty")
2931 ;; (widget-glyph-insert nil "-- " "horizontal")
2932 (push (widget-create-child-and-convert
2933 widget 'custom-browse-group-tag)
2935 (insert " " tag "\n")
2936 (widget-put widget :buttons buttons))
2937 ((eq custom-buffer-style 'tree)
2938 (custom-browse-insert-prefix prefix)
2939 (custom-load-widget widget)
2940 (if (zerop (length members))
2942 (custom-browse-insert-prefix prefix)
2944 ;; (widget-glyph-insert nil "[ ]" "empty")
2945 ;; (widget-glyph-insert nil "-- " "horizontal")
2946 (push (widget-create-child-and-convert
2947 widget 'custom-browse-group-tag)
2949 (insert " " tag "\n")
2950 (widget-put widget :buttons buttons))
2951 (push (widget-create-child-and-convert
2952 widget 'custom-browse-visibility
2953 ;; :tag-glyph "minus"
2957 ;; (widget-glyph-insert nil "-\\ " "top")
2958 (push (widget-create-child-and-convert
2959 widget 'custom-browse-group-tag)
2961 (insert " " tag "\n")
2962 (widget-put widget :buttons buttons)
2963 (message "Creating group...")
2964 (let* ((members (custom-sort-items members
2965 custom-browse-sort-alphabetically
2966 custom-browse-order-groups))
2967 (prefixes (widget-get widget :custom-prefixes))
2968 (custom-prefix-list (custom-prefix-add symbol prefixes))
2969 (extra-prefix (if (widget-get widget :custom-last)
2972 (prefix (concat prefix extra-prefix))
2975 (setq entry (car members)
2976 members (cdr members))
2977 (push (widget-create-child-and-convert
2978 widget (nth 1 entry)
2980 :tag (custom-unlispify-tag-name (nth 0 entry))
2981 :custom-prefixes custom-prefix-list
2982 :custom-level (1+ level)
2983 :custom-last (null members)
2984 :value (nth 0 entry)
2985 :custom-prefix prefix)
2987 (widget-put widget :children (reverse children)))
2988 (message "Creating group...done")))
2991 ;; Create level indicator.
2992 (unless (eq custom-buffer-style 'links)
2993 (insert-char ?\ (* custom-buffer-indent (1- level)))
2995 ;; Create link indicator.
2996 (when (eq custom-buffer-style 'links)
2998 (push (widget-create-child-and-convert
2999 widget 'custom-group-link
3001 :tag-glyph '("open-up" "open-down")
3006 (let ((begin (point)))
3008 (widget-specify-sample widget begin (point)))
3010 ;; Create visibility indicator.
3011 (unless (eq custom-buffer-style 'links)
3013 (push (widget-create-child-and-convert
3014 widget 'custom-group-visibility
3015 :help-echo "Show members of this group"
3016 :action 'custom-toggle-parent
3017 (not (eq state 'hidden)))
3020 ;; Create magic button.
3021 (let ((magic (widget-create-child-and-convert
3022 widget 'custom-magic nil)))
3023 (widget-put widget :custom-magic magic)
3024 (push magic buttons))
3026 (widget-put widget :buttons buttons)
3027 ;; Insert documentation.
3028 (if (and (eq custom-buffer-style 'links) (> level 1))
3029 (widget-put widget :documentation-indent 0))
3030 (widget-default-format-handler widget ?h))
3033 (custom-load-widget widget)
3035 (setq members (custom-group-members
3036 symbol (and (eq custom-buffer-style 'tree)
3037 custom-browse-only-groups)))
3038 ;; Add parent groups references above the group.
3039 (if t ;;; This should test that the buffer
3040 ;;; was made to display a group.
3042 (if (custom-add-parent-links widget
3043 "Go to parent group:")
3045 ;; Create level indicator.
3046 (insert-char ?\ (* custom-buffer-indent (1- level)))
3049 (let ((start (point)))
3051 (widget-specify-sample widget start (point)))
3053 ;; Create visibility indicator.
3054 (unless (eq custom-buffer-style 'links)
3056 (push (widget-create-child-and-convert
3058 :help-echo "Hide members of this group"
3059 :action 'custom-toggle-parent
3060 (not (eq state 'hidden)))
3063 ;; Create more dashes.
3064 ;; Use 76 instead of 75 to compensate for the temporary "<"
3065 ;; added by `widget-insert'.
3066 (insert-char ?- (- 76 (current-column)
3067 (* custom-buffer-indent level)))
3069 ;; Create magic button.
3070 (let ((magic (widget-create-child-and-convert
3071 widget 'custom-magic
3074 (widget-put widget :custom-magic magic)
3075 (push magic buttons))
3077 (widget-put widget :buttons buttons)
3078 ;; Insert documentation.
3079 (widget-default-format-handler widget ?h)
3081 (if nil ;;; This should test that the buffer
3082 ;;; was not made to display a group.
3084 (insert-char ?\ custom-buffer-indent)
3085 (custom-add-parent-links widget)))
3086 (custom-add-see-also widget
3087 (make-string (* custom-buffer-indent level)
3090 (message "Creating group...")
3091 (let* ((members (custom-sort-items members
3092 custom-buffer-sort-alphabetically
3093 custom-buffer-order-groups))
3094 (prefixes (widget-get widget :custom-prefixes))
3095 (custom-prefix-list (custom-prefix-add symbol prefixes))
3096 (length (length members))
3100 (widget-insert "\n")
3101 (when (zerop (% count custom-skip-messages))
3105 Creating group members... %2d%%"
3106 (/ (* 100.0 count) length))))
3109 (widget-create-child-and-convert
3110 widget (nth 1 entry)
3112 :tag (custom-unlispify-tag-name
3114 :custom-prefixes custom-prefix-list
3115 :custom-level (1+ level)
3116 :value (nth 0 entry))
3117 (unless (eq (preceding-char) ?\n)
3118 (widget-insert "\n"))))
3120 (message "Creating group magic...")
3121 (mapc 'custom-magic-reset children)
3122 (message "Creating group state...")
3123 (widget-put widget :children children)
3124 (custom-group-state-update widget)
3125 (message "Creating group... done"))
3128 (insert-char ?\ (* custom-buffer-indent (1- level)))
3129 (insert "\\- " (widget-get widget :tag) " group end ")
3130 (insert-char ?- (- 75 (current-column) (* custom-buffer-indent level)))
3133 (defvar custom-group-menu
3134 '(("Set for Current Session" custom-group-set
3136 (eq (widget-get widget :custom-state) 'modified)))
3137 ("Save for Future Sessions" custom-group-save
3139 (memq (widget-get widget :custom-state) '(modified set))))
3140 ("Reset to Current" custom-group-reset-current
3142 (memq (widget-get widget :custom-state) '(modified))))
3143 ("Reset to Saved" custom-group-reset-saved
3145 (memq (widget-get widget :custom-state) '(modified set))))
3146 ("Reset to standard setting" custom-group-reset-standard
3148 (memq (widget-get widget :custom-state) '(modified set saved)))))
3149 "Alist of actions for the `custom-group' widget.
3150 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3151 the menu entry, ACTION is the function to call on the widget when the
3152 menu is selected, and FILTER is a predicate which takes a `custom-group'
3153 widget as an argument, and returns non-nil if ACTION is valid on that
3154 widget. If FILTER is nil, ACTION is always valid.")
3156 (defun custom-group-action (widget &optional event)
3157 "Show the menu for `custom-group' WIDGET.
3158 Optional EVENT is the location for the menu."
3159 (if (eq (widget-get widget :custom-state) 'hidden)
3160 (custom-toggle-hide widget)
3161 (let* ((completion-ignore-case t)
3162 (answer (widget-choose (concat "Operation on "
3163 (custom-unlispify-tag-name
3164 (widget-get widget :value)))
3165 (custom-menu-filter custom-group-menu
3169 (funcall answer widget)))))
3171 (defun custom-group-set (widget)
3172 "Set changes in all modified group members."
3173 (let ((children (widget-get widget :children)))
3174 (mapc (lambda (child)
3175 (when (eq (widget-get child :custom-state) 'modified)
3176 (widget-apply child :custom-set)))
3179 (defun custom-group-save (widget)
3180 "Save all modified group members."
3181 (let ((children (widget-get widget :children)))
3182 (mapc (lambda (child)
3183 (when (memq (widget-get child :custom-state) '(modified set))
3184 (widget-apply child :custom-save)))
3187 (defun custom-group-reset-current (widget)
3188 "Reset all modified group members."
3189 (let ((children (widget-get widget :children)))
3190 (mapc (lambda (child)
3191 (when (eq (widget-get child :custom-state) 'modified)
3192 (widget-apply child :custom-reset-current)))
3195 (defun custom-group-reset-saved (widget)
3196 "Reset all modified or set group members."
3197 (let ((children (widget-get widget :children)))
3198 (mapc (lambda (child)
3199 (when (memq (widget-get child :custom-state) '(modified set))
3200 (widget-apply child :custom-reset-saved)))
3203 (defun custom-group-reset-standard (widget)
3204 "Reset all modified, set, or saved group members."
3205 (let ((children (widget-get widget :children)))
3206 (mapc (lambda (child)
3207 (when (memq (widget-get child :custom-state)
3208 '(modified set saved))
3209 (widget-apply child :custom-reset-standard)))
3212 (defun custom-group-state-update (widget)
3214 (unless (eq (widget-get widget :custom-state) 'hidden)
3215 (let* ((children (widget-get widget :children))
3216 (states (mapcar (lambda (child)
3217 (widget-get child :custom-state))
3219 (magics custom-magic-alist)
3222 (let ((magic (car (car magics))))
3223 (if (and (not (eq magic 'hidden))
3224 (memq magic states))
3227 (setq magics (cdr magics)))))
3228 (widget-put widget :custom-state found)))
3229 (custom-magic-reset widget))
3231 ;;; The `custom-save-all' Function.
3233 (defcustom custom-file "~/.emacs"
3234 "File used for storing customization information.
3235 If you change this from the default \"~/.emacs\" you need to
3236 explicitly load that file for the settings to take effect."
3240 (defun custom-save-delete (symbol)
3241 "Delete the call to SYMBOL form in `custom-file'.
3242 Leave point at the location of the call, or after the last expression."
3243 (let ((find-file-hooks nil)
3244 (auto-mode-alist nil))
3245 (set-buffer (find-file-noselect custom-file)))
3246 (goto-char (point-min))
3249 (let ((sexp (condition-case nil
3250 (read (current-buffer))
3251 (end-of-file (throw 'found nil)))))
3252 (when (and (listp sexp)
3253 (eq (car sexp) symbol))
3254 (delete-region (save-excursion
3258 (throw 'found nil))))))
3260 (defun custom-save-variables ()
3261 "Save all customized variables in `custom-file'."
3263 (custom-save-delete 'custom-load-themes)
3264 (custom-save-delete 'custom-reset-variables)
3265 (custom-save-delete 'custom-set-variables)
3266 (custom-save-loaded-themes)
3267 (custom-save-resets 'theme-value 'custom-reset-variables nil)
3268 (let ((standard-output (current-buffer)))
3271 (princ "(custom-set-variables")
3272 (mapatoms (lambda (symbol)
3273 (let ((spec (car-safe (get symbol 'theme-value)))
3274 (requests (get symbol 'custom-requests))
3275 (now (not (or (get symbol 'standard-value)
3276 (and (not (boundp symbol))
3277 (not (eq (get symbol 'force-value)
3279 (comment (get symbol 'saved-variable-comment)))
3280 (when (or (and spec (eq (car spec) 'user)
3281 (eq (second spec) 'set)) comment)
3285 ;; This comment stuf is in the way ####
3286 ;; Is (eq (third spec) (car saved-value)) ????
3287 ;; (prin1 (third spec))
3288 (prin1 (car (get symbol 'saved-value)))
3289 (when (or now requests comment)
3290 (princ (if now " t" " nil")))
3291 (when (or comment requests)
3299 (unless (looking-at "\n")
3302 (defvar custom-save-face-ignoring nil)
3304 (defun custom-save-face-internal (symbol)
3305 (let ((theme-spec (car-safe (get symbol 'theme-face)))
3306 (comment (get symbol 'saved-face-comment))
3307 (now (not (or (get symbol 'face-defface-spec)
3308 (and (not (find-face symbol))
3309 (not (eq (get symbol 'force-face) 'rogue)))))))
3310 (when (or (and (not (memq symbol custom-save-face-ignoring))
3311 ;; Don't print default face here.
3313 (eq (car theme-spec) 'user)
3314 (eq (second theme-spec) 'set)) comment)
3318 (prin1 (get symbol 'saved-face))
3319 (if (or comment now)
3320 (princ (if now " t" " nil")))
3326 (defun custom-save-faces ()
3327 "Save all customized faces in `custom-file'."
3329 (custom-save-delete 'custom-reset-faces)
3330 (custom-save-delete 'custom-set-faces)
3331 (custom-save-resets 'theme-face 'custom-reset-faces '(default))
3332 (let ((standard-output (current-buffer)))
3335 (princ "(custom-set-faces")
3336 ;; The default face must be first, since it affects the others.
3337 (custom-save-face-internal 'default)
3338 (let ((custom-save-face-ignoring '(default)))
3339 (mapatoms #'custom-save-face-internal))
3341 (unless (looking-at "\n")
3344 (defun custom-save-resets (property setter special)
3345 (let (started-writing ignored-special)
3346 ;; (custom-save-delete setter) Done by caller
3347 (let ((standard-output (current-buffer))
3348 (mapper `(lambda (object)
3349 (let ((spec (car-safe (get object (quote ,property)))))
3350 (when (and (not (memq object ignored-special))
3351 (eq (car spec) 'user)
3352 (eq (second spec) 'reset))
3353 ;; Do not write reset statements unless necessary.
3354 (unless started-writing
3355 (setq started-writing t)
3359 (princ (quote ,setter))
3363 (prin1 (third spec))
3365 (mapc mapper special)
3366 (setq ignored-special special)
3368 (when started-writing
3372 (defun custom-save-loaded-themes ()
3373 (let ((themes (reverse (get 'user 'theme-loads-themes)))
3374 (standard-output (current-buffer)))
3376 (unless (bolp) (princ "\n"))
3377 (princ "(custom-load-themes")
3378 (mapc (lambda (theme)
3380 (prin1 theme)) themes)
3384 (defun customize-save-customized ()
3385 "Save all user options which have been set in this session."
3387 (mapatoms (lambda (symbol)
3388 (let ((face (get symbol 'customized-face))
3389 (value (get symbol 'customized-value))
3390 (face-comment (get symbol 'customized-face-comment))
3392 (get symbol 'customized-variable-comment)))
3394 (put symbol 'saved-face face)
3395 (custom-push-theme 'theme-face symbol 'user 'set value)
3396 (put symbol 'customized-face nil))
3398 (put symbol 'saved-value value)
3399 (custom-push-theme 'theme-value symbol 'user 'set value)
3400 (put symbol 'customized-value nil))
3401 (when variable-comment
3402 (put symbol 'saved-variable-comment variable-comment)
3403 (put symbol 'customized-variable-comment nil))
3405 (put symbol 'saved-face-comment face-comment)
3406 (put symbol 'customized-face-comment nil)))))
3407 ;; We really should update all custom buffers here.
3411 (defun custom-save-all ()
3412 "Save all customizations in `custom-file'."
3413 (let ((inhibit-read-only t))
3414 (custom-save-variables)
3416 (let ((find-file-hooks nil)
3418 (with-current-buffer (find-file-noselect custom-file)
3422 ;;; The Customize Menu.
3426 (defun custom-face-menu-create (widget symbol)
3427 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
3428 (vector (custom-unlispify-menu-entry symbol)
3429 `(customize-face ',symbol)
3432 (defun custom-variable-menu-create (widget symbol)
3433 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
3434 (let ((type (get symbol 'custom-type)))
3435 (unless (listp type)
3436 (setq type (list type)))
3437 (if (and type (widget-get type :custom-menu))
3438 (widget-apply type :custom-menu symbol)
3439 (vector (custom-unlispify-menu-entry symbol)
3440 `(customize-variable ',symbol)
3443 ;; Add checkboxes to boolean variable entries.
3444 (widget-put (get 'boolean 'widget-type)
3445 :custom-menu (lambda (widget symbol)
3446 `[,(custom-unlispify-menu-entry symbol)
3447 (customize-variable ',symbol)
3449 :selected ,symbol]))
3451 ;; XEmacs can create menus dynamically.
3452 (defun custom-group-menu-create (widget symbol)
3453 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
3454 `( ,(custom-unlispify-menu-entry symbol t)
3455 :filter (lambda (&rest junk)
3456 (let ((item (custom-menu-create ',symbol)))
3462 (defun custom-menu-create (symbol)
3463 "Create menu for customization group SYMBOL.
3464 The menu is in a format applicable to `easy-menu-define'."
3465 (let* ((item (vector (custom-unlispify-menu-entry symbol)
3466 `(customize-group ',symbol)
3468 ;; Item is the entry for creating a menu buffer for SYMBOL.
3469 ;; We may nest, if the menu is not too big.
3470 (custom-load-symbol symbol)
3471 (if (< (length (get symbol 'custom-group)) widget-menu-max-size)
3472 ;; The menu is not too big.
3473 (let ((custom-prefix-list (custom-prefix-add symbol
3474 custom-prefix-list))
3475 (members (custom-sort-items (get symbol 'custom-group)
3476 custom-menu-sort-alphabetically
3477 custom-menu-order-groups)))
3479 `(,(custom-unlispify-menu-entry symbol t)
3482 ,@(mapcar (lambda (entry)
3483 (widget-apply (if (listp (nth 1 entry))
3485 (list (nth 1 entry)))
3486 :custom-menu (nth 0 entry)))
3488 ;; The menu was too big.
3492 (defun customize-menu-create (symbol &optional name)
3493 "Return a customize menu for customization group SYMBOL.
3494 If optional NAME is given, use that as the name of the menu.
3495 Otherwise the menu will be named `Customize'.
3496 The format is suitable for use with `easy-menu-define'."
3498 (setq name "Customize"))
3500 :filter (lambda (&rest junk)
3501 (cdr (custom-menu-create ',symbol)))))
3503 ;;; The Custom Mode.
3505 (defvar custom-mode-map nil
3506 "Keymap for `custom-mode'.")
3508 (unless custom-mode-map
3509 (setq custom-mode-map (make-sparse-keymap))
3510 (set-keymap-parents custom-mode-map widget-keymap)
3511 (suppress-keymap custom-mode-map)
3512 (define-key custom-mode-map " " 'scroll-up)
3513 (define-key custom-mode-map [delete] 'scroll-down)
3514 (define-key custom-mode-map "q" 'Custom-buffer-done)
3515 (define-key custom-mode-map "u" 'Custom-goto-parent)
3516 (define-key custom-mode-map "n" 'widget-forward)
3517 (define-key custom-mode-map "p" 'widget-backward))
3519 (easy-menu-define Custom-mode-menu
3521 "Menu used in customization buffers."
3523 ,(customize-menu-create 'customize)
3524 ["Set" Custom-set t]
3525 ["Save" Custom-save t]
3526 ["Reset to Current" Custom-reset-current t]
3527 ["Reset to Saved" Custom-reset-saved t]
3528 ["Reset to Standard Settings" Custom-reset-standard t]
3529 ["Info" (Info-goto-node "(xemacs)Easy Customization") t]))
3531 (defun Custom-goto-parent ()
3532 "Go to the parent group listed at the top of this buffer.
3533 If several parents are listed, go to the first of them."
3536 (goto-char (point-min))
3537 (if (search-forward "\nGo to parent group: " nil t)
3538 (let* ((button (get-char-property (point) 'button))
3539 (parent (downcase (widget-get button :tag))))
3540 (customize-group parent)))))
3542 (defcustom custom-mode-hook nil
3543 "Hook called when entering custom-mode."
3545 :group 'custom-buffer )
3547 (defun custom-state-buffer-message (widget)
3548 (if (eq (widget-get (widget-get widget :parent) :custom-state) 'modified)
3550 "To install your edits, invoke [State] and choose the Set operation")))
3552 (defun custom-mode ()
3553 "Major mode for editing customization buffers.
3555 The following commands are available:
3557 Move to next button or editable field. \\[widget-forward]
3558 Move to previous button or editable field. \\[widget-backward]
3559 \\<widget-field-keymap>\
3560 Complete content of editable text field. \\[widget-complete]
3561 \\<custom-mode-map>\
3562 Invoke button under point. \\[widget-button-press]
3563 Set all modifications. \\[Custom-set]
3564 Make all modifications default. \\[Custom-save]
3565 Reset all modified options. \\[Custom-reset-current]
3566 Reset all modified or set options. \\[Custom-reset-saved]
3567 Reset all options. \\[Custom-reset-standard]
3569 Entry to this mode calls the value of `custom-mode-hook'
3570 if that value is non-nil."
3571 (kill-all-local-variables)
3572 (setq major-mode 'custom-mode
3574 (use-local-map custom-mode-map)
3575 (easy-menu-add Custom-mode-menu)
3576 (make-local-variable 'custom-options)
3577 (make-local-variable 'widget-documentation-face)
3578 (setq widget-documentation-face 'custom-documentation-face)
3579 (make-local-variable 'widget-button-face)
3580 (setq widget-button-face 'custom-button-face)
3581 (make-local-hook 'widget-edit-functions)
3582 (add-hook 'widget-edit-functions 'custom-state-buffer-message nil t)
3583 (run-hooks 'custom-mode-hook))
3590 ;; cus-edit.el ends here