1 ;;; cus-edit.el --- Tools for customizating Emacs and Lisp packages.
3 ;; Copyright (C) 1996, 1997, 2000 Free Software Foundation, Inc.
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
6 ;; Maintainer: Hrvoje Niksic <hniksic@xemacs.org>
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.
60 ;; Huh? This looks dirty!
61 (put 'custom-define-hook 'custom-type 'hook)
62 (put 'custom-define-hook 'standard-value '(nil))
63 (custom-add-to-group 'customize 'custom-define-hook 'custom-variable)
65 ;;; Customization Groups.
68 "Customization of the One True Editor."
69 :link '(custom-manual "(XEmacs)Top"))
71 ;; Most of these groups are stolen from `finder.el',
73 "Basic text editing facilities."
76 (defgroup matching nil
77 "Various sorts of searching and matching."
80 (defgroup emulations nil
81 "Emulations of other editors."
84 (defgroup outlines nil
85 "Support for hierarchical outlining."
88 (defgroup external nil
89 "Interfacing to external utilities."
93 "Code related to the `bib' bibliography processor."
97 (defgroup programming nil
98 "Support for programming in other languages."
101 (defgroup languages nil
102 "Specialized modes for editing programming languages."
105 ;; #### This should be in cc-vars.el
107 "Support for the C language and related languages."
115 "Support for object-oriented programming."
118 (defgroup applications nil
119 "Applications written in Emacs."
122 ;; #### This should be in calendar.el
123 (defgroup calendar nil
124 "Calendar and time management support."
125 :group 'applications)
128 "Modes for electronic-mail handling."
129 :group 'applications)
132 "Support for netnews reading and posting."
133 :group 'applications)
136 "Games, jokes and amusements."
137 :group 'applications)
139 (defgroup development nil
140 "Support for further development of Emacs."
144 "Support for Emacs documentation."
147 (defgroup extensions nil
148 "Emacs Lisp language extensions."
151 (defgroup internal nil
152 "Code for Emacs internals, build process, defaults."
156 "Maintenance aids for the Emacs development group."
160 (defgroup environment nil
161 "Fitting Emacs with its environment."
165 "Communications, networking, remote access to files."
169 (defgroup hardware nil
170 "Support for interfacing with exotic hardware."
173 (defgroup terminals nil
174 "Support for terminal types."
178 "Front-ends/assistants for, or emulators of, UNIX features."
182 "Internationalization and alternate character-set support."
187 "Support editing files of data."
195 "Code related to the TeX formatter."
198 (defgroup hypermedia nil
199 "Support for links between text or other media types."
203 "Code local to your site."
206 (defgroup customize '((widgets custom-group))
207 "Customization of the Customization support."
208 :link '(custom-manual "(custom)Top")
209 :link '(url-link :tag "Development Page"
210 "http://www.dina.kvl.dk/~abraham/custom/")
214 (defgroup custom-faces nil
215 "Faces used by customize."
219 (defgroup custom-browse nil
220 "Control customize browser."
224 (defgroup custom-buffer nil
225 "Control customize buffers."
229 (defgroup custom-menu nil
230 "Control customize menus."
235 "Storage allocation and gc for GNU Emacs Lisp interpreter."
236 :tag "Storage Allocation"
240 "Undoing changes in buffers."
243 (defgroup editing-basics nil
244 "Most basic editing facilities."
247 (defgroup display nil
248 "How characters are displayed in buffers."
251 (defgroup installation nil
252 "The Emacs installation."
256 "Internal Emacs limits."
260 "Debugging Emacs itself."
264 "Mule XEmacs internationalization."
270 (defun custom-quote (sexp)
271 "Quote SEXP iff it is not self quoting."
272 (if (or (memq sexp '(t nil))
274 (eq (car-safe sexp) 'lambda)
283 (defun custom-split-regexp-maybe (regexp)
284 "If REGEXP is a string, split it to a list at `\\|'.
285 You can get the original back with from the result with:
286 (mapconcat #'identity result \"\\|\")
288 IF REGEXP is not a string, return it unchanged."
290 (split-string regexp "\\\\|")
293 (defun custom-variable-prompt ()
294 ;; Code stolen from `help.el'.
295 "Prompt for a variable, defaulting to the variable at point.
296 Return a list suitable for use in `interactive'."
297 (let ((v (variable-at-point))
298 (enable-recursive-minibuffers t)
300 (setq val (completing-read
302 (format "Customize variable: (default %s) " v)
303 "Customize variable: ")
304 obarray (lambda (symbol)
306 (or (get symbol 'custom-type)
307 (user-variable-p symbol))))
308 t nil nil (and v (symbol-name v))))
309 (list (if (equal val "")
310 (if (symbolp v) v nil)
313 ;; Here we take not only the actual groups, but the loads, too.
314 (defun custom-group-prompt (prompt)
315 "Read group from minibuffer."
316 (let ((completion-ignore-case t))
317 (list (completing-read
320 (or (get symbol 'custom-group)
321 (get symbol 'custom-loads)))
324 (defun custom-menu-filter (menu widget)
325 "Convert MENU to the form used by `widget-choose'.
326 MENU should be in the same format as `custom-variable-menu'.
327 WIDGET is the widget to apply the filter entries of MENU on."
329 current name action filter)
331 (setq current (car menu)
333 action (nth 1 current)
334 filter (nth 2 current)
336 (if (or (null filter) (funcall filter widget))
337 (push (cons name action) result)
344 (defvar custom-prefix-list nil
345 "List of prefixes that should be ignored by `custom-unlispify'")
347 (defcustom custom-unlispify-menu-entries t
348 "Display menu entries as words instead of symbols if non nil."
352 (defcustom custom-unlispify-remove-prefixes t
353 "Non-nil means remove group prefixes from option names in buffers and menus.
354 This only has an effect when `custom-unlispify-tag-names' or
355 `custom-unlispify-menu-entries' is on."
359 (defun custom-unlispify-menu-entry (symbol &optional no-suffix)
360 "Convert symbol into a menu entry."
361 (cond ((not custom-unlispify-menu-entries)
362 (symbol-name symbol))
363 ((get symbol 'custom-tag)
365 (get symbol 'custom-tag)
366 (concat (get symbol 'custom-tag) "...")))
368 (with-current-buffer (get-buffer-create " *Custom-Work*")
370 (princ symbol (current-buffer))
371 (goto-char (point-min))
372 (when (and (eq (get symbol 'custom-type) 'boolean)
373 (re-search-forward "-p\\'" nil t))
374 (replace-match "" t t)
375 (goto-char (point-min)))
376 (when custom-unlispify-remove-prefixes
377 (let ((prefixes custom-prefix-list)
380 (setq prefix (car prefixes))
381 (if (search-forward prefix (+ (point) (length prefix)) t)
384 (delete-region (point-min) (point)))
385 (setq prefixes (cdr prefixes))))))
386 (subst-char-in-region (point-min) (point-max) ?- ?\ t)
387 (capitalize-region (point-min) (point-max))
389 (goto-char (point-max))
393 (defcustom custom-unlispify-tag-names t
394 "Display tag names as words instead of symbols if non nil."
395 :group 'custom-buffer
398 (defun custom-unlispify-tag-name (symbol)
399 "Convert symbol into a menu entry."
400 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names))
401 (custom-unlispify-menu-entry symbol t)))
403 (defun custom-prefix-add (symbol prefixes)
404 ;; Add SYMBOL to list of ignored PREFIXES.
405 (cons (or (get symbol 'custom-prefix)
406 (concat (symbol-name symbol) "-"))
412 (defcustom custom-guess-name-alist
417 ("-function\\'" function)
418 ("-functions\\'" (repeat function))
419 ("-list\\'" (repeat sexp))
420 ("-alist\\'" (repeat (cons sexp sexp))))
421 "Alist of (MATCH TYPE).
423 MATCH should be a regexp matching the name of a symbol, and TYPE should
424 be a widget suitable for editing the value of that symbol. The TYPE
425 of the first entry where MATCH matches the name of the symbol will be
428 This is used for guessing the type of variables not declared with
430 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
433 (defcustom custom-guess-doc-alist
434 '(("\\`\\*?Non-nil " boolean))
435 "Alist of (MATCH TYPE).
437 MATCH should be a regexp matching a documentation string, and TYPE
438 should be a widget suitable for editing the value of a variable with
439 that documentation string. The TYPE of the first entry where MATCH
440 matches the name of the symbol will be used.
442 This is used for guessing the type of variables not declared with
444 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
447 (defun custom-guess-type (symbol)
448 "Guess a widget suitable for editing the value of SYMBOL.
449 This is done by matching SYMBOL with `custom-guess-name-alist' and
450 if that fails, the doc string with `custom-guess-doc-alist'."
451 (let ((name (symbol-name symbol))
452 (names custom-guess-name-alist)
455 (setq current (car names)
457 (when (string-match (nth 0 current) name)
458 (setq found (nth 1 current)
461 (let ((doc (documentation-property symbol 'variable-documentation))
462 (docs custom-guess-doc-alist))
465 (setq current (car docs)
467 (when (string-match (nth 0 current) doc)
468 (setq found (nth 1 current)
475 (defcustom custom-browse-sort-alphabetically nil
476 "If non-nil, sort members of each customization group alphabetically."
478 :group 'custom-browse)
480 (defcustom custom-browse-order-groups nil
481 "If non-nil, order group members within each customization group.
482 If `first', order groups before non-groups.
483 If `last', order groups after non-groups."
484 :type '(choice (const first)
486 (const :tag "none" nil))
487 :group 'custom-browse)
489 (defcustom custom-browse-only-groups nil
490 "If non-nil, show group members only within each customization group."
492 :group 'custom-browse)
494 (defcustom custom-buffer-sort-alphabetically nil
495 "If non-nil, sort members of each customization group alphabetically."
497 :group 'custom-buffer)
499 (defcustom custom-buffer-order-groups 'last
500 "If non-nil, order group members within each customization group.
501 If `first', order groups before non-groups.
502 If `last', order groups after non-groups."
503 :type '(choice (const first)
505 (const :tag "none" nil))
506 :group 'custom-buffer)
508 (defcustom custom-menu-sort-alphabetically nil
509 "If non-nil, sort members of each customization group alphabetically."
513 (defcustom custom-menu-order-groups 'first
514 "If non-nil, order group members within each customization group.
515 If `first', order groups before non-groups.
516 If `last', order groups after non-groups."
517 :type '(choice (const first)
519 (const :tag "none" nil))
522 (defun custom-sort-items (items sort-alphabetically order-groups)
523 "Return a sorted copy of ITEMS.
524 ITEMS should be a `custom-group' property.
525 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
526 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
527 groups after non-groups, if nil do not order groups at all."
528 (sort (copy-sequence items)
530 (let ((typea (nth 1 a)) (typeb (nth 1 b))
531 (namea (symbol-name (nth 0 a))) (nameb (symbol-name (nth 0 b))))
532 (cond ((not order-groups)
533 ;; Since we don't care about A and B order, maybe sort.
534 (when sort-alphabetically
535 (string-lessp namea nameb)))
536 ((eq typea 'custom-group)
537 ;; If B is also a group, maybe sort. Otherwise, order A and B.
538 (if (eq typeb 'custom-group)
539 (when sort-alphabetically
540 (string-lessp namea nameb))
541 (eq order-groups 'first)))
542 ((eq typeb 'custom-group)
543 ;; Since A cannot be a group, order A and B.
544 (eq order-groups 'last))
546 ;; Since A and B cannot be groups, sort.
547 (string-lessp namea nameb)))))))
550 ;;; Custom Mode Commands.
552 (defvar custom-options nil
553 "Customization widgets in the current buffer.")
556 "Set changes in all modified options."
558 (let ((children custom-options))
559 (mapc (lambda (child)
560 (when (eq (widget-get child :custom-state) 'modified)
561 (widget-apply child :custom-set)))
564 (defun Custom-save ()
565 "Set all modified options and save them."
567 (let ((all-children custom-options)
569 (mapc (lambda (child)
570 (when (memq (widget-get child :custom-state) '(modified set))
571 (push child children)))
573 (let ((the-children children)
575 (while (setq child (pop the-children))
576 (widget-apply child :custom-pre-save)))
578 (let ((the-children children)
580 (while (setq child (pop the-children))
581 (widget-apply child :custom-post-save)))
584 (defvar custom-reset-menu
585 '(("Current" . Custom-reset-current)
586 ("Saved" . Custom-reset-saved)
587 ("Standard Settings" . Custom-reset-standard))
588 "Alist of actions for the `Reset' button.
589 The key is a string containing the name of the action, the value is a
590 lisp function taking the widget as an element which will be called
591 when the action is chosen.")
593 (defun custom-reset (event)
594 "Select item from reset menu."
595 (let* ((completion-ignore-case t)
596 (answer (widget-choose "Reset to"
602 (defun Custom-reset-current (&rest ignore)
603 "Reset all modified group members to their current value."
605 (let ((children custom-options))
606 (mapc (lambda (child)
607 (when (eq (widget-get child :custom-state) 'modified)
608 (widget-apply child :custom-reset-current)))
611 (defun Custom-reset-saved (&rest ignore)
612 "Reset all modified or set group members to their saved value."
614 (let ((children custom-options))
615 (mapc (lambda (child)
616 (when (eq (widget-get child :custom-state) 'modified)
617 (widget-apply child :custom-reset-saved)))
620 (defun Custom-reset-standard (&rest ignore)
621 "Reset all modified, set, or saved group members to their standard settings."
623 (let ((all-children custom-options)
625 (mapc (lambda (child)
626 (when (memq (widget-get child :custom-state) '(modified set saved))
627 (push child children)))
629 (let ((the-children children)
631 (while (setq child (pop the-children))
632 (and (widget-apply child :custom-pre-reset-standard)
633 (setq must-save t))))
634 (and must-save (custom-save-all))
635 (let ((the-children children)
637 (while (setq child (pop the-children))
638 (widget-apply child :custom-post-reset-standard)))
642 ;;; The Customize Commands
644 (defun custom-prompt-variable (prompt-var prompt-val &optional comment)
645 "Prompt for a variable and a value and return them as a list.
646 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
647 prompt for the value. The %s escape in PROMPT-VAL is replaced with
648 the name of the variable.
650 If the variable has a `variable-interactive' property, that is used as if
651 it were the arg to `interactive' (which see) to interactively read the value.
653 If the variable has a `custom-type' property, it must be a widget and the
654 `:prompt-value' property of that widget will be used for reading the value.
656 If optional COMMENT argument is non nil, also prompt for a comment and return
657 it as the third element in the list."
658 (let* ((var (read-variable prompt-var))
659 (minibuffer-help-form '(describe-variable var))
661 (let ((prop (get var 'variable-interactive))
662 (type (get var 'custom-type))
663 (prompt (format prompt-val var)))
665 (setq type (list type)))
667 ;; Use VAR's `variable-interactive' property
668 ;; as an interactive spec for prompting.
669 (call-interactively (list 'lambda '(arg)
670 (list 'interactive prop)
673 (widget-prompt-value type
679 (eval-minibuffer prompt))))))
682 (read-string "Comment: " (get var 'variable-comment)))
687 (defun customize-set-value (var val &optional comment)
688 "Set VARIABLE to VALUE. VALUE is a Lisp object.
690 If VARIABLE has a `variable-interactive' property, that is used as if
691 it were the arg to `interactive' (which see) to interactively read the value.
693 If VARIABLE has a `custom-type' property, it must be a widget and the
694 `:prompt-value' property of that widget will be used for reading the value.
696 If given a prefix (or a COMMENT argument), also prompt for a comment."
697 (interactive (custom-prompt-variable "Set variable: "
702 (cond ((string= comment "")
703 (put var 'variable-comment nil))
705 (put var 'variable-comment comment))))
708 (defun customize-set-variable (variable value &optional comment)
709 "Set the default for VARIABLE to VALUE. VALUE is any Lisp object.
711 If VARIABLE has a `custom-set' property, that is used for setting
712 VARIABLE, otherwise `set-default' is used.
714 The `customized-value' property of the VARIABLE will be set to a list
715 with a quoted VALUE as its sole list member.
717 If VARIABLE has a `variable-interactive' property, that is used as if
718 it were the arg to `interactive' (which see) to interactively read the value.
720 If VARIABLE has a `custom-type' property, it must be a widget and the
721 `:prompt-value' property of that widget will be used for reading the value.
723 If given a prefix (or a COMMENT argument), also prompt for a comment."
724 (interactive (custom-prompt-variable "Set variable: "
725 "Set customized value for %s to: "
727 (funcall (or (get variable 'custom-set) 'set-default) variable value)
728 (put variable 'customized-value (list (custom-quote value)))
729 (cond ((string= comment "")
730 (put variable 'variable-comment nil)
731 (put variable 'customized-variable-comment nil))
733 (put variable 'variable-comment comment)
734 (put variable 'customized-variable-comment comment))))
738 (defun customize-save-variable (variable value &optional comment)
739 "Set the default for VARIABLE to VALUE, and save it for future sessions.
740 If VARIABLE has a `custom-set' property, that is used for setting
741 VARIABLE, otherwise `set-default' is used.
743 The `customized-value' property of the VARIABLE will be set to a list
744 with a quoted VALUE as its sole list member.
746 If VARIABLE has a `variable-interactive' property, that is used as if
747 it were the arg to `interactive' (which see) to interactively read the value.
749 If VARIABLE has a `custom-type' property, it must be a widget and the
750 `:prompt-value' property of that widget will be used for reading the value.
752 If given a prefix (or a COMMENT argument), also prompt for a comment."
753 (interactive (custom-prompt-variable "Set and save variable: "
754 "Set and save value for %s as: "
756 (funcall (or (get variable 'custom-set) 'set-default) variable value)
757 (put variable 'saved-value (list (custom-quote value)))
758 (custom-push-theme 'theme-value variable 'user 'set (list (custom-quote value)))
759 (cond ((string= comment "")
760 (put variable 'variable-comment nil)
761 (put variable 'saved-variable-comment nil))
763 (put variable 'variable-comment comment)
764 (put variable 'saved-variable-comment comment)))
768 (defun customize (group)
769 "Select a customization buffer which you can use to set user options.
770 User options are structured into \"groups\".
771 The default group is `Emacs'."
772 (interactive (custom-group-prompt
773 "Customize group: (default emacs) "))
774 (when (stringp group)
775 (if (string-equal "" group)
777 (setq group (intern group))))
778 (let ((name (format "*Customize Group: %s*"
779 (custom-unlispify-tag-name group))))
780 (if (get-buffer name)
781 (switch-to-buffer name)
782 (custom-buffer-create (list (list group 'custom-group))
784 (concat " for group "
785 (custom-unlispify-tag-name group))))))
788 (defalias 'customize-group 'customize)
791 (defun customize-other-window (symbol)
792 "Customize SYMBOL, which must be a customization group."
793 (interactive (custom-group-prompt
794 "Customize group: (default emacs) "))
795 (when (stringp symbol)
796 (if (string-equal "" symbol)
798 (setq symbol (intern symbol))))
799 (custom-buffer-create-other-window
800 (list (list symbol 'custom-group))
801 (format "*Customize Group: %s*" (custom-unlispify-tag-name symbol))))
804 (defalias 'customize-group-other-window 'customize-other-window)
807 (defalias 'customize-option 'customize-variable)
810 (defun customize-variable (symbol)
811 "Customize SYMBOL, which must be a user option variable."
812 (interactive (custom-variable-prompt))
813 (custom-buffer-create (list (list symbol 'custom-variable))
814 (format "*Customize Variable: %s*"
815 (custom-unlispify-tag-name symbol))))
818 (defun customize-changed-options (since-version)
819 "Customize all user option variables whose default values changed recently.
820 This means, in other words, variables defined with a `:version' keyword."
821 (interactive "sCustomize options changed, since version (default all versions): ")
822 (if (equal since-version "")
823 (setq since-version nil))
825 (mapatoms (lambda (symbol)
827 (let ((version (get symbol 'custom-version)))
829 (or (null since-version)
830 (customize-version-lessp since-version version))))
831 (push (list symbol 'custom-variable) found))))
833 (error "No user options have changed defaults %s"
835 (format "since XEmacs %s" since-version)
836 "in recent Emacs versions")))
837 (custom-buffer-create (custom-sort-items found t nil)
838 "*Customize Changed Options*")))
840 (defun customize-version-lessp (version1 version2)
841 (let (major1 major2 minor1 minor2)
842 (string-match "\\([0-9]+\\)[.]\\([0-9]+\\)" version1)
843 (setq major1 (read (match-string 1 version1)))
844 (setq minor1 (read (match-string 2 version1)))
845 (string-match "\\([0-9]+\\)[.]\\([0-9]+\\)" version2)
846 (setq major2 (read (match-string 1 version2)))
847 (setq minor2 (read (match-string 2 version2)))
848 (or (< major1 major2)
849 (and (= major1 major2)
850 (< minor1 minor2)))))
853 (defalias 'customize-variable-other-window 'customize-option-other-window)
856 (defun customize-option-other-window (symbol)
857 "Customize SYMBOL, which must be a user option variable.
858 Show the buffer in another window, but don't select it."
859 (interactive (custom-variable-prompt))
860 (custom-buffer-create-other-window
861 (list (list symbol 'custom-variable))
862 (format "*Customize Option: %s*" (custom-unlispify-tag-name symbol))))
865 (defun customize-face (&optional symbol)
866 "Customize SYMBOL, which should be a face name or nil.
867 If SYMBOL is nil, customize all faces."
868 (interactive (list (completing-read "Customize face: (default all) "
869 obarray 'find-face)))
870 (if (or (null symbol) (and (stringp symbol) (zerop (length symbol))))
871 (custom-buffer-create (custom-sort-items
872 (mapcar (lambda (symbol)
873 (list symbol 'custom-face))
877 (when (stringp symbol)
878 (setq symbol (intern symbol)))
879 (check-argument-type 'symbolp symbol)
880 (custom-buffer-create (list (list symbol 'custom-face))
881 (format "*Customize Face: %s*"
882 (custom-unlispify-tag-name symbol)))))
885 (defun customize-face-other-window (&optional symbol)
886 "Show customization buffer for FACE in other window."
887 (interactive (list (completing-read "Customize face: "
888 obarray 'find-face)))
889 (if (or (null symbol) (and (stringp symbol) (zerop (length symbol))))
892 (setq symbol (intern symbol)))
893 (check-argument-type 'symbolp symbol)
894 (custom-buffer-create-other-window
895 (list (list symbol 'custom-face))
896 (format "*Customize Face: %s*" (custom-unlispify-tag-name symbol)))))
899 (defun customize-customized ()
900 "Customize all user options set since the last save in this session."
903 (mapatoms (lambda (symbol)
904 (and (or (get symbol 'customized-face)
905 (get symbol 'customized-face-comment))
907 (push (list symbol 'custom-face) found))
908 (and (or (get symbol 'customized-value)
909 (get symbol 'customized-variable-comment))
911 (push (list symbol 'custom-variable) found))))
913 (error "No customized user options")
914 (custom-buffer-create (custom-sort-items found t nil)
915 "*Customize Customized*"))))
918 (defun customize-saved ()
919 "Customize all already saved user options."
922 (mapatoms (lambda (symbol)
923 (and (or (get symbol 'saved-face)
924 (get symbol 'saved-face-comment))
926 (push (list symbol 'custom-face) found))
927 (and (or (get symbol 'saved-value)
928 (get symbol 'saved-variable-comment))
930 (push (list symbol 'custom-variable) found))))
932 (error "No saved user options")
933 (custom-buffer-create (custom-sort-items found t nil)
934 "*Customize Saved*"))))
937 (defun customize-apropos (regexp &optional all)
938 "Customize all user options matching REGEXP.
939 If ALL is `options', include only options.
940 If ALL is `faces', include only faces.
941 If ALL is `groups', include only groups.
942 If ALL is t (interactively, with prefix arg), include options which are not
943 user-settable, as well as faces and groups."
944 (interactive "sCustomize regexp: \nP")
946 (mapatoms (lambda (symbol)
947 (when (string-match regexp (symbol-name symbol))
948 (when (and (not (memq all '(faces options)))
949 (get symbol 'custom-group))
950 (push (list symbol 'custom-group) found))
951 (when (and (not (memq all '(options groups)))
953 (push (list symbol 'custom-face) found))
954 (when (and (not (memq all '(groups faces)))
956 (or (get symbol 'saved-value)
957 (get symbol 'standard-value)
958 (if (memq all '(nil options))
959 (user-variable-p symbol)
960 (get symbol 'variable-documentation))))
961 (push (list symbol 'custom-variable) found)))))
964 (custom-buffer-create (custom-sort-items found t
965 custom-buffer-order-groups)
966 "*Customize Apropos*"))))
969 (defun customize-apropos-options (regexp &optional arg)
970 "Customize all user options matching REGEXP.
971 With prefix arg, include options which are not user-settable."
972 (interactive "sCustomize regexp: \nP")
973 (customize-apropos regexp (or arg 'options)))
976 (defun customize-apropos-faces (regexp)
977 "Customize all user faces matching REGEXP."
978 (interactive "sCustomize regexp: \n")
979 (customize-apropos regexp 'faces))
982 (defun customize-apropos-groups (regexp)
983 "Customize all user groups matching REGEXP."
984 (interactive "sCustomize regexp: \n")
985 (customize-apropos regexp 'groups))
990 (defcustom custom-buffer-style 'links
991 "*Control the presentation style for customization buffers.
992 The value should be a symbol, one of:
994 brackets: groups nest within each other with big horizontal brackets.
995 links: groups have links to subgroups."
996 :type '(radio (const :tag "brackets: Groups nest within each others" brackets)
997 (const :tag "links: Group have links to subgroups" links))
998 :group 'custom-buffer)
1000 (defcustom custom-buffer-done-function 'kill-buffer
1001 "*Function to be used to remove the buffer when the user is done with it.
1002 Choices include `kill-buffer' (the default) and `bury-buffer'.
1003 The function will be called with one argument, the buffer to remove."
1004 :type '(radio (function-item kill-buffer)
1005 (function-item bury-buffer)
1006 (function :tag "Other" nil))
1007 :group 'custom-buffer)
1009 (defcustom custom-buffer-indent 3
1010 "Number of spaces to indent nested groups."
1012 :group 'custom-buffer)
1015 (defun custom-buffer-create (options &optional name description)
1016 "Create a buffer containing OPTIONS.
1017 Optional NAME is the name of the buffer.
1018 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1019 SYMBOL is a customization option, and WIDGET is a widget for editing
1021 (unless name (setq name "*Customization*"))
1022 (kill-buffer (get-buffer-create name))
1023 (switch-to-buffer (get-buffer-create name))
1024 (custom-buffer-create-internal options description))
1027 (defun custom-buffer-create-other-window (options &optional name description)
1028 "Create a buffer containing OPTIONS.
1029 Optional NAME is the name of the buffer.
1030 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1031 SYMBOL is a customization option, and WIDGET is a widget for editing
1033 (unless name (setq name "*Customization*"))
1034 (kill-buffer (get-buffer-create name))
1035 (let ((window (selected-window)))
1036 (switch-to-buffer-other-window (get-buffer-create name))
1037 (custom-buffer-create-internal options description)
1038 (select-window window)))
1040 (defcustom custom-reset-button-menu t
1041 "If non-nil, only show a single reset button in customize buffers.
1042 This button will have a menu with all three reset operations."
1044 :group 'custom-buffer)
1046 (defconst custom-skip-messages 5)
1048 (defun Custom-buffer-done ()
1049 "Remove current buffer.
1050 This works by calling the function specified by
1051 `custom-buffer-done-function'."
1053 (funcall custom-buffer-done-function (current-buffer)))
1055 (defun custom-buffer-create-buttons ()
1056 (message "Creating customization buttons...")
1057 (widget-insert "\nOperate on everything in this buffer:\n ")
1058 (widget-create 'push-button
1061 Make your editing in this buffer take effect for this session"
1062 :action (lambda (widget &optional event)
1065 (widget-create 'push-button
1068 Make your editing in this buffer take effect for future Emacs sessions"
1069 :action (lambda (widget &optional event)
1071 (if custom-reset-button-menu
1074 (widget-create 'push-button
1076 :tag-glyph '("reset-up" "reset-down")
1077 :help-echo "Show a menu with reset operations"
1078 :mouse-down-action (lambda (&rest junk) t)
1079 :action (lambda (widget &optional event)
1080 (custom-reset event))))
1082 (widget-create 'push-button
1085 Reset all edited text in this buffer to reflect current values"
1086 :action 'Custom-reset-current)
1088 (widget-create 'push-button
1089 :tag "Reset to Saved"
1091 Reset all values in this buffer to their saved settings"
1092 :action 'Custom-reset-saved)
1094 (widget-create 'push-button
1095 :tag "Reset to Standard"
1097 Reset all values in this buffer to their standard settings"
1098 :action 'Custom-reset-standard))
1100 (widget-create 'push-button
1102 :help-echo "Remove the buffer"
1103 :action (lambda (widget &optional event)
1104 (Custom-buffer-done)))
1105 (widget-insert "\n"))
1107 (defcustom custom-novice t
1108 "If non-nil, show help message at top of customize buffers."
1110 :group 'custom-buffer)
1112 (defcustom custom-display-global-buttons 'top
1113 "If `nil' don't display the global buttons. If `top' display at the
1114 beginning of custom buffers. If `bottom', display at the end."
1115 :type '(choice (const top)
1117 (const :tag "don't" nil))
1118 :group 'custom-buffer)
1120 (defun custom-buffer-create-internal (options &optional description)
1121 (message "Creating customization buffer...")
1123 (widget-insert "This is a customization buffer")
1125 (widget-insert description))
1127 (widget-insert ".\n\
1128 Type RET or click button2 on an active field to invoke its action.
1130 (widget-create 'info-link
1132 :help-echo "Read the online help"
1133 "(XEmacs)Easy Customization")
1134 (widget-insert " for more information."))
1135 (widget-insert "\n")
1136 (if (equal custom-display-global-buttons 'top)
1137 (custom-buffer-create-buttons))
1138 (widget-insert "\n")
1139 (message "Creating customization items...")
1140 (setq custom-options
1141 (if (= (length options) 1)
1142 (mapcar (lambda (entry)
1143 (widget-create (nth 1 entry)
1144 :documentation-shown t
1145 :custom-state 'unknown
1146 :tag (custom-unlispify-tag-name
1148 :value (nth 0 entry)))
1151 (length (length options)))
1152 (mapcar (lambda (entry)
1156 (format "Creating customization items %2d%%..."
1157 (/ (* 100.0 count) length)))
1158 (widget-create (nth 1 entry)
1159 :tag (custom-unlispify-tag-name
1161 :value (nth 0 entry))
1163 (unless (eq (preceding-char) ?\n)
1164 (widget-insert "\n"))
1165 (widget-insert "\n")))
1167 (unless (eq (preceding-char) ?\n)
1168 (widget-insert "\n"))
1169 (if (equal custom-display-global-buttons 'bottom)
1170 (custom-buffer-create-buttons))
1171 (display-message 'progress
1173 "Creating customization items %2d%%...done" 100))
1174 (unless (eq custom-buffer-style 'tree)
1175 (mapc 'custom-magic-reset custom-options))
1176 (message "Creating customization setup...")
1178 (goto-char (point-min))
1179 (message "Creating customization buffer...done"))
1182 ;;; The Tree Browser.
1185 (defun customize-browse (&optional group)
1186 "Create a tree browser for the customize hierarchy."
1189 (setq group 'emacs))
1190 (let ((name "*Customize Browser*"))
1191 (kill-buffer (get-buffer-create name))
1192 (switch-to-buffer (get-buffer-create name)))
1195 Square brackets show active fields; type RET or click button2
1196 on an active field to invoke its action.
1197 Invoke [+] below to expand a group, and [-] to collapse an expanded group.\n")
1198 (if custom-browse-only-groups
1200 Invoke the [Group] button below to edit that item in another window.\n\n")
1201 (widget-insert "Invoke the ")
1202 (widget-create 'item
1205 :tag-glyph "folder")
1206 (widget-insert ", ")
1207 (widget-create 'item
1211 (widget-insert ", and ")
1212 (widget-create 'item
1215 :tag-glyph "option")
1216 (widget-insert " buttons below to edit that
1217 item in another window.\n\n"))
1218 (let ((custom-buffer-style 'tree))
1219 (widget-create 'custom-group
1221 :custom-state 'unknown
1222 :tag (custom-unlispify-tag-name group)
1225 (goto-char (point-min)))
1227 (define-widget 'custom-browse-visibility 'item
1228 "Control visibility of of items in the customize tree browser."
1230 :action 'custom-browse-visibility-action)
1232 (defun custom-browse-visibility-action (widget &rest ignore)
1233 (let ((custom-buffer-style 'tree))
1234 (custom-toggle-parent widget)))
1236 (define-widget 'custom-browse-group-tag 'push-button
1237 "Show parent in other window when activated."
1240 :action 'custom-browse-group-tag-action)
1242 (defun custom-browse-group-tag-action (widget &rest ignore)
1243 (let ((parent (widget-get widget :parent)))
1244 (customize-group-other-window (widget-value parent))))
1246 (define-widget 'custom-browse-variable-tag 'push-button
1247 "Show parent in other window when activated."
1250 :action 'custom-browse-variable-tag-action)
1252 (defun custom-browse-variable-tag-action (widget &rest ignore)
1253 (let ((parent (widget-get widget :parent)))
1254 (customize-variable-other-window (widget-value parent))))
1256 (define-widget 'custom-browse-face-tag 'push-button
1257 "Show parent in other window when activated."
1260 :action 'custom-browse-face-tag-action)
1262 (defun custom-browse-face-tag-action (widget &rest ignore)
1263 (let ((parent (widget-get widget :parent)))
1264 (customize-face-other-window (widget-value parent))))
1266 (defconst custom-browse-alist '((" " "space")
1272 (defun custom-browse-insert-prefix (prefix)
1273 "Insert PREFIX. On XEmacs convert it to line graphics."
1275 (if nil ; (string-match "XEmacs" emacs-version)
1278 (while (not (string-equal prefix ""))
1279 (let ((entry (substring prefix 0 3)))
1280 (setq prefix (substring prefix 3))
1281 (let ((overlay (make-overlay (1- (point)) (point) nil t nil))
1282 (name (nth 1 (assoc entry custom-browse-alist))))
1283 (overlay-put overlay 'end-glyph (widget-glyph-find name entry))
1284 (overlay-put overlay 'start-open t)
1285 (overlay-put overlay 'end-open t)))))
1289 ;;; Modification of Basic Widgets.
1291 ;; We add extra properties to the basic widgets needed here. This is
1292 ;; fine, as long as we are careful to stay within out own namespace.
1294 ;; We want simple widgets to be displayed by default, but complex
1295 ;; widgets to be hidden.
1297 (widget-put (get 'item 'widget-type) :custom-show t)
1298 (widget-put (get 'editable-field 'widget-type)
1299 :custom-show (lambda (widget value)
1300 ;; This used to call pp-to-string
1301 (let ((pp (widget-prettyprint-to-string value)))
1302 (cond ((string-match "\n" pp)
1307 (widget-put (get 'menu-choice 'widget-type) :custom-show t)
1309 ;;; The `custom-manual' Widget.
1311 (define-widget 'custom-manual 'info-link
1312 "Link to the manual entry for this customization option."
1315 ;;; The `custom-magic' Widget.
1317 (defgroup custom-magic-faces nil
1318 "Faces used by the magic button."
1319 :group 'custom-faces
1320 :group 'custom-buffer)
1322 (defface custom-invalid-face '((((class color))
1323 (:foreground "yellow" :background "red"))
1325 (:bold t :italic t :underline t)))
1326 "Face used when the customize item is invalid."
1327 :group 'custom-magic-faces)
1329 (defface custom-rogue-face '((((class color))
1330 (:foreground "pink" :background "black"))
1333 "Face used when the customize item is not defined for customization."
1334 :group 'custom-magic-faces)
1336 (defface custom-modified-face '((((class color))
1337 (:foreground "white" :background "blue"))
1340 "Face used when the customize item has been modified."
1341 :group 'custom-magic-faces)
1343 (defface custom-set-face '((((class color))
1344 (:foreground "blue" :background "white"))
1347 "Face used when the customize item has been set."
1348 :group 'custom-magic-faces)
1350 (defface custom-changed-face '((((class color))
1351 (:foreground "white" :background "blue"))
1354 "Face used when the customize item has been changed."
1355 :group 'custom-magic-faces)
1357 (defface custom-saved-face '((t (:underline t)))
1358 "Face used when the customize item has been saved."
1359 :group 'custom-magic-faces)
1361 (defconst custom-magic-alist '((nil "#" underline "\
1362 uninitialized, you should not see this.")
1363 (unknown "?" italic "\
1364 unknown, you should not see this.")
1365 (hidden "-" default "\
1366 hidden, invoke \"Show\" button in the previous line to show." "\
1367 group now hidden, invoke the above \"Show\" button to show contents.")
1368 (invalid "x" custom-invalid-face "\
1369 the value displayed for this %c is invalid and cannot be set.")
1370 (modified "*" custom-modified-face "\
1371 you have edited the value as text, but you have not set the %c." "\
1372 you have edited something in this group, but not set it.")
1373 (set "+" custom-set-face "\
1374 you have set this %c, but not saved it for future sessions." "\
1375 something in this group has been set, but not saved.")
1376 (changed ":" custom-changed-face "\
1377 this %c has been changed outside the customize buffer." "\
1378 something in this group has been changed outside customize.")
1379 (saved "!" custom-saved-face "\
1380 this %c has been set and saved." "\
1381 something in this group has been set and saved.")
1382 (rogue "@" custom-rogue-face "\
1383 this %c has not been changed with customize." "\
1384 something in this group is not prepared for customization.")
1385 (standard " " nil "\
1386 this %c is unchanged from its standard setting." "\
1387 visible group members are all at standard settings."))
1388 "Alist of customize option states.
1389 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1391 STATE is one of the following symbols:
1394 For internal use, should never occur.
1396 For internal use, should never occur.
1398 This item is not being displayed.
1400 This item is modified, but has an invalid form.
1402 This item is modified, and has a valid form.
1404 This item has been set but not saved.
1406 The current value of this item has been changed temporarily.
1408 This item is marked for saving.
1410 This item has no customization information.
1412 This item is unchanged from the standard setting.
1414 MAGIC is a string used to present that state.
1416 FACE is a face used to present the state.
1418 ITEM-DESC is a string describing the state for options.
1420 GROUP-DESC is a string describing the state for groups. If this is
1421 left out, ITEM-DESC will be used.
1423 The string %c in either description will be replaced with the
1424 category of the item. These are `group'. `option', and `face'.
1426 The list should be sorted most significant first.")
1428 (defcustom custom-magic-show 'long
1429 "If non-nil, show textual description of the state.
1430 If `long', show a full-line description, not just one word."
1431 :type '(choice (const :tag "no" nil)
1434 :group 'custom-buffer)
1436 (defcustom custom-magic-show-hidden '(option face)
1437 "Control whether the State button is shown for hidden items.
1438 The value should be a list with the custom categories where the State
1439 button should be visible. Possible categories are `group', `option',
1441 :type '(set (const group) (const option) (const face))
1442 :group 'custom-buffer)
1444 (defcustom custom-magic-show-button nil
1445 "Show a \"magic\" button indicating the state of each customization option."
1447 :group 'custom-buffer)
1449 (define-widget 'custom-magic 'default
1450 "Show and manipulate state for a customization option."
1452 :action 'widget-parent-action
1455 :value-create 'custom-magic-value-create
1456 :value-delete 'widget-children-value-delete)
1458 (defun widget-magic-mouse-down-action (widget &optional event)
1459 ;; Non-nil unless hidden.
1460 (not (eq (widget-get (widget-get (widget-get widget :parent) :parent)
1464 (defun custom-magic-value-create (widget)
1465 ;; Create compact status report for WIDGET.
1466 (let* ((parent (widget-get widget :parent))
1467 (state (widget-get parent :custom-state))
1468 (hidden (eq state 'hidden))
1469 (entry (assq state custom-magic-alist))
1470 (magic (nth 1 entry))
1471 (face (nth 2 entry))
1472 (category (widget-get parent :custom-category))
1473 (text (or (and (eq category 'group)
1476 (form (widget-get parent :custom-form))
1478 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text)
1479 (setq text (concat (match-string 1 text)
1480 (symbol-name category)
1481 (match-string 2 text))))
1482 (when (and custom-magic-show
1484 (memq category custom-magic-show-hidden)))
1486 (when (and (eq category 'group)
1487 (not (and (eq custom-buffer-style 'links)
1488 (> (widget-get parent :custom-level) 1))))
1489 (insert-char ?\ (* custom-buffer-indent
1490 (widget-get parent :custom-level))))
1491 (push (widget-create-child-and-convert
1493 :help-echo "Change the state of this item"
1494 :format (if hidden "%t" "%[%t%]")
1495 :button-prefix 'widget-push-button-prefix
1496 :button-suffix 'widget-push-button-suffix
1497 :mouse-down-action 'widget-magic-mouse-down-action
1499 ;;:tag-glyph (or hidden '("state-up" "state-down"))
1503 (let ((start (point)))
1504 (if (eq custom-magic-show 'long)
1506 (insert (symbol-name state)))
1507 (cond ((eq form 'lisp)
1509 ((eq form 'mismatch)
1510 (insert " (mismatch)")))
1511 (put-text-property start (point) 'face 'custom-state-face))
1513 (when (and (eq category 'group)
1514 (not (and (eq custom-buffer-style 'links)
1515 (> (widget-get parent :custom-level) 1))))
1516 (insert-char ?\ (* custom-buffer-indent
1517 (widget-get parent :custom-level))))
1518 (when custom-magic-show-button
1519 (when custom-magic-show
1520 (let ((indent (widget-get parent :indent)))
1522 (insert-char ?\ indent))))
1523 (push (widget-create-child-and-convert
1525 :mouse-down-action 'widget-magic-mouse-down-action
1529 :help-echo "Change the state"
1530 :format (if hidden "%t" "%[%t%]")
1531 :tag (if (memq form '(lisp mismatch))
1532 (concat "(" magic ")")
1533 (concat "[" magic "]")))
1536 (widget-put widget :children children)))
1538 (defun custom-magic-reset (widget)
1539 "Redraw the :custom-magic property of WIDGET."
1540 (let ((magic (widget-get widget :custom-magic)))
1541 (widget-value-set magic (widget-value magic))))
1543 ;;; The `custom' Widget.
1545 (defface custom-button-face '((t (:bold t)))
1546 "Face used for buttons in customization buffers."
1547 :group 'custom-faces)
1549 (defface custom-documentation-face nil
1550 "Face used for documentation strings in customization buffers."
1551 :group 'custom-faces)
1553 (defface custom-state-face '((((class color)
1555 (:foreground "lime green"))
1558 (:foreground "dark green"))
1560 "Face used for State descriptions in the customize buffer."
1561 :group 'custom-faces)
1563 (define-widget 'custom 'default
1564 "Customize a user option."
1566 :convert-widget 'custom-convert-widget
1567 :notify 'custom-notify
1570 :custom-state 'hidden
1571 :documentation-property 'widget-subclass-responsibility
1572 :value-create 'widget-subclass-responsibility
1573 :value-delete 'widget-children-value-delete
1574 :value-get 'widget-value-value-get
1575 :validate 'widget-children-validate
1576 :match (lambda (widget value) (symbolp value)))
1578 (defun custom-convert-widget (widget)
1579 ;; Initialize :value and :tag from :args in WIDGET.
1580 (let ((args (widget-get widget :args)))
1582 (widget-put widget :value (widget-apply widget
1583 :value-to-internal (car args)))
1584 (widget-put widget :tag (custom-unlispify-tag-name (car args)))
1585 (widget-put widget :args nil)))
1588 (defun custom-notify (widget &rest args)
1589 "Keep track of changes."
1590 (let ((state (widget-get widget :custom-state)))
1591 (unless (eq state 'modified)
1592 (unless (memq state '(nil unknown hidden))
1593 (widget-put widget :custom-state 'modified))
1594 (custom-magic-reset widget)
1595 (apply 'widget-default-notify widget args))))
1597 (defun custom-redraw (widget)
1598 "Redraw WIDGET with current settings."
1599 (let ((line (count-lines (point-min) (point)))
1600 (column (current-column))
1602 (from (marker-position (widget-get widget :from)))
1603 (to (marker-position (widget-get widget :to))))
1605 (widget-value-set widget (widget-value widget))
1606 (custom-redraw-magic widget))
1607 (when (and (>= pos from) (<= pos to))
1612 (goto-line (1+ line)))
1613 (move-to-column column))
1616 (defun custom-redraw-magic (widget)
1617 "Redraw WIDGET state with current settings."
1619 (let ((magic (widget-get widget :custom-magic)))
1621 (widget-value-set magic (widget-value magic))
1622 (when (setq widget (widget-get widget :group))
1623 (custom-group-state-update widget)))
1625 (setq widget nil)))))
1628 (defun custom-show (widget value)
1629 "Non-nil if WIDGET should be shown with VALUE by default."
1630 (let ((show (widget-get widget :custom-show)))
1636 (funcall show widget value)))))
1638 (defvar custom-load-recursion nil
1639 "Hack to avoid recursive dependencies.")
1641 (defun custom-load-symbol (symbol)
1642 "Load all dependencies for SYMBOL."
1643 (unless custom-load-recursion
1644 (let ((custom-load-recursion t)
1645 (loads (get symbol 'custom-loads))
1648 (setq load (car loads)
1650 (cond ((symbolp load)
1654 ;; Don't reload a file already loaded.
1655 ((and (boundp 'preloaded-file-list)
1656 (member load preloaded-file-list)))
1657 ((assoc load load-history))
1658 ((assoc (locate-library load) load-history))
1661 ;; Without this, we would load cus-edit recursively.
1662 ;; We are still loading it when we call this,
1663 ;; and it is not in load-history yet.
1664 (or (equal load "cus-edit")
1665 (load-library load))
1668 (defun custom-load-widget (widget)
1669 "Load all dependencies for WIDGET."
1670 (custom-load-symbol (widget-value widget)))
1672 (defun custom-unloaded-symbol-p (symbol)
1673 "Return non-nil if the dependencies of SYMBOL has not yet been loaded."
1675 (loads (get symbol 'custom-loads))
1678 (setq load (car loads)
1680 (cond ((symbolp load)
1681 (unless (featurep load)
1683 ((assoc load load-history))
1684 ((assoc (locate-library load) load-history)
1691 (defun custom-unloaded-widget-p (widget)
1692 "Return non-nil if the dependencies of WIDGET has not yet been loaded."
1693 (custom-unloaded-symbol-p (widget-value widget)))
1695 (defun custom-toggle-hide (widget)
1696 "Toggle visibility of WIDGET."
1697 (custom-load-widget widget)
1698 (let ((state (widget-get widget :custom-state)))
1699 (cond ((memq state '(invalid modified))
1700 (error "There are unset changes"))
1702 (widget-put widget :custom-state 'unknown))
1704 (widget-put widget :documentation-shown nil)
1705 (widget-put widget :custom-state 'hidden)))
1706 (custom-redraw widget)
1709 (defun custom-toggle-parent (widget &rest ignore)
1710 "Toggle visibility of parent of WIDGET."
1711 (custom-toggle-hide (widget-get widget :parent)))
1713 (defun custom-add-see-also (widget &optional prefix)
1714 "Add `See also ...' to WIDGET if there are any links.
1715 Insert PREFIX first if non-nil."
1716 (let* ((symbol (widget-get widget :value))
1717 (links (get symbol 'custom-links))
1718 (many (> (length links) 2))
1719 (buttons (widget-get widget :buttons))
1720 (indent (widget-get widget :indent)))
1723 (insert-char ?\ indent))
1726 (insert "See also ")
1728 (push (widget-create-child-and-convert widget (car links))
1730 (setq links (cdr links))
1739 (widget-put widget :buttons buttons))))
1741 (defun custom-add-parent-links (widget &optional initial-string)
1742 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
1743 The value if non-nil if any parents were found.
1744 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
1745 (let ((name (widget-value widget))
1746 (type (widget-type widget))
1747 (buttons (widget-get widget :buttons))
1750 (insert (or initial-string "Parent groups:"))
1751 (maphash (lambda (group ignore)
1752 (let ((entry (assq name (get group 'custom-group))))
1753 (when (eq (nth 1 entry) type)
1755 (push (widget-create-child-and-convert
1756 widget 'custom-group-link
1757 :tag (custom-unlispify-tag-name group)
1761 custom-group-hash-table)
1762 (widget-put widget :buttons buttons)
1765 (delete-region start (point)))
1768 ;;; The `custom-comment' Widget.
1770 ;; like the editable field
1771 (defface custom-comment-face '((((class grayscale color)
1773 (:background "gray85"))
1774 (((class grayscale color)
1776 (:background "dim gray"))
1779 "Face used for comments on variables or faces"
1780 :group 'custom-faces)
1782 ;; like font-lock-comment-face
1783 (defface custom-comment-tag-face
1784 '((((class color) (background dark)) (:foreground "gray80"))
1785 (((class color) (background light)) (:foreground "blue4"))
1786 (((class grayscale) (background light))
1787 (:foreground "DimGray" :bold t :italic t))
1788 (((class grayscale) (background dark))
1789 (:foreground "LightGray" :bold t :italic t))
1791 "Face used for variables or faces comment tags"
1792 :group 'custom-faces)
1794 (define-widget 'custom-comment 'string
1797 :help-echo "Edit a comment here"
1798 :sample-face 'custom-comment-tag-face
1799 :value-face 'custom-comment-face
1800 :value-set 'custom-comment-value-set
1801 :create 'custom-comment-create
1802 :delete 'custom-comment-delete)
1804 (defun custom-comment-create (widget)
1806 (widget-default-create widget)
1807 (widget-put widget :comment-extent
1808 (setq ext (make-extent (widget-get widget :from)
1809 (widget-get widget :to))))
1810 (set-extent-property ext 'start-open t)
1811 (when (equal (widget-get widget :value) "")
1812 (set-extent-property ext 'invisible t))
1815 (defun custom-comment-delete (widget)
1816 (widget-default-delete widget)
1817 (delete-extent (widget-get widget :comment-extent)))
1819 (defun custom-comment-value-set (widget value)
1820 (widget-default-value-set widget value)
1821 (if (equal value "")
1822 (set-extent-property (widget-get widget :comment-extent)
1824 (set-extent-property (widget-get widget :comment-extent)
1827 ;; Those functions are for the menu. WIDGET is NOT the comment widget. It's
1828 ;; the global custom one
1829 (defun custom-comment-show (widget)
1830 (set-extent-property
1831 (widget-get (widget-get widget :comment-widget) :comment-extent)
1834 (defun custom-comment-invisible-p (widget)
1836 (widget-get (widget-get widget :comment-widget) :comment-extent)
1839 ;;; The `custom-variable' Widget.
1841 (defface custom-variable-tag-face '((((class color)
1843 (:foreground "light blue" :underline t))
1846 (:foreground "blue" :underline t))
1848 "Face used for unpushable variable tags."
1849 :group 'custom-faces)
1851 (defface custom-variable-button-face '((t (:underline t :bold t)))
1852 "Face used for pushable variable tags."
1853 :group 'custom-faces)
1855 (defcustom custom-variable-default-form 'edit
1856 "Default form of displaying variable values."
1857 :type '(choice (const edit)
1859 :group 'custom-buffer)
1861 (define-widget 'custom-variable 'custom
1862 "Customize variable."
1864 :help-echo "Set or reset this variable"
1865 :documentation-property 'variable-documentation
1866 :custom-category 'option
1868 :custom-menu 'custom-variable-menu-create
1869 :custom-form nil ; defaults to value of `custom-variable-default-form'
1870 :value-create 'custom-variable-value-create
1871 :action 'custom-variable-action
1872 :custom-set 'custom-variable-set
1873 :custom-pre-save 'custom-variable-pre-save
1874 :custom-save 'custom-variable-save
1875 :custom-post-save 'custom-variable-post-save
1876 :custom-reset-current 'custom-redraw
1877 :custom-reset-saved 'custom-variable-reset-saved
1878 :custom-pre-reset-standard 'custom-variable-pre-reset-standard
1879 :custom-reset-standard 'custom-variable-reset-standard
1880 :custom-post-reset-standard 'custom-variable-post-reset-standard)
1882 (defun custom-variable-type (symbol)
1883 "Return a widget suitable for editing the value of SYMBOL.
1884 If SYMBOL has a `custom-type' property, use that.
1885 Otherwise, look up symbol in `custom-guess-type-alist'."
1886 (let* ((type (or (get symbol 'custom-type)
1887 (and (not (get symbol 'standard-value))
1888 (custom-guess-type symbol))
1890 (options (get symbol 'custom-options))
1891 (tmp (if (listp type)
1892 (copy-sequence type)
1895 (widget-put tmp :options options))
1898 (defun custom-variable-value-create (widget)
1899 "Here is where you edit the variables value."
1900 (custom-load-widget widget)
1901 (unless (widget-get widget :custom-form)
1902 (widget-put widget :custom-form custom-variable-default-form))
1903 (let* ((buttons (widget-get widget :buttons))
1904 (children (widget-get widget :children))
1905 (form (widget-get widget :custom-form))
1906 (state (widget-get widget :custom-state))
1907 (symbol (widget-get widget :value))
1908 (tag (widget-get widget :tag))
1909 (type (custom-variable-type symbol))
1910 (conv (widget-convert type))
1911 (get (or (get symbol 'custom-get) 'default-value))
1912 (prefix (widget-get widget :custom-prefix))
1913 (last (widget-get widget :custom-last))
1914 (value (if (default-boundp symbol)
1915 (funcall get symbol)
1916 (widget-get conv :value))))
1917 ;; If the widget is new, the child determine whether it is hidden.
1919 ((custom-show type value)
1920 (setq state 'unknown))
1922 (setq state 'hidden)))
1923 ;; If we don't know the state, see if we need to edit it in lisp form.
1924 (when (eq state 'unknown)
1925 (unless (widget-apply conv :match value)
1926 ;; (widget-apply (widget-convert type) :match value)
1927 (setq form 'mismatch)))
1928 ;; Now we can create the child widget.
1929 (cond ((eq custom-buffer-style 'tree)
1930 (insert prefix (if last " `--- " " |--- "))
1931 (push (widget-create-child-and-convert
1932 widget 'custom-browse-variable-tag)
1934 (insert " " tag "\n")
1935 (widget-put widget :buttons buttons))
1937 ;; Indicate hidden value.
1938 (push (widget-create-child-and-convert
1941 :sample-face 'custom-variable-tag-face
1945 (push (widget-create-child-and-convert
1947 :help-echo "Show the value of this option"
1948 :action 'custom-toggle-parent
1951 ((memq form '(lisp mismatch))
1952 ;; In lisp mode edit the saved value when possible.
1953 (let* ((value (cond ((get symbol 'saved-value)
1954 (car (get symbol 'saved-value)))
1955 ((get symbol 'standard-value)
1956 (car (get symbol 'standard-value)))
1957 ((default-boundp symbol)
1958 (custom-quote (funcall get symbol)))
1960 (custom-quote (widget-get conv :value))))))
1961 (insert (symbol-name symbol) ": ")
1962 (push (widget-create-child-and-convert
1964 :help-echo "Hide the value of this option"
1965 :action 'custom-toggle-parent
1969 (push (widget-create-child-and-convert
1971 :button-face 'custom-variable-button-face
1973 :tag (symbol-name symbol)
1979 (let* ((format (widget-get type :format))
1980 tag-format value-format)
1981 (while (not (string-match ":" format))
1982 (setq format (signal 'error (list "Bad format" format))))
1983 (setq tag-format (substring format 0 (match-end 0)))
1984 (setq value-format (substring format (match-end 0)))
1985 (push (widget-create-child-and-convert
1988 :action 'custom-tag-action
1989 :help-echo "Change value of this option"
1990 :mouse-down-action 'custom-tag-mouse-down-action
1991 :button-face 'custom-variable-button-face
1992 :sample-face 'custom-variable-tag-face
1996 (push (widget-create-child-and-convert
1998 :help-echo "Hide the value of this option"
1999 :action 'custom-toggle-parent
2002 (push (widget-create-child-and-convert
2004 :format value-format
2007 (unless (eq custom-buffer-style 'tree)
2008 (unless (eq (preceding-char) ?\n)
2009 (widget-insert "\n"))
2010 ;; Create the magic button.
2011 (let ((magic (widget-create-child-and-convert
2012 widget 'custom-magic nil)))
2013 (widget-put widget :custom-magic magic)
2014 (push magic buttons))
2015 ;; Insert documentation.
2016 ;; #### NOTE: this is ugly!!!! I need to do update the :buttons property
2017 ;; before the call to `widget-default-format-handler'. Otherwise, I
2018 ;; lose my current `buttons'. This function shouldn't be called like
2019 ;; this anyway. The doc string widget should be added like the others.
2021 (widget-put widget :buttons buttons)
2022 (widget-default-format-handler widget ?h)
2023 ;; The comment field
2024 (unless (eq state 'hidden)
2025 (let* ((comment (get symbol 'variable-comment))
2027 (widget-create-child-and-convert
2028 widget 'custom-comment
2030 :value (or comment ""))))
2031 (widget-put widget :comment-widget comment-widget)
2032 ;; Don't push it !!! Custom assumes that the first child is the
2034 (setq children (append children (list comment-widget)))))
2035 ;; Update the rest of the properties properties.
2036 (widget-put widget :custom-form form)
2037 (widget-put widget :children children)
2038 ;; Now update the state.
2039 (if (eq state 'hidden)
2040 (widget-put widget :custom-state state)
2041 (custom-variable-state-set widget))
2043 (unless (eq state 'hidden)
2044 (when (eq (widget-get widget :custom-level) 1)
2045 (custom-add-parent-links widget))
2046 (custom-add-see-also widget)))))
2048 (defun custom-tag-action (widget &rest args)
2049 "Pass :action to first child of WIDGET's parent."
2050 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
2053 (defun custom-tag-mouse-down-action (widget &rest args)
2054 "Pass :mouse-down-action to first child of WIDGET's parent."
2055 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
2056 :mouse-down-action args))
2058 (defun custom-variable-state-set (widget)
2059 "Set the state of WIDGET."
2060 (let* ((symbol (widget-value widget))
2061 (get (or (get symbol 'custom-get) 'default-value))
2062 (value (if (default-boundp symbol)
2063 (funcall get symbol)
2064 (widget-get widget :value)))
2065 (comment (get symbol 'variable-comment))
2068 (state (cond ((progn (setq tmp (get symbol 'customized-value))
2070 (get symbol 'customized-variable-comment))
2072 (if (condition-case nil
2073 (and (equal value (eval (car tmp)))
2074 (equal comment temp))
2078 ((progn (setq tmp (get symbol 'saved-value))
2079 (setq temp (get symbol 'saved-variable-comment))
2081 (if (condition-case nil
2082 (and (equal value (eval (car tmp)))
2083 (equal comment temp))
2087 ((setq tmp (get symbol 'standard-value))
2088 (if (condition-case nil
2089 (and (equal value (eval (car tmp)))
2090 (equal comment nil))
2095 (widget-put widget :custom-state state)))
2097 (defvar custom-variable-menu
2098 '(("Set for Current Session" custom-variable-set
2100 (eq (widget-get widget :custom-state) 'modified)))
2101 ("Save for Future Sessions" custom-variable-save
2103 (memq (widget-get widget :custom-state) '(modified set changed rogue))))
2104 ("Reset to Current" custom-redraw
2106 (and (default-boundp (widget-value widget))
2107 (memq (widget-get widget :custom-state) '(modified changed)))))
2108 ("Reset to Saved" custom-variable-reset-saved
2110 (and (or (get (widget-value widget) 'saved-value)
2111 (get (widget-value widget) 'saved-variable-comment))
2112 (memq (widget-get widget :custom-state)
2113 '(modified set changed rogue)))))
2114 ("Reset to Standard Settings" custom-variable-reset-standard
2116 (and (get (widget-value widget) 'standard-value)
2117 (memq (widget-get widget :custom-state)
2118 '(modified set changed saved rogue)))))
2119 ("---" ignore ignore)
2120 ("Add Comment" custom-comment-show custom-comment-invisible-p)
2121 ("---" ignore ignore)
2122 ("Don't show as Lisp expression" custom-variable-edit
2124 (eq (widget-get widget :custom-form) 'lisp)))
2125 ("Show as Lisp expression" custom-variable-edit-lisp
2127 (eq (widget-get widget :custom-form) 'edit))))
2128 "Alist of actions for the `custom-variable' widget.
2129 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2130 the menu entry, ACTION is the function to call on the widget when the
2131 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2132 widget as an argument, and returns non-nil if ACTION is valid on that
2133 widget. If FILTER is nil, ACTION is always valid.")
2135 (defun custom-variable-action (widget &optional event)
2136 "Show the menu for `custom-variable' WIDGET.
2137 Optional EVENT is the location for the menu."
2138 (if (eq (widget-get widget :custom-state) 'hidden)
2139 (custom-toggle-hide widget)
2140 (unless (eq (widget-get widget :custom-state) 'modified)
2141 (custom-variable-state-set widget))
2142 ;; Redrawing magic also depresses the state glyph.
2143 ;(custom-redraw-magic widget)
2144 (let* ((completion-ignore-case t)
2145 (answer (widget-choose (concat "Operation on "
2146 (custom-unlispify-tag-name
2147 (widget-get widget :value)))
2148 (custom-menu-filter custom-variable-menu
2152 (funcall answer widget)))))
2154 (defun custom-variable-edit (widget)
2155 "Edit value of WIDGET."
2156 (widget-put widget :custom-state 'unknown)
2157 (widget-put widget :custom-form 'edit)
2158 (custom-redraw widget))
2160 (defun custom-variable-edit-lisp (widget)
2161 "Edit the lisp representation of the value of WIDGET."
2162 (widget-put widget :custom-state 'unknown)
2163 (widget-put widget :custom-form 'lisp)
2164 (custom-redraw widget))
2166 (defun custom-variable-set (widget)
2167 "Set the current value for the variable being edited by WIDGET."
2168 (let* ((form (widget-get widget :custom-form))
2169 (state (widget-get widget :custom-state))
2170 (child (car (widget-get widget :children)))
2171 (symbol (widget-value widget))
2172 (set (or (get symbol 'custom-set) 'set-default))
2173 (comment-widget (widget-get widget :comment-widget))
2174 (comment (widget-value comment-widget))
2176 (cond ((eq state 'hidden)
2177 (error "Cannot set hidden variable"))
2178 ((setq val (widget-apply child :validate))
2179 (goto-char (widget-get val :from))
2180 (error "%s" (widget-get val :error)))
2181 ((memq form '(lisp mismatch))
2182 (when (equal comment "")
2184 ;; Make the comment invisible by hand if it's empty
2185 (set-extent-property (widget-get comment-widget :comment-extent)
2187 (funcall set symbol (eval (setq val (widget-value child))))
2188 (put symbol 'customized-value (list val))
2189 (put symbol 'variable-comment comment)
2190 (put symbol 'customized-variable-comment comment))
2192 (when (equal comment "")
2194 ;; Make the comment invisible by hand if it's empty
2195 (set-extent-property (widget-get comment-widget :comment-extent)
2197 (funcall set symbol (setq val (widget-value child)))
2198 (put symbol 'customized-value (list (custom-quote val)))
2199 (put symbol 'variable-comment comment)
2200 (put symbol 'customized-variable-comment comment)))
2201 (custom-variable-state-set widget)
2202 (custom-redraw-magic widget)))
2204 (defun custom-variable-pre-save (widget)
2205 "Prepare for saving the value for the variable being edited by WIDGET."
2206 (let* ((form (widget-get widget :custom-form))
2207 (state (widget-get widget :custom-state))
2208 (child (car (widget-get widget :children)))
2209 (symbol (widget-value widget))
2210 (set (or (get symbol 'custom-set) 'set-default))
2211 (comment-widget (widget-get widget :comment-widget))
2212 (comment (widget-value comment-widget))
2214 (cond ((eq state 'hidden)
2215 (error "Cannot set hidden variable"))
2216 ((setq val (widget-apply child :validate))
2217 (goto-char (widget-get val :from))
2218 (error "%s" (widget-get val :error)))
2219 ((memq form '(lisp mismatch))
2220 (when (equal comment "")
2222 ;; Make the comment invisible by hand if it's empty
2223 (set-extent-property (widget-get comment-widget :comment-extent)
2225 (put symbol 'saved-value (list (widget-value child)))
2226 (custom-push-theme 'theme-value symbol 'user
2227 'set (list (widget-value child)))
2228 (funcall set symbol (eval (widget-value child)))
2229 (put symbol 'variable-comment comment)
2230 (put symbol 'saved-variable-comment comment))
2232 (when (equal comment "")
2234 ;; Make the comment invisible by hand if it's empty
2235 (set-extent-property (widget-get comment-widget :comment-extent)
2238 'saved-value (list (custom-quote (widget-value
2240 (custom-push-theme 'theme-value symbol 'user
2241 'set (list (custom-quote (widget-value
2243 (funcall set symbol (widget-value child))
2244 (put symbol 'variable-comment comment)
2245 (put symbol 'saved-variable-comment comment)))
2246 (put symbol 'customized-value nil)
2247 (put symbol 'customized-variable-comment nil)
2250 (defun custom-variable-post-save (widget)
2251 "Finish saving the variable being edited by WIDGET."
2252 (custom-variable-state-set widget)
2253 (custom-redraw-magic widget))
2255 (defun custom-variable-save (widget)
2256 "Set and save the value for the variable being edited by WIDGET."
2257 (custom-variable-pre-save widget)
2259 (custom-variable-post-save widget))
2261 (defun custom-variable-reset-saved (widget)
2262 "Restore the saved value for the variable being edited by WIDGET."
2263 (let* ((symbol (widget-value widget))
2264 (set (or (get symbol 'custom-set) 'set-default))
2265 (value (get symbol 'saved-value))
2266 (comment (get symbol 'saved-variable-comment)))
2267 (cond ((or value comment)
2268 (put symbol 'variable-comment comment)
2270 (funcall set symbol (eval (car value)))
2273 (signal 'error (list "No saved value for variable" symbol))))
2274 (put symbol 'customized-value nil)
2275 (put symbol 'customized-variable-comment nil)
2276 (widget-put widget :custom-state 'unknown)
2277 ;; This call will possibly make the comment invisible
2278 (custom-redraw widget)))
2280 ;; This function returns non nil if we need to re-save the options --dv.
2281 (defun custom-variable-pre-reset-standard (widget)
2282 "Prepare for restoring the variable being edited by WIDGET to its
2284 (let* ((symbol (widget-value widget))
2285 (set (or (get symbol 'custom-set) 'set-default)))
2286 (if (get symbol 'standard-value)
2287 (funcall set symbol (eval (car (get symbol 'standard-value))))
2288 (signal 'error (list "No standard setting known for variable" symbol)))
2289 (put symbol 'variable-comment nil)
2290 (put symbol 'customized-value nil)
2291 (put symbol 'customized-variable-comment nil)
2292 (when (or (get symbol 'saved-value) (get symbol 'saved-variable-comment))
2293 (put symbol 'saved-value nil)
2294 (custom-push-theme 'theme-value symbol 'user 'reset 'standard)
2295 ;; As a special optimizations we do not (explictly)
2296 ;; save resets to standard when no theme set the value.
2297 (if (null (cdr (get symbol 'theme-value)))
2298 (put symbol 'theme-value nil))
2299 (put symbol 'saved-variable-comment nil)
2303 (defun custom-variable-post-reset-standard (widget)
2304 "Finish resetting the variable being edited by WIDGET to its standard
2306 (widget-put widget :custom-state 'unknown)
2307 ;; This call will possibly make the comment invisible
2308 (custom-redraw widget))
2310 (defun custom-variable-reset-standard (widget)
2311 "Restore the standard setting for the variable being edited by WIDGET."
2312 (when (custom-variable-pre-reset-standard widget)
2314 (custom-variable-post-reset-standard widget))
2316 ;;; The `custom-face-edit' Widget.
2318 (define-widget 'custom-face-edit 'checklist
2319 "Edit face attributes."
2323 :button-args '(:help-echo "Control whether this attribute has any effect")
2324 :args (mapcar (lambda (att)
2327 :sibling-args (widget-get (nth 1 att) :sibling-args)
2328 (list 'const :format "" :value (nth 0 att))
2330 custom-face-attributes))
2332 ;;; The `custom-display' Widget.
2334 (define-widget 'custom-display 'menu-choice
2335 "Select a display type."
2338 :help-echo "Specify frames where the face attributes should be used"
2339 :args '((const :tag "all" t)
2343 :args ((group :sibling-args (:help-echo "\
2344 Only match the specified window systems")
2345 (const :format "Type: "
2347 (checklist :inline t
2350 :sibling-args (:help-echo "\
2351 The X11 Window System")
2353 (const :format "GTK "
2354 :sibling-args (:help-echo "\
2355 The GTK Window System")
2357 (const :format "PM "
2358 :sibling-args (:help-echo "\
2359 OS/2 Presentation Manager")
2361 (const :format "MSWindows "
2362 :sibling-args (:help-echo "\
2363 Microsoft Windows, displays")
2365 (const :format "MSPrinter "
2366 :sibling-args (:help-echo "\
2367 Microsoft Windows, printers")
2369 (const :format "TTY%n"
2370 :sibling-args (:help-echo "\
2371 Plain text terminals")
2373 (group :sibling-args (:help-echo "\
2374 Only match display or printer devices")
2375 (const :format "Output: "
2377 (checklist :inline t
2379 (const :format "Display "
2380 :sibling-args (:help-echo "\
2381 Match display devices")
2383 (const :format "Printer%n"
2384 :sibling-args (:help-echo "\
2385 Match printer devices")
2387 (group :sibling-args (:help-echo "\
2388 Only match the frames with the specified color support")
2389 (const :format "Color support: "
2391 (checklist :inline t
2393 (const :format "Color "
2394 :sibling-args (:help-echo "\
2395 Match color frames")
2397 (const :format "Grayscale "
2398 :sibling-args (:help-echo "\
2399 Match grayscale frames")
2401 (const :format "Monochrome%n"
2402 :sibling-args (:help-echo "\
2403 Match frames with no color support")
2405 (group :sibling-args (:help-echo "\
2406 Only match frames with the specified intensity")
2408 Background brightness: "
2410 (checklist :inline t
2412 (const :format "Light "
2413 :sibling-args (:help-echo "\
2414 Match frames with light backgrounds")
2416 (const :format "Dark\n"
2417 :sibling-args (:help-echo "\
2418 Match frames with dark backgrounds")
2421 ;;; The `custom-face' Widget.
2423 (defface custom-face-tag-face '((t (:underline t)))
2424 "Face used for face tags."
2425 :group 'custom-faces)
2427 (defcustom custom-face-default-form 'selected
2428 "Default form of displaying face definition."
2429 :type '(choice (const all)
2432 :group 'custom-buffer)
2434 (define-widget 'custom-face 'custom
2436 :sample-face 'custom-face-tag-face
2437 :help-echo "Set or reset this face"
2438 :documentation-property '(lambda (face)
2439 (face-doc-string face))
2440 :value-create 'custom-face-value-create
2441 :action 'custom-face-action
2442 :custom-category 'face
2443 :custom-form nil ; defaults to value of `custom-face-default-form'
2444 :custom-set 'custom-face-set
2445 :custom-pre-save 'custom-face-pre-save
2446 :custom-save 'custom-face-save
2447 :custom-post-save 'custom-face-post-save
2448 :custom-reset-current 'custom-redraw
2449 :custom-reset-saved 'custom-face-reset-saved
2450 :custom-pre-reset-standard 'custom-face-pre-reset-standard
2451 :custom-reset-standard 'custom-face-reset-standard
2452 :custom-post-reset-standard 'custom-face-post-reset-standard
2453 :custom-menu 'custom-face-menu-create)
2455 (define-widget 'custom-face-all 'editable-list
2456 "An editable list of display specifications and attributes."
2457 :entry-format "%i %d %v"
2458 :insert-button-args '(:help-echo "Insert new display specification here")
2459 :append-button-args '(:help-echo "Append new display specification here")
2460 :delete-button-args '(:help-echo "Delete this display specification")
2461 :args '((group :format "%v" custom-display custom-face-edit)))
2463 (defconst custom-face-all (widget-convert 'custom-face-all)
2464 "Converted version of the `custom-face-all' widget.")
2466 (define-widget 'custom-display-unselected 'item
2467 "A display specification that doesn't match the selected display."
2468 :match 'custom-display-unselected-match)
2470 (defun custom-display-unselected-match (widget value)
2471 "Non-nil if VALUE is an unselected display specification."
2472 (not (face-spec-set-match-display value (selected-frame))))
2474 (define-widget 'custom-face-selected 'group
2475 "Edit the attributes of the selected display in a face specification."
2476 :args '((repeat :format ""
2478 (group custom-display-unselected sexp))
2479 (group (sexp :format "") custom-face-edit)
2484 (defconst custom-face-selected (widget-convert 'custom-face-selected)
2485 "Converted version of the `custom-face-selected' widget.")
2487 (defun custom-face-value-create (widget)
2488 "Create a list of the display specifications for WIDGET."
2489 (let ((buttons (widget-get widget :buttons))
2491 (symbol (widget-get widget :value))
2492 (tag (widget-get widget :tag))
2493 (state (widget-get widget :custom-state))
2495 (is-last (widget-get widget :custom-last))
2496 (prefix (widget-get widget :custom-prefix)))
2498 (setq tag (prin1-to-string symbol)))
2499 (cond ((eq custom-buffer-style 'tree)
2500 (insert prefix (if is-last " `--- " " |--- "))
2501 (push (widget-create-child-and-convert
2502 widget 'custom-browse-face-tag)
2504 (insert " " tag "\n")
2505 (widget-put widget :buttons buttons))
2509 (if (eq custom-buffer-style 'face)
2511 (widget-specify-sample widget begin (point))
2514 (and (not (find-face symbol))
2515 ;; XEmacs cannot display uninitialized faces.
2517 (push (widget-create-child-and-convert widget 'item
2524 (push (widget-create-child-and-convert
2526 :help-echo "Hide or show this face"
2527 :action 'custom-toggle-parent
2528 (not (eq state 'hidden)))
2532 (let ((magic (widget-create-child-and-convert
2533 widget 'custom-magic nil)))
2534 (widget-put widget :custom-magic magic)
2535 (push magic buttons))
2537 (widget-put widget :buttons buttons)
2538 ;; Insert documentation.
2539 (widget-default-format-handler widget ?h)
2540 ;; The comment field
2541 (unless (eq state 'hidden)
2542 (let* ((comment (get symbol 'face-comment))
2544 (widget-create-child-and-convert
2545 widget 'custom-comment
2547 :value (or comment ""))))
2548 (widget-put widget :comment-widget comment-widget)
2549 (push comment-widget children)))
2551 (unless (eq state 'hidden)
2552 (when (eq (widget-get widget :custom-level) 1)
2553 (custom-add-parent-links widget))
2554 (custom-add-see-also widget))
2556 (unless (eq (preceding-char) ?\n)
2558 (unless (eq state 'hidden)
2559 (message "Creating face editor...")
2560 (custom-load-widget widget)
2561 (unless (widget-get widget :custom-form)
2562 (widget-put widget :custom-form custom-face-default-form))
2563 (let* ((symbol (widget-value widget))
2564 (spec (custom-face-get-spec symbol))
2565 (form (widget-get widget :custom-form))
2566 (indent (widget-get widget :indent))
2567 (edit (widget-create-child-and-convert
2569 (cond ((and (eq form 'selected)
2570 (widget-apply custom-face-selected
2572 (when indent (insert-char ?\ indent))
2573 'custom-face-selected)
2574 ((and (not (eq form 'lisp))
2575 (widget-apply custom-face-all
2579 (when indent (insert-char ?\ indent))
2582 (custom-face-state-set widget)
2583 (push edit children)
2584 (widget-put widget :children children))
2585 (message "Creating face editor...done"))))))
2587 (defvar custom-face-menu
2588 '(("Set for Current Session" custom-face-set)
2589 ("Save for Future Sessions" custom-face-save)
2590 ("Reset to Saved" custom-face-reset-saved
2592 (or (get (widget-value widget) 'saved-face)
2593 (get (widget-value widget) 'saved-face-comment))))
2594 ("Reset to Standard Setting" custom-face-reset-standard
2596 (get (widget-value widget) 'face-defface-spec)))
2597 ("---" ignore ignore)
2598 ("Add Comment" custom-comment-show custom-comment-invisible-p)
2599 ("---" ignore ignore)
2600 ("Show all display specs" custom-face-edit-all
2602 (not (eq (widget-get widget :custom-form) 'all))))
2603 ("Just current attributes" custom-face-edit-selected
2605 (not (eq (widget-get widget :custom-form) 'selected))))
2606 ("Show as Lisp expression" custom-face-edit-lisp
2608 (not (eq (widget-get widget :custom-form) 'lisp)))))
2609 "Alist of actions for the `custom-face' widget.
2610 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2611 the menu entry, ACTION is the function to call on the widget when the
2612 menu is selected, and FILTER is a predicate which takes a `custom-face'
2613 widget as an argument, and returns non-nil if ACTION is valid on that
2614 widget. If FILTER is nil, ACTION is always valid.")
2616 (defun custom-face-edit-selected (widget)
2617 "Edit selected attributes of the value of WIDGET."
2618 (widget-put widget :custom-state 'unknown)
2619 (widget-put widget :custom-form 'selected)
2620 (custom-redraw widget))
2622 (defun custom-face-edit-all (widget)
2623 "Edit all attributes of the value of WIDGET."
2624 (widget-put widget :custom-state 'unknown)
2625 (widget-put widget :custom-form 'all)
2626 (custom-redraw widget))
2628 (defun custom-face-edit-lisp (widget)
2629 "Edit the lisp representation of the value of WIDGET."
2630 (widget-put widget :custom-state 'unknown)
2631 (widget-put widget :custom-form 'lisp)
2632 (custom-redraw widget))
2634 (defun custom-face-state-set (widget)
2635 "Set the state of WIDGET."
2636 (let* ((symbol (widget-value widget))
2637 (comment (get symbol 'face-comment))
2639 (widget-put widget :custom-state
2641 (setq tmp (get symbol 'customized-face))
2642 (setq temp (get symbol 'customized-face-comment))
2644 (if (equal temp comment)
2648 (setq tmp (get symbol 'saved-face))
2649 (setq temp (get symbol 'saved-face-comment))
2651 (if (equal temp comment)
2654 ((get symbol 'face-defface-spec)
2655 (if (equal comment nil)
2661 (defun custom-face-action (widget &optional event)
2662 "Show the menu for `custom-face' WIDGET.
2663 Optional EVENT is the location for the menu."
2664 (if (eq (widget-get widget :custom-state) 'hidden)
2665 (custom-toggle-hide widget)
2666 (let* ((completion-ignore-case t)
2667 (symbol (widget-get widget :value))
2668 (answer (widget-choose (concat "Operation on "
2669 (custom-unlispify-tag-name symbol))
2670 (custom-menu-filter custom-face-menu
2674 (funcall answer widget)))))
2676 (defun custom-face-set (widget)
2677 "Make the face attributes in WIDGET take effect."
2678 (let* ((symbol (widget-value widget))
2679 (child (car (widget-get widget :children)))
2680 (value (widget-value child))
2681 (comment-widget (widget-get widget :comment-widget))
2682 (comment (widget-value comment-widget)))
2683 (when (equal comment "")
2685 ;; Make the comment invisible by hand if it's empty
2686 (set-extent-property (widget-get comment-widget :comment-extent)
2688 (put symbol 'customized-face value)
2689 (face-spec-set symbol value nil '(custom))
2690 (put symbol 'customized-face-comment comment)
2691 (put symbol 'face-comment comment)
2692 (custom-face-state-set widget)
2693 (custom-redraw-magic widget)))
2695 (defun custom-face-pre-save (widget)
2696 "Prepare for saving the face being edited by WIDGET."
2697 (let* ((symbol (widget-value widget))
2698 (child (car (widget-get widget :children)))
2699 (value (widget-value child))
2700 (comment-widget (widget-get widget :comment-widget))
2701 (comment (widget-value comment-widget)))
2702 (when (equal comment "")
2704 ;; Make the comment invisible by hand if it's empty
2705 (set-extent-property (widget-get comment-widget :comment-extent)
2707 (face-spec-set symbol value nil '(custom))
2708 (put symbol 'saved-face value)
2709 (custom-push-theme 'theme-face symbol 'user 'set value)
2710 (put symbol 'customized-face nil)
2711 (put symbol 'face-comment comment)
2712 (put symbol 'customized-face-comment nil)
2713 (put symbol 'saved-face-comment comment)
2716 (defun custom-face-post-save (widget)
2717 "Finish saving the face being edited by WIDGET."
2718 (custom-face-state-set widget)
2719 (custom-redraw-magic widget))
2721 (defun custom-face-save (widget)
2722 "Save the face being edited by WIDGET."
2723 (custom-face-pre-save widget)
2725 (custom-face-post-save widget))
2727 (defun custom-face-reset-saved (widget)
2728 "Reset the face being edited by WIDGET to its saved value."
2729 (let* ((symbol (widget-value widget))
2730 (child (car (widget-get widget :children)))
2731 (value (get symbol 'saved-face))
2732 (comment (get symbol 'saved-face-comment))
2733 (comment-widget (widget-get widget :comment-widget)))
2734 (unless (or value comment)
2735 (signal 'error (list "No saved value for this face" symbol)))
2736 (put symbol 'customized-face nil)
2737 (put symbol 'customized-face-comment nil)
2738 (face-spec-set symbol value nil '(custom))
2739 (put symbol 'face-comment comment)
2740 (widget-value-set child value)
2741 ;; This call manages the comment visibility
2742 (widget-value-set comment-widget (or comment ""))
2743 (custom-face-state-set widget)
2744 (custom-redraw-magic widget)))
2746 ;; This function returns non nil if we need to re-save the options --dv.
2747 (defun custom-face-pre-reset-standard (widget)
2748 "Prepare for restoring the face edited by WIDGET to its standard
2750 (let* ((symbol (widget-value widget))
2751 (value (get symbol 'face-defface-spec)))
2753 (signal 'error (list "No standard setting for this face" symbol)))
2754 (put symbol 'customized-face nil)
2755 (put symbol 'customized-face-comment nil)
2756 (when (or (get symbol 'saved-face) (get symbol 'saved-face-comment))
2757 (put symbol 'saved-face nil)
2758 (custom-push-theme 'theme-face symbol 'user 'reset 'standard)
2759 ;; Do not explictly save resets to standards without themes.
2760 (if (null (cdr (get symbol 'theme-face)))
2761 (put symbol 'theme-face nil))
2762 (put symbol 'saved-face-comment nil)
2766 (defun custom-face-post-reset-standard (widget)
2767 "Finish restoring the face edited by WIDGET to its standard settings."
2768 (let* ((symbol (widget-value widget))
2769 (child (car (widget-get widget :children)))
2770 (value (get symbol 'face-defface-spec))
2771 (comment-widget (widget-get widget :comment-widget)))
2772 (face-spec-set symbol value nil '(custom))
2773 (put symbol 'face-comment nil)
2774 (widget-value-set child value)
2775 ;; This call manages the comment visibility
2776 (widget-value-set comment-widget "")
2777 (custom-face-state-set widget)
2778 (custom-redraw-magic widget)
2781 (defun custom-face-reset-standard (widget)
2782 "Restore the face edited by WIDGET to its standard settings."
2783 (when (custom-face-pre-reset-standard widget)
2785 (custom-face-post-reset-standard widget))
2788 ;;; The `face' Widget.
2790 (define-widget 'face 'default
2791 "Select and customize a face."
2792 :convert-widget 'widget-value-convert-widget
2793 :button-prefix 'widget-push-button-prefix
2794 :button-suffix 'widget-push-button-suffix
2795 :format "%t: %[select face%] %v"
2798 :value-create 'widget-face-value-create
2799 :value-delete 'widget-face-value-delete
2800 :value-get 'widget-value-value-get
2801 :validate 'widget-children-validate
2802 :action 'widget-face-action
2803 :match (lambda (widget value) (symbolp value)))
2805 (defun widget-face-value-create (widget)
2806 ;; Create a `custom-face' child.
2807 (let* ((symbol (widget-value widget))
2808 (custom-buffer-style 'face)
2809 (child (widget-create-child-and-convert
2813 (custom-magic-reset child)
2814 (setq custom-options (cons child custom-options))
2815 (widget-put widget :children (list child))))
2817 (defun widget-face-value-delete (widget)
2818 ;; Remove the child from the options.
2819 (let ((child (car (widget-get widget :children))))
2820 (setq custom-options (delq child custom-options))
2821 (widget-children-value-delete widget)))
2823 (defvar face-history nil
2824 "History of entered face names.")
2826 (defun widget-face-action (widget &optional event)
2827 "Prompt for a face."
2828 (let ((answer (completing-read "Face: "
2829 (mapcar (lambda (face)
2830 (list (symbol-name face)))
2834 (unless (zerop (length answer))
2835 (widget-value-set widget (intern answer))
2836 (widget-apply widget :notify widget event)
2839 ;;; The `hook' Widget.
2841 (define-widget 'hook 'list
2843 :value-to-internal (lambda (widget value)
2847 :match (lambda (widget value)
2849 (widget-group-match widget value)))
2850 :convert-widget 'custom-hook-convert-widget
2853 (defun custom-hook-convert-widget (widget)
2854 ;; Handle `:options'.
2855 (let* ((options (widget-get widget :options))
2856 (other `(editable-list :inline t
2857 :entry-format "%i %d%v"
2858 (function :format " %v")))
2860 (list `(checklist :inline t
2861 ,@(mapcar (lambda (entry)
2862 `(function-item ,entry))
2866 (widget-put widget :args args)
2869 ;;; The `plist' Widget.
2871 (define-widget 'plist 'list
2873 :match (lambda (widget value)
2874 (valid-plist-p value))
2875 :convert-widget 'custom-plist-convert-widget
2876 :tag "Property List")
2878 ;; #### Should handle options better.
2879 (defun custom-plist-convert-widget (widget)
2880 (let* ((options (widget-get widget :options))
2881 (other `(editable-list :inline t
2883 (symbol :format "%t: %v "
2886 (sexp :tag "Value"))))
2889 `((checklist :inline t
2890 ,@(mapcar 'custom-plist-process-option options))
2893 (widget-put widget :args args)
2896 (defun custom-plist-process-option (entry)
2898 (const :tag "Property"
2902 (sexp :tag "Value")))
2904 ;;; The `custom-group-link' Widget.
2906 (define-widget 'custom-group-link 'link
2907 "Show parent in other window when activated."
2908 :help-echo 'custom-group-link-help-echo
2909 :action 'custom-group-link-action)
2911 (defun custom-group-link-help-echo (widget)
2912 (concat "Create customization buffer for the `"
2913 (custom-unlispify-tag-name (widget-value widget))
2916 (defun custom-group-link-action (widget &rest ignore)
2917 (customize-group (widget-value widget)))
2919 ;;; The `custom-group' Widget.
2921 (defcustom custom-group-tag-faces nil
2922 ;; In XEmacs, this ought to play games with font size.
2923 "Face used for group tags.
2924 The first member is used for level 1 groups, the second for level 2,
2925 and so forth. The remaining group tags are shown with
2926 `custom-group-tag-face'."
2927 :type '(repeat face)
2928 :group 'custom-faces)
2930 (defface custom-group-tag-face-1 '((((class color)
2932 (:foreground "pink" :underline t))
2935 (:foreground "red" :underline t))
2937 "Face used for group tags.")
2939 (defface custom-group-tag-face '((((class color)
2941 (:foreground "light blue" :underline t))
2944 (:foreground "blue" :underline t))
2946 "Face used for low level group tags."
2947 :group 'custom-faces)
2949 (define-widget 'custom-group 'custom
2952 :sample-face-get 'custom-group-sample-face-get
2953 :documentation-property 'group-documentation
2954 :help-echo "Set or reset all members of this group"
2955 :value-create 'custom-group-value-create
2956 :action 'custom-group-action
2957 :custom-category 'group
2958 :custom-set 'custom-group-set
2959 :custom-pre-save 'custom-group-pre-save
2960 :custom-save 'custom-group-save
2961 :custom-post-save 'custom-group-post-save
2962 :custom-reset-current 'custom-group-reset-current
2963 :custom-reset-saved 'custom-group-reset-saved
2964 :custom-pre-reset-standard 'custom-group-pre-reset-standard
2965 :custom-reset-standard 'custom-group-reset-standard
2966 :custom-post-reset-standard 'custom-group-post-reset-standard
2967 :custom-menu 'custom-group-menu-create)
2969 (defun custom-group-sample-face-get (widget)
2970 ;; Use :sample-face.
2971 (or (nth (1- (widget-get widget :custom-level)) custom-group-tag-faces)
2972 'custom-group-tag-face))
2974 (define-widget 'custom-group-visibility 'visibility
2975 "An indicator and manipulator for hidden group contents."
2976 :create 'custom-group-visibility-create)
2978 (defun custom-group-visibility-create (widget)
2979 (let ((visible (widget-value widget)))
2981 (insert "--------")))
2982 (widget-default-create widget))
2984 (defun custom-group-members (symbol groups-only)
2985 "Return SYMBOL's custom group members.
2986 If GROUPS-ONLY non-nil, return only those members that are groups."
2987 (if (not groups-only)
2988 (get symbol 'custom-group)
2990 (dolist (entry (get symbol 'custom-group) (nreverse members))
2991 (when (eq (nth 1 entry) 'custom-group)
2992 (push entry members))))))
2994 (defun custom-group-value-create (widget)
2995 "Insert a customize group for WIDGET in the current buffer."
2996 (let* ((state (widget-get widget :custom-state))
2997 (level (widget-get widget :custom-level))
2998 ;; (indent (widget-get widget :indent))
2999 (prefix (widget-get widget :custom-prefix))
3000 (buttons (widget-get widget :buttons))
3001 (tag (widget-get widget :tag))
3002 (symbol (widget-value widget))
3003 (members (custom-group-members symbol
3004 (and (eq custom-buffer-style 'tree)
3005 custom-browse-only-groups))))
3006 (cond ((and (eq custom-buffer-style 'tree)
3008 (or members (custom-unloaded-widget-p widget)))
3009 (custom-browse-insert-prefix prefix)
3010 (push (widget-create-child-and-convert
3011 widget 'custom-browse-visibility
3012 ;; :tag-glyph "plus"
3016 ;; (widget-glyph-insert nil "-- " "horizontal")
3017 (push (widget-create-child-and-convert
3018 widget 'custom-browse-group-tag)
3020 (insert " " tag "\n")
3021 (widget-put widget :buttons buttons))
3022 ((and (eq custom-buffer-style 'tree)
3023 (zerop (length members)))
3024 (custom-browse-insert-prefix prefix)
3026 ;; (widget-glyph-insert nil "[ ]" "empty")
3027 ;; (widget-glyph-insert nil "-- " "horizontal")
3028 (push (widget-create-child-and-convert
3029 widget 'custom-browse-group-tag)
3031 (insert " " tag "\n")
3032 (widget-put widget :buttons buttons))
3033 ((eq custom-buffer-style 'tree)
3034 (custom-browse-insert-prefix prefix)
3035 (custom-load-widget widget)
3036 (if (zerop (length members))
3038 (custom-browse-insert-prefix prefix)
3040 ;; (widget-glyph-insert nil "[ ]" "empty")
3041 ;; (widget-glyph-insert nil "-- " "horizontal")
3042 (push (widget-create-child-and-convert
3043 widget 'custom-browse-group-tag)
3045 (insert " " tag "\n")
3046 (widget-put widget :buttons buttons))
3047 (push (widget-create-child-and-convert
3048 widget 'custom-browse-visibility
3049 ;; :tag-glyph "minus"
3053 ;; (widget-glyph-insert nil "-\\ " "top")
3054 (push (widget-create-child-and-convert
3055 widget 'custom-browse-group-tag)
3057 (insert " " tag "\n")
3058 (widget-put widget :buttons buttons)
3059 (message "Creating group...")
3060 (let* ((members (custom-sort-items members
3061 custom-browse-sort-alphabetically
3062 custom-browse-order-groups))
3063 (prefixes (widget-get widget :custom-prefixes))
3064 (custom-prefix-list (custom-prefix-add symbol prefixes))
3065 (extra-prefix (if (widget-get widget :custom-last)
3068 (prefix (concat prefix extra-prefix))
3071 (setq entry (car members)
3072 members (cdr members))
3073 (push (widget-create-child-and-convert
3074 widget (nth 1 entry)
3076 :tag (custom-unlispify-tag-name (nth 0 entry))
3077 :custom-prefixes custom-prefix-list
3078 :custom-level (1+ level)
3079 :custom-last (null members)
3080 :value (nth 0 entry)
3081 :custom-prefix prefix)
3083 (widget-put widget :children (reverse children)))
3084 (message "Creating group...done")))
3087 ;; Create level indicator.
3088 (unless (eq custom-buffer-style 'links)
3089 (insert-char ?\ (* custom-buffer-indent (1- level)))
3091 ;; Create link indicator.
3092 (when (eq custom-buffer-style 'links)
3094 (push (widget-create-child-and-convert
3095 widget 'custom-group-link
3097 :tag-glyph '("open-up" "open-down")
3102 (let ((begin (point)))
3104 (widget-specify-sample widget begin (point)))
3106 ;; Create visibility indicator.
3107 (unless (eq custom-buffer-style 'links)
3109 (push (widget-create-child-and-convert
3110 widget 'custom-group-visibility
3111 :help-echo "Show members of this group"
3112 :action 'custom-toggle-parent
3113 (not (eq state 'hidden)))
3116 ;; Create magic button.
3117 (let ((magic (widget-create-child-and-convert
3118 widget 'custom-magic nil)))
3119 (widget-put widget :custom-magic magic)
3120 (push magic buttons))
3122 (widget-put widget :buttons buttons)
3123 ;; Insert documentation.
3124 (if (and (eq custom-buffer-style 'links) (> level 1))
3125 (widget-put widget :documentation-indent 0))
3126 (widget-default-format-handler widget ?h))
3129 (custom-load-widget widget)
3131 (setq members (custom-group-members
3132 symbol (and (eq custom-buffer-style 'tree)
3133 custom-browse-only-groups)))
3134 ;; Add parent groups references above the group.
3135 (if t ;;; This should test that the buffer
3136 ;;; was made to display a group.
3138 (if (custom-add-parent-links widget
3139 "Go to parent group:")
3141 ;; Create level indicator.
3142 (insert-char ?\ (* custom-buffer-indent (1- level)))
3145 (let ((start (point)))
3147 (widget-specify-sample widget start (point)))
3149 ;; Create visibility indicator.
3150 (unless (eq custom-buffer-style 'links)
3152 (push (widget-create-child-and-convert
3154 :help-echo "Hide members of this group"
3155 :action 'custom-toggle-parent
3156 (not (eq state 'hidden)))
3159 ;; Create more dashes.
3160 ;; Use 76 instead of 75 to compensate for the temporary "<"
3161 ;; added by `widget-insert'.
3162 (insert-char ?- (- 76 (current-column)
3163 (* custom-buffer-indent level)))
3165 ;; Create magic button.
3166 (let ((magic (widget-create-child-and-convert
3167 widget 'custom-magic
3170 (widget-put widget :custom-magic magic)
3171 (push magic buttons))
3173 (widget-put widget :buttons buttons)
3174 ;; Insert documentation.
3175 (widget-default-format-handler widget ?h)
3177 (if nil ;;; This should test that the buffer
3178 ;;; was not made to display a group.
3180 (insert-char ?\ custom-buffer-indent)
3181 (custom-add-parent-links widget)))
3182 (custom-add-see-also widget
3183 (make-string (* custom-buffer-indent level)
3186 (message "Creating group...")
3187 (let* ((members (custom-sort-items members
3188 custom-buffer-sort-alphabetically
3189 custom-buffer-order-groups))
3190 (prefixes (widget-get widget :custom-prefixes))
3191 (custom-prefix-list (custom-prefix-add symbol prefixes))
3192 (length (length members))
3196 (widget-insert "\n")
3197 (when (zerop (% count custom-skip-messages))
3201 Creating group members... %2d%%"
3202 (/ (* 100.0 count) length))))
3205 (widget-create-child-and-convert
3206 widget (nth 1 entry)
3208 :tag (custom-unlispify-tag-name
3210 :custom-prefixes custom-prefix-list
3211 :custom-level (1+ level)
3212 :value (nth 0 entry))
3213 (unless (eq (preceding-char) ?\n)
3214 (widget-insert "\n"))))
3216 (message "Creating group magic...")
3217 (mapc 'custom-magic-reset children)
3218 (message "Creating group state...")
3219 (widget-put widget :children children)
3220 (custom-group-state-update widget)
3221 (message "Creating group... done"))
3224 (insert-char ?\ (* custom-buffer-indent (1- level)))
3225 (insert "\\- " (widget-get widget :tag) " group end ")
3226 (insert-char ?- (- 75 (current-column) (* custom-buffer-indent level)))
3229 (defvar custom-group-menu
3230 '(("Set for Current Session" custom-group-set
3232 (eq (widget-get widget :custom-state) 'modified)))
3233 ("Save for Future Sessions" custom-group-save
3235 (memq (widget-get widget :custom-state) '(modified set))))
3236 ("Reset to Current" custom-group-reset-current
3238 (memq (widget-get widget :custom-state) '(modified))))
3239 ("Reset to Saved" custom-group-reset-saved
3241 (memq (widget-get widget :custom-state) '(modified set))))
3242 ("Reset to standard setting" custom-group-reset-standard
3244 (memq (widget-get widget :custom-state) '(modified set saved)))))
3245 "Alist of actions for the `custom-group' widget.
3246 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3247 the menu entry, ACTION is the function to call on the widget when the
3248 menu is selected, and FILTER is a predicate which takes a `custom-group'
3249 widget as an argument, and returns non-nil if ACTION is valid on that
3250 widget. If FILTER is nil, ACTION is always valid.")
3252 (defun custom-group-action (widget &optional event)
3253 "Show the menu for `custom-group' WIDGET.
3254 Optional EVENT is the location for the menu."
3255 (if (eq (widget-get widget :custom-state) 'hidden)
3256 (custom-toggle-hide widget)
3257 (let* ((completion-ignore-case t)
3258 (answer (widget-choose (concat "Operation on "
3259 (custom-unlispify-tag-name
3260 (widget-get widget :value)))
3261 (custom-menu-filter custom-group-menu
3265 (funcall answer widget)))))
3267 (defun custom-group-set (widget)
3268 "Set changes in all modified group members."
3269 (let ((children (widget-get widget :children)))
3270 (mapc (lambda (child)
3271 (when (eq (widget-get child :custom-state) 'modified)
3272 (widget-apply child :custom-set)))
3275 (defun custom-group-pre-save (widget)
3276 "Prepare for saving all modified group members."
3277 (let ((children (widget-get widget :children)))
3278 (mapc (lambda (child)
3279 (when (memq (widget-get child :custom-state) '(modified set))
3280 (widget-apply child :custom-pre-save)))
3283 (defun custom-group-post-save (widget)
3284 "Save all modified group members."
3285 (let ((children (widget-get widget :children)))
3286 (mapc (lambda (child)
3287 (when (memq (widget-get child :custom-state) '(modified set))
3288 (widget-apply child :custom-post-save)))
3291 (defun custom-group-save (widget)
3292 "Save all modified group members."
3293 (custom-group-pre-save widget)
3295 (custom-group-post-save widget))
3297 (defun custom-group-reset-current (widget)
3298 "Reset all modified group members."
3299 (let ((children (widget-get widget :children)))
3300 (mapc (lambda (child)
3301 (when (eq (widget-get child :custom-state) 'modified)
3302 (widget-apply child :custom-reset-current)))
3305 (defun custom-group-reset-saved (widget)
3306 "Reset all modified or set group members."
3307 (let ((children (widget-get widget :children)))
3308 (mapc (lambda (child)
3309 (when (memq (widget-get child :custom-state) '(modified set))
3310 (widget-apply child :custom-reset-saved)))
3313 ;; This function returns non nil when we need to re-save the options --dv.
3314 (defun custom-group-pre-reset-standard (widget)
3315 "Prepare for resetting all modified, set, or saved group members."
3316 (let ((children (widget-get widget :children))
3318 (mapc (lambda (child)
3319 (when (memq (widget-get child :custom-state)
3320 '(modified set saved))
3321 (and (widget-apply child :custom-pre-reset-standard)
3322 (setq must-save t))))
3327 (defun custom-group-post-reset-standard (widget)
3328 "Finish resetting all modified, set, or saved group members."
3329 (let ((children (widget-get widget :children)))
3330 (mapc (lambda (child)
3331 (when (memq (widget-get child :custom-state)
3332 '(modified set saved))
3333 (widget-apply child :custom-post-reset-standard)))
3336 (defun custom-group-reset-standard (widget)
3337 "Reset all modified, set, or saved group members."
3338 (when (custom-group-pre-reset-standard widget)
3340 (custom-group-post-reset-standard widget))
3342 (defun custom-group-state-update (widget)
3344 (unless (eq (widget-get widget :custom-state) 'hidden)
3345 (let* ((children (widget-get widget :children))
3346 (states (mapcar (lambda (child)
3347 (widget-get child :custom-state))
3349 (magics custom-magic-alist)
3352 (let ((magic (car (car magics))))
3353 (if (and (not (eq magic 'hidden))
3354 (memq magic states))
3357 (setq magics (cdr magics)))))
3358 (widget-put widget :custom-state found)))
3359 (custom-magic-reset widget))
3361 (defun custom-save-delete (symbol)
3362 "Delete the call to SYMBOL form in `custom-file'.
3363 Leave point at the location of the call, or after the last expression."
3364 (let ((find-file-hooks nil)
3365 (auto-mode-alist nil))
3366 (set-buffer (find-file-noselect custom-file)))
3367 (goto-char (point-min))
3370 (let ((sexp (condition-case nil
3371 (read (current-buffer))
3372 (end-of-file (throw 'found nil)))))
3373 (when (and (listp sexp)
3374 (eq (car sexp) symbol))
3375 (delete-region (save-excursion
3379 (throw 'found nil))))))
3381 (defun custom-save-variables ()
3382 "Save all customized variables in `custom-file'."
3384 (custom-save-delete 'custom-load-themes)
3385 (custom-save-delete 'custom-reset-variables)
3386 (custom-save-delete 'custom-set-variables)
3387 (custom-save-loaded-themes)
3388 (custom-save-resets 'theme-value 'custom-reset-variables nil)
3389 (let ((standard-output (current-buffer)))
3392 (princ "(custom-set-variables")
3393 (mapatoms (lambda (symbol)
3394 (let ((spec (car-safe (get symbol 'theme-value)))
3395 (requests (get symbol 'custom-requests))
3396 (now (not (or (get symbol 'standard-value)
3397 (and (not (boundp symbol))
3398 (not (eq (get symbol 'force-value)
3400 (comment (get symbol 'saved-variable-comment)))
3402 (eq (car spec) 'user)
3403 (eq (second spec) 'set))
3405 ;; support non-themed vars
3406 (and (null spec) (get symbol 'saved-value)))
3410 ;; This comment stuff is in the way ####
3411 ;; Is (eq (third spec) (car saved-value)) ????
3412 ;; (prin1 (third spec))
3413 (prin1 (car (get symbol 'saved-value)))
3414 (when (or now requests comment)
3415 (princ (if now " t" " nil")))
3416 (when (or comment requests)
3424 (unless (looking-at "\n")
3427 (defvar custom-save-face-ignoring nil)
3429 (defun custom-save-face-internal (symbol)
3430 (let ((theme-spec (car-safe (get symbol 'theme-face)))
3431 (comment (get symbol 'saved-face-comment))
3432 (now (not (or (get symbol 'face-defface-spec)
3433 (and (not (find-face symbol))
3434 (not (eq (get symbol 'force-face) 'rogue)))))))
3435 (when (or (and (not (memq symbol custom-save-face-ignoring))
3436 ;; Don't print default face here.
3438 (eq (car theme-spec) 'user)
3439 (eq (second theme-spec) 'set))
3440 ;; cope with non-themed faces
3441 (and (null theme-spec)
3442 (get symbol 'saved-face))))
3447 (prin1 (get symbol 'saved-face))
3448 (if (or comment now)
3449 (princ (if now " t" " nil")))
3455 (defun custom-save-faces ()
3456 "Save all customized faces in `custom-file'."
3458 (custom-save-delete 'custom-reset-faces)
3459 (custom-save-delete 'custom-set-faces)
3460 (custom-save-resets 'theme-face 'custom-reset-faces '(default))
3461 (let ((standard-output (current-buffer)))
3464 (princ "(custom-set-faces")
3465 ;; The default face must be first, since it affects the others.
3466 (custom-save-face-internal 'default)
3467 (let ((custom-save-face-ignoring '(default)))
3468 (mapatoms #'custom-save-face-internal))
3470 (unless (looking-at "\n")
3473 (defun custom-save-resets (property setter special)
3474 (let (started-writing ignored-special)
3475 (setq ignored-special ignored-special) ;; suppress byte-compiler warning
3476 ;; (custom-save-delete setter) Done by caller
3477 (let ((standard-output (current-buffer))
3478 (mapper `(lambda (object)
3479 (let ((spec (car-safe (get object (quote ,property)))))
3480 (when (and (not (memq object ignored-special))
3481 (eq (car spec) 'user)
3482 (eq (second spec) 'reset))
3483 ;; Do not write reset statements unless necessary.
3484 (unless started-writing
3485 (setq started-writing t)
3489 (princ (quote ,setter))
3493 (prin1 (third spec))
3495 (mapc mapper special)
3496 (setq ignored-special special)
3498 (when started-writing
3503 (defun custom-save-loaded-themes ()
3504 (let ((themes (reverse (get 'user 'theme-loads-themes)))
3505 (standard-output (current-buffer)))
3507 (unless (bolp) (princ "\n"))
3508 (princ "(custom-load-themes")
3509 (mapc (lambda (theme)
3511 (prin1 theme)) themes)
3515 (defun customize-save-customized ()
3516 "Save all user options which have been set in this session."
3518 (mapatoms (lambda (symbol)
3519 (let ((face (get symbol 'customized-face))
3520 (value (get symbol 'customized-value))
3521 (face-comment (get symbol 'customized-face-comment))
3523 (get symbol 'customized-variable-comment)))
3525 (put symbol 'saved-face face)
3526 (custom-push-theme 'theme-face symbol 'user 'set value)
3527 (put symbol 'customized-face nil))
3529 (put symbol 'saved-value value)
3530 (custom-push-theme 'theme-value symbol 'user 'set value)
3531 (put symbol 'customized-value nil))
3532 (when variable-comment
3533 (put symbol 'saved-variable-comment variable-comment)
3534 (put symbol 'customized-variable-comment nil))
3536 (put symbol 'saved-face-comment face-comment)
3537 (put symbol 'customized-face-comment nil)))))
3538 ;; We really should update all custom buffers here.
3542 (defun custom-save-all ()
3543 "Save all customizations in `custom-file'."
3544 (let ((inhibit-read-only t))
3545 (custom-save-variables)
3547 (let ((find-file-hooks nil)
3549 (with-current-buffer (find-file-noselect custom-file)
3553 ;;; The Customize Menu.
3557 (defun custom-face-menu-create (widget symbol)
3558 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
3559 (vector (custom-unlispify-menu-entry symbol)
3560 `(customize-face ',symbol)
3563 (defun custom-variable-menu-create (widget symbol)
3564 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
3565 (let ((type (get symbol 'custom-type)))
3566 (unless (listp type)
3567 (setq type (list type)))
3568 (if (and type (widget-get type :custom-menu))
3569 (widget-apply type :custom-menu symbol)
3570 (vector (custom-unlispify-menu-entry symbol)
3571 `(customize-variable ',symbol)
3574 ;; Add checkboxes to boolean variable entries.
3575 (widget-put (get 'boolean 'widget-type)
3576 :custom-menu (lambda (widget symbol)
3577 `[,(custom-unlispify-menu-entry symbol)
3578 (customize-variable ',symbol)
3580 :selected ,symbol]))
3582 ;; XEmacs can create menus dynamically.
3583 (defun custom-group-menu-create (widget symbol)
3584 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
3585 `( ,(custom-unlispify-menu-entry symbol t)
3586 :filter (lambda (&rest junk)
3587 (let ((item (custom-menu-create ',symbol)))
3593 (defun custom-menu-create (symbol)
3594 "Create menu for customization group SYMBOL.
3595 The menu is in a format applicable to `easy-menu-define'."
3596 (let* ((item (vector (custom-unlispify-menu-entry symbol)
3597 `(customize-group ',symbol)
3599 ;; Item is the entry for creating a menu buffer for SYMBOL.
3600 ;; We may nest, if the menu is not too big.
3601 (custom-load-symbol symbol)
3602 (if (< (length (get symbol 'custom-group)) widget-menu-max-size)
3603 ;; The menu is not too big.
3604 (let ((custom-prefix-list (custom-prefix-add symbol
3605 custom-prefix-list))
3606 (members (custom-sort-items (get symbol 'custom-group)
3607 custom-menu-sort-alphabetically
3608 custom-menu-order-groups)))
3610 `(,(custom-unlispify-menu-entry symbol t)
3613 ,@(mapcar (lambda (entry)
3614 (widget-apply (if (listp (nth 1 entry))
3616 (list (nth 1 entry)))
3617 :custom-menu (nth 0 entry)))
3619 ;; The menu was too big.
3623 (defun customize-menu-create (symbol &optional name)
3624 "Return a customize menu for customization group SYMBOL.
3625 If optional NAME is given, use that as the name of the menu.
3626 Otherwise the menu will be named `Customize'.
3627 The format is suitable for use with `easy-menu-define'."
3629 (setq name "Customize"))
3631 :filter (lambda (&rest junk)
3632 (cdr (custom-menu-create ',symbol)))))
3634 ;;; The Custom Mode.
3636 (defvar custom-mode-map nil
3637 "Keymap for `custom-mode'.")
3639 (unless custom-mode-map
3640 (setq custom-mode-map (make-sparse-keymap))
3641 (set-keymap-parents custom-mode-map widget-keymap)
3642 (suppress-keymap custom-mode-map)
3643 (define-key custom-mode-map " " 'scroll-up)
3644 (define-key custom-mode-map [delete] 'scroll-down)
3645 (define-key custom-mode-map "q" 'Custom-buffer-done)
3646 (define-key custom-mode-map "u" 'Custom-goto-parent)
3647 (define-key custom-mode-map "n" 'widget-forward)
3648 (define-key custom-mode-map "p" 'widget-backward))
3650 (easy-menu-define Custom-mode-menu
3652 "Menu used in customization buffers."
3654 ,(customize-menu-create 'customize)
3655 ["Set" Custom-set t]
3656 ["Save" Custom-save t]
3657 ["Reset to Current" Custom-reset-current t]
3658 ["Reset to Saved" Custom-reset-saved t]
3659 ["Reset to Standard Settings" Custom-reset-standard t]
3660 ["Info" (Info-goto-node "(xemacs)Easy Customization") t]))
3662 (defun Custom-goto-parent ()
3663 "Go to the parent group listed at the top of this buffer.
3664 If several parents are listed, go to the first of them."
3667 (goto-char (point-min))
3668 (if (search-forward "\nGo to parent group: " nil t)
3669 (let* ((button (get-char-property (point) 'button))
3670 (parent (downcase (widget-get button :tag))))
3671 (customize-group parent)))))
3673 (defcustom custom-mode-hook nil
3674 "Hook called when entering custom-mode."
3676 :group 'custom-buffer )
3678 (defun custom-state-buffer-message (widget)
3679 (if (eq (widget-get (widget-get widget :parent) :custom-state) 'modified)
3681 "To install your edits, invoke [State] and choose the Set operation")))
3683 (defun custom-mode ()
3684 "Major mode for editing customization buffers.
3686 The following commands are available:
3688 Move to next button or editable field. \\[widget-forward]
3689 Move to previous button or editable field. \\[widget-backward]
3690 \\<widget-field-keymap>\
3691 Complete content of editable text field. \\[widget-complete]
3692 \\<custom-mode-map>\
3693 Invoke button under point. \\[widget-button-press]
3694 Set all modifications. \\[Custom-set]
3695 Make all modifications default. \\[Custom-save]
3696 Reset all modified options. \\[Custom-reset-current]
3697 Reset all modified or set options. \\[Custom-reset-saved]
3698 Reset all options. \\[Custom-reset-standard]
3700 Entry to this mode calls the value of `custom-mode-hook'
3701 if that value is non-nil."
3702 (kill-all-local-variables)
3703 (setq major-mode 'custom-mode
3705 (use-local-map custom-mode-map)
3706 (easy-menu-add Custom-mode-menu)
3707 (make-local-variable 'custom-options)
3708 (make-local-variable 'widget-documentation-face)
3709 (setq widget-documentation-face 'custom-documentation-face)
3710 (make-local-variable 'widget-button-face)
3711 (setq widget-button-face 'custom-button-face)
3712 (make-local-hook 'widget-edit-functions)
3713 (add-hook 'widget-edit-functions 'custom-state-buffer-message nil t)
3714 (run-hooks 'custom-mode-hook))
3718 (defun custom-migrate-custom-file (new-custom-file-name)
3719 "Migrate custom file from home directory."
3720 (mapc 'custom-save-delete
3721 '(custom-load-themes custom-reset-variables
3722 custom-set-variables
3724 custom-reset-faces))
3725 (with-current-buffer (find-file-noselect custom-file)
3727 (setq custom-file new-custom-file-name)
3734 ;; cus-edit.el ends here