1 ;;; cus-edit.el --- Tools for customizating Emacs and Lisp packages.
3 ;; Copyright (C) 1996, 1997, 1999 Free Software Foundation, Inc.
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
6 ;; Keywords: help, faces
7 ;; X-URL: http://www.dina.kvl.dk/~abraham/custom/ (probably obsolete)
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
28 ;; This file implements the code to create and edit customize buffers.
32 ;; No commands should have names starting with `custom-' because
33 ;; that interferes with completion. Use `customize-' for commands
34 ;; that the user will run with M-x, and `Custom-' for interactive commands.
43 (defvar custom-versions-load-alist)) ; from cus-load
53 (put 'custom-define-hook 'custom-type 'hook)
54 (put 'custom-define-hook 'standard-value '(nil))
55 (custom-add-to-group 'customize 'custom-define-hook 'custom-variable)
57 ;;; Customization Groups.
60 "Customization of the One True Editor."
61 :link '(custom-manual "(emacs)Top"))
63 ;; Most of these groups are stolen from `finder.el',
65 "Basic text editing facilities."
69 "Abbreviation handling, typing shortcuts, macros."
73 (defgroup matching nil
74 "Various sorts of searching and matching."
77 (defgroup emulations nil
78 "Emulations of other editors."
85 (defgroup outlines nil
86 "Support for hierarchical outlining."
89 (defgroup external nil
90 "Interfacing to external utilities."
94 "Code related to the `bib' bibliography processor."
98 (defgroup processes nil
99 "Process, subshell, compilation, and job control support."
103 (defgroup convenience nil
104 "Convenience features for faster editing."
107 (defgroup programming nil
108 "Support for programming in other languages."
111 (defgroup languages nil
112 "Specialized modes for editing programming languages."
116 "Lisp support, including Emacs Lisp."
121 "Support for the C language and related languages."
129 "Support for object-oriented programming."
132 (defgroup applications nil
133 "Applications written in Emacs."
136 (defgroup calendar nil
137 "Calendar and time management support."
138 :group 'applications)
141 "Modes for electronic-mail handling."
142 :group 'applications)
145 "Support for netnews reading and posting."
146 :group 'applications)
149 "Games, jokes and amusements."
150 :group 'applications)
152 (defgroup development nil
153 "Support for further development of Emacs."
157 "Support for Emacs documentation."
160 (defgroup extensions nil
161 "Emacs Lisp language extensions."
164 (defgroup internal nil
165 "Code for Emacs internals, build process, defaults."
169 "Maintenance aids for the Emacs development group."
173 (defgroup environment nil
174 "Fitting Emacs with its environment."
178 "Communications, networking, remote access to files."
182 (defgroup hardware nil
183 "Support for interfacing with exotic hardware."
186 (defgroup terminals nil
187 "Support for terminal types."
191 "Front-ends/assistants for, or emulators of, UNIX features."
195 "Support code for vms."
199 "Internationalization and alternate character-set support."
204 "The X Window system."
208 "Support for Emacs frames and window systems."
212 "Support editing files of data."
216 "Support editing files."
224 "Code related to the TeX formatter."
228 "Support for multiple fonts."
231 (defgroup hypermedia nil
232 "Support for links between text or other media types."
236 "Support for on-line help systems."
239 (defgroup multimedia nil
240 "Non-textual support, specifically images and sound."
244 "Code local to your site."
247 (defgroup customize '((widgets custom-group))
248 "Customization of the Customization support."
249 :link '(custom-manual "(elisp)Customization")
250 :link '(url-link :tag "(Old?) Development Page"
251 "http://www.dina.kvl.dk/~abraham/custom/")
255 (defgroup custom-faces nil
256 "Faces used by customize."
260 (defgroup custom-browse nil
261 "Control customize browser."
265 (defgroup custom-buffer nil
266 "Control customize buffers."
270 (defgroup custom-menu nil
271 "Control customize menus."
275 (defgroup abbrev-mode nil
276 "Word abbreviations mode."
280 "Storage allocation and gc for GNU Emacs Lisp interpreter."
281 :tag "Storage Allocation"
285 "Undoing changes in buffers."
288 (defgroup modeline nil
289 "Content of the modeline."
293 "Indenting and filling text."
296 (defgroup editing-basics nil
297 "Most basic editing facilities."
300 (defgroup display nil
301 "How characters are displayed in buffers."
304 (defgroup execute nil
305 "Executing external commands."
308 (defgroup installation nil
309 "The Emacs installation."
317 "Internal Emacs limits."
321 "Debugging Emacs itself."
324 (defgroup minibuffer nil
325 "Controling the behaviour of the minibuffer."
328 (defgroup keyboard nil
329 "Input from the keyboard."
333 "Input from the mouse."
337 "Input from the menus."
340 (defgroup auto-save nil
341 "Preventing accidential loss of data."
344 (defgroup processes-basics nil
345 "Basic stuff dealing with processes."
349 "MULE Emacs internationalization."
352 (defgroup windows nil
353 "Windows within a frame."
358 (defun custom-quote (sexp)
359 "Quote SEXP iff it is not self quoting."
360 (if (or (memq sexp '(t nil))
362 (eq (aref (symbol-name sexp) 0) ?:))
364 (memq (car sexp) '(lambda)))
368 ;;; (and (fboundp 'characterp)
369 ;;; (characterp sexp))
374 (defun custom-split-regexp-maybe (regexp)
375 "If REGEXP is a string, split it to a list at `\\|'.
376 You can get the original back with from the result with:
377 (mapconcat 'identity result \"\\|\")
379 IF REGEXP is not a string, return it unchanged."
383 (while (string-match "\\\\|" regexp start)
384 (setq all (cons (substring regexp start (match-beginning 0)) all)
385 start (match-end 0)))
386 (nreverse (cons (substring regexp start) all)))
389 (defun custom-variable-prompt ()
390 ;; Code stolen from `help.el'.
391 "Prompt for a variable, defaulting to the variable at point.
392 Return a list suitable for use in `interactive'."
393 (let ((v (variable-at-point))
394 (enable-recursive-minibuffers t)
396 (setq val (completing-read
398 (format "Customize option: (default %s) " v)
399 "Customize variable: ")
400 obarray (lambda (symbol)
402 (or (get symbol 'custom-type)
403 (get symbol 'custom-loads)
404 (user-variable-p symbol)))) t))
405 (list (if (equal val "")
406 (if (symbolp v) v nil)
409 (defun custom-menu-filter (menu widget)
410 "Convert MENU to the form used by `widget-choose'.
411 MENU should be in the same format as `custom-variable-menu'.
412 WIDGET is the widget to apply the filter entries of MENU on."
414 current name action filter)
416 (setq current (car menu)
418 action (nth 1 current)
419 filter (nth 2 current)
421 (if (or (null filter) (funcall filter widget))
422 (push (cons name action) result)
428 (defvar custom-prefix-list nil
429 "List of prefixes that should be ignored by `custom-unlispify'")
431 (defcustom custom-unlispify-menu-entries t
432 "Display menu entries as words instead of symbols if non nil."
436 (defcustom custom-unlispify-remove-prefixes nil
437 "Non-nil means remove group prefixes from option names in buffer."
441 (defun custom-unlispify-menu-entry (symbol &optional no-suffix)
442 "Convert symbol into a menu entry."
443 (cond ((not custom-unlispify-menu-entries)
444 (symbol-name symbol))
445 ((get symbol 'custom-tag)
447 (get symbol 'custom-tag)
448 (concat (get symbol 'custom-tag) "...")))
451 (set-buffer (get-buffer-create " *Custom-Work*"))
453 (princ symbol (current-buffer))
454 (goto-char (point-min))
455 (when (and (eq (get symbol 'custom-type) 'boolean)
456 (re-search-forward "-p\\'" nil t))
457 (replace-match "" t t)
458 (goto-char (point-min)))
459 (if custom-unlispify-remove-prefixes
460 (let ((prefixes custom-prefix-list)
463 (setq prefix (car prefixes))
464 (if (search-forward prefix (+ (point) (length prefix)) t)
467 (delete-region (point-min) (point)))
468 (setq prefixes (cdr prefixes))))))
469 (subst-char-in-region (point-min) (point-max) ?- ?\ t)
470 (capitalize-region (point-min) (point-max))
472 (goto-char (point-max))
476 (defcustom custom-unlispify-tag-names t
477 "Display tag names as words instead of symbols if non nil."
478 :group 'custom-buffer
481 (defun custom-unlispify-tag-name (symbol)
482 "Convert symbol into a menu entry."
483 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names))
484 (custom-unlispify-menu-entry symbol t)))
486 (defun custom-prefix-add (symbol prefixes)
487 ;; Addd SYMBOL to list of ignored PREFIXES.
488 (cons (or (get symbol 'custom-prefix)
489 (concat (symbol-name symbol) "-"))
494 (defcustom custom-guess-name-alist
499 ("-function\\'" function)
500 ("-functions\\'" (repeat function))
501 ("-list\\'" (repeat sexp))
502 ("-alist\\'" (repeat (cons sexp sexp))))
503 "Alist of (MATCH TYPE).
505 MATCH should be a regexp matching the name of a symbol, and TYPE should
506 be a widget suitable for editing the value of that symbol. The TYPE
507 of the first entry where MATCH matches the name of the symbol will be
510 This is used for guessing the type of variables not declared with
512 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
515 (defcustom custom-guess-doc-alist
516 '(("\\`\\*?Non-nil " boolean))
517 "Alist of (MATCH TYPE).
519 MATCH should be a regexp matching a documentation string, and TYPE
520 should be a widget suitable for editing the value of a variable with
521 that documentation string. The TYPE of the first entry where MATCH
522 matches the name of the symbol will be used.
524 This is used for guessing the type of variables not declared with
526 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
529 (defun custom-guess-type (symbol)
530 "Guess a widget suitable for editing the value of SYMBOL.
531 This is done by matching SYMBOL with `custom-guess-name-alist' and
532 if that fails, the doc string with `custom-guess-doc-alist'."
533 (let ((name (symbol-name symbol))
534 (names custom-guess-name-alist)
537 (setq current (car names)
539 (when (string-match (nth 0 current) name)
540 (setq found (nth 1 current)
543 (let ((doc (documentation-property symbol 'variable-documentation))
544 (docs custom-guess-doc-alist))
547 (setq current (car docs)
549 (when (string-match (nth 0 current) doc)
550 (setq found (nth 1 current)
556 (defcustom custom-browse-sort-alphabetically nil
557 "If non-nil, sort members of each customization group alphabetically."
559 :group 'custom-browse)
561 (defcustom custom-browse-order-groups nil
562 "If non-nil, order group members within each customization group.
563 If `first', order groups before non-groups.
564 If `last', order groups after non-groups."
565 :type '(choice (const first)
567 (const :tag "none" nil))
568 :group 'custom-browse)
570 (defcustom custom-browse-only-groups nil
571 "If non-nil, show group members only within each customization group."
573 :group 'custom-browse)
575 (defcustom custom-buffer-sort-alphabetically nil
576 "If non-nil, sort members of each customization group alphabetically."
578 :group 'custom-buffer)
580 (defcustom custom-buffer-order-groups 'last
581 "If non-nil, order group members within each customization group.
582 If `first', order groups before non-groups.
583 If `last', order groups after non-groups."
584 :type '(choice (const first)
586 (const :tag "none" nil))
587 :group 'custom-buffer)
589 (defcustom custom-menu-sort-alphabetically nil
590 "If non-nil, sort members of each customization group alphabetically."
594 (defcustom custom-menu-order-groups 'first
595 "If non-nil, order group members within each customization group.
596 If `first', order groups before non-groups.
597 If `last', order groups after non-groups."
598 :type '(choice (const first)
600 (const :tag "none" nil))
603 ;;;###autoload (add-hook 'same-window-regexps "\\`\\*Customiz.*\\*\\'")
605 (defun custom-sort-items (items sort-alphabetically order-groups)
606 "Return a sorted copy of ITEMS.
607 ITEMS should be a `custom-group' property.
608 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
609 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
610 groups after non-groups, if nil do not order groups at all."
611 (sort (copy-sequence items)
613 (let ((typea (nth 1 a)) (typeb (nth 1 b))
614 (namea (symbol-name (nth 0 a))) (nameb (symbol-name (nth 0 b))))
615 (cond ((not order-groups)
616 ;; Since we don't care about A and B order, maybe sort.
617 (when sort-alphabetically
618 (string-lessp namea nameb)))
619 ((eq typea 'custom-group)
620 ;; If B is also a group, maybe sort. Otherwise, order A and B.
621 (if (eq typeb 'custom-group)
622 (when sort-alphabetically
623 (string-lessp namea nameb))
624 (eq order-groups 'first)))
625 ((eq typeb 'custom-group)
626 ;; Since A cannot be a group, order A and B.
627 (eq order-groups 'last))
629 ;; Since A and B cannot be groups, sort.
630 (string-lessp namea nameb)))))))
632 ;;; Custom Mode Commands.
634 (defvar custom-options nil
635 "Customization widgets in the current buffer.")
638 "Set changes in all modified options."
640 (let ((children custom-options))
641 (mapcar (lambda (child)
642 (when (eq (widget-get child :custom-state) 'modified)
643 (widget-apply child :custom-set)))
646 (defun Custom-save ()
647 "Set all modified group members and save them."
649 (let ((children custom-options))
650 (mapcar (lambda (child)
651 (when (memq (widget-get child :custom-state)
652 '(modified set changed rogue))
653 (widget-apply child :custom-save)))
657 (defvar custom-reset-menu
658 '(("Current" . Custom-reset-current)
659 ("Saved" . Custom-reset-saved)
660 ("Standard Settings" . Custom-reset-standard))
661 "Alist of actions for the `Reset' button.
662 The key is a string containing the name of the action, the value is a
663 lisp function taking the widget as an element which will be called
664 when the action is chosen.")
666 (defun custom-reset (event)
667 "Select item from reset menu."
668 (let* ((completion-ignore-case t)
669 (answer (widget-choose "Reset to"
675 (defun Custom-reset-current (&rest ignore)
676 "Reset all modified group members to their current value."
678 (let ((children custom-options))
679 (mapcar (lambda (widget)
680 (and (default-boundp (widget-value widget))
681 (if (memq (widget-get widget :custom-state)
683 (widget-apply widget :custom-reset-current))))
686 (defun Custom-reset-saved (&rest ignore)
687 "Reset all modified or set group members to their saved value."
689 (let ((children custom-options))
690 (mapcar (lambda (widget)
691 (and (get (widget-value widget) 'saved-value)
692 (if (memq (widget-get widget :custom-state)
693 '(modified set changed rogue))
694 (widget-apply widget :custom-reset-saved))))
697 (defun Custom-reset-standard (&rest ignore)
698 "Reset all modified, set, or saved group members to their standard settings."
700 (let ((children custom-options))
701 (mapcar (lambda (widget)
702 (and (get (widget-value widget) 'standard-value)
703 (if (memq (widget-get widget :custom-state)
704 '(modified set changed saved rogue))
705 (widget-apply widget :custom-reset-standard))))
708 ;;; The Customize Commands
710 (defun custom-prompt-variable (prompt-var prompt-val &optional comment)
711 "Prompt for a variable and a value and return them as a list.
712 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
713 prompt for the value. The %s escape in PROMPT-VAL is replaced with
714 the name of the variable.
716 If the variable has a `variable-interactive' property, that is used as if
717 it were the arg to `interactive' (which see) to interactively read the value.
719 If the variable has a `custom-type' property, it must be a widget and the
720 `:prompt-value' property of that widget will be used for reading the value.
722 If optional COMMENT argument is non nil, also prompt for a comment and return
723 it as the third element in the list."
724 (let* ((var (read-variable prompt-var))
725 (minibuffer-help-form '(describe-variable var))
727 (let ((prop (get var 'variable-interactive))
728 (type (get var 'custom-type))
729 (prompt (format prompt-val var)))
731 (setq type (list type)))
733 ;; Use VAR's `variable-interactive' property
734 ;; as an interactive spec for prompting.
735 (call-interactively (list 'lambda '(arg)
736 (list 'interactive prop)
739 (widget-prompt-value type
745 (eval-minibuffer prompt))))))
748 (read-string "Comment: " (get var 'variable-comment)))
752 (defun customize-set-value (var val &optional comment)
753 "Set VARIABLE to VALUE. VALUE is a Lisp object.
755 If VARIABLE has a `variable-interactive' property, that is used as if
756 it were the arg to `interactive' (which see) to interactively read the value.
758 If VARIABLE has a `custom-type' property, it must be a widget and the
759 `:prompt-value' property of that widget will be used for reading the value.
761 If given a prefix (or a COMMENT argument), also prompt for a comment."
762 (interactive (custom-prompt-variable "Set variable: "
767 (cond ((string= comment "")
768 (put var 'variable-comment nil))
770 (put var 'variable-comment comment))))
773 (defun customize-set-variable (var val &optional comment)
774 "Set the default for VARIABLE to VALUE. VALUE is a Lisp object.
776 If VARIABLE has a `custom-set' property, that is used for setting
777 VARIABLE, otherwise `set-default' is used.
779 The `customized-value' property of the VARIABLE will be set to a list
780 with a quoted VALUE as its sole list member.
782 If VARIABLE has a `variable-interactive' property, that is used as if
783 it were the arg to `interactive' (which see) to interactively read the value.
785 If VARIABLE has a `custom-type' property, it must be a widget and the
786 `:prompt-value' property of that widget will be used for reading the value.
788 If given a prefix (or a COMMENT argument), also prompt for a comment."
789 (interactive (custom-prompt-variable "Set variable: "
790 "Set customized value for %s to: "
792 (funcall (or (get var 'custom-set) 'set-default) var val)
793 (put var 'customized-value (list (custom-quote val)))
794 (cond ((string= comment "")
795 (put var 'variable-comment nil)
796 (put var 'customized-variable-comment nil))
798 (put var 'variable-comment comment)
799 (put var 'customized-variable-comment comment))))
802 (defun customize-save-variable (var val &optional comment)
803 "Set the default for VARIABLE to VALUE, and save it for future sessions.
804 If VARIABLE has a `custom-set' property, that is used for setting
805 VARIABLE, otherwise `set-default' is used.
807 The `customized-value' property of the VARIABLE will be set to a list
808 with a quoted VALUE as its sole list member.
810 If VARIABLE has a `variable-interactive' property, that is used as if
811 it were the arg to `interactive' (which see) to interactively read the value.
813 If VARIABLE has a `custom-type' property, it must be a widget and the
814 `:prompt-value' property of that widget will be used for reading the value.
816 If given a prefix (or a COMMENT argument), also prompt for a comment."
817 (interactive (custom-prompt-variable "Set and ave variable: "
818 "Set and save value for %s as: "
820 (funcall (or (get var 'custom-set) 'set-default) var val)
821 (put var 'saved-value (list (custom-quote val)))
822 (cond ((string= comment "")
823 (put var 'variable-comment nil)
824 (put var 'saved-variable-comment nil))
826 (put var 'variable-comment comment)
827 (put var 'saved-variable-comment comment)))
832 "Select a customization buffer which you can use to set user options.
833 User options are structured into \"groups\".
834 Initially the top-level group `Emacs' and its immediate subgroups
835 are shown; the contents of those subgroups are initially hidden."
837 (customize-group 'emacs))
840 (defun customize-group (group)
841 "Customize GROUP, which must be a customization group."
842 (interactive (list (let ((completion-ignore-case t))
843 (completing-read "Customize group: (default emacs) "
846 (or (get symbol 'custom-loads)
847 (get symbol 'custom-group)))
849 (when (stringp group)
850 (if (string-equal "" group)
852 (setq group (intern group))))
853 (or (get group 'custom-group)
854 (custom-load-symbol group))
855 (let ((name (format "*Customize Group: %s*"
856 (custom-unlispify-tag-name group))))
857 (if (get-buffer name)
859 (custom-buffer-create (list (list group 'custom-group))
861 (concat " for group "
862 (custom-unlispify-tag-name group))))))
865 (defun customize-group-other-window (group)
866 "Customize GROUP, which must be a customization group."
867 (interactive (list (let ((completion-ignore-case t))
868 (completing-read "Customize group: (default emacs) "
871 (or (get symbol 'custom-loads)
872 (get symbol 'custom-group)))
874 (when (stringp group)
875 (if (string-equal "" group)
877 (setq group (intern group))))
878 (or (get group 'custom-group)
879 (custom-load-symbol group))
880 (let ((name (format "*Customize Group: %s*"
881 (custom-unlispify-tag-name group))))
882 (if (get-buffer name)
883 (let ((window (selected-window)))
885 (select-window window))
886 (custom-buffer-create-other-window
887 (list (list group 'custom-group))
889 (concat " for group "
890 (custom-unlispify-tag-name group))))))
893 (defalias 'customize-variable 'customize-option)
896 (defun customize-option (symbol)
897 "Customize SYMBOL, which must be a user option variable."
898 (interactive (custom-variable-prompt))
899 ;; If we don't have SYMBOL's real definition loaded,
901 (unless (get symbol 'custom-type)
902 (let ((loaddefs-file (locate-library "loaddefs.el" t))
904 ;; See if it is autoloaded from some library.
907 (insert-file-contents loaddefs-file)
908 (when (re-search-forward (concat "^(defvar " (symbol-name symbol))
910 (search-backward "\n;;; Generated autoloads from ")
911 (goto-char (match-end 0))
912 (setq file (buffer-substring (point)
913 (progn (end-of-line) (point)))))))
914 ;; If it is, load that library.
916 (when (string-match "\\.el\\'" file)
917 (setq file (substring file 0 (match-beginning 0))))
919 (unless (get symbol 'custom-type)
920 (error "Variable %s cannot be customized" symbol))
921 (custom-buffer-create (list (list symbol 'custom-variable))
922 (format "*Customize Option: %s*"
923 (custom-unlispify-tag-name symbol))))
925 (defvar customize-changed-options-previous-release "20.2"
926 "Version for `customize-changed-options' to refer back to by default.")
929 (defun customize-changed-options (since-version)
930 "Customize all user option variables changed in Emacs itself.
931 This includes new user option variables and faces, and new
932 customization groups, as well as older options and faces whose default
933 values have changed since the previous major Emacs release.
935 With argument SINCE-VERSION (a string), customize all user option
936 variables that were added (or their meanings were changed) since that
939 (interactive "sCustomize options changed, since version (default all versions): ")
940 (if (equal since-version "")
941 (setq since-version nil))
942 (unless since-version
943 (setq since-version customize-changed-options-previous-release))
946 (mapatoms (lambda (symbol)
947 (and (or (boundp symbol)
948 ;; For variables not yet loaded.
949 (get symbol 'standard-value)
950 ;; For groups the previous test fails, this one
951 ;; could be used to determine if symbol is a
952 ;; group. Is there a better way for this?
953 (get symbol 'group-documentation))
954 (let ((version (get symbol 'custom-version)))
956 (or (null since-version)
957 (customize-version-lessp since-version version))
958 (if (member version versions)
960 ;;; Collect all versions that we use.
961 (push version versions))))
963 ;; We have to set the right thing here,
964 ;; depending if we have a group or a
966 (if (get symbol 'group-documentation)
967 (cons (list symbol 'custom-group) found)
968 (cons (list symbol 'custom-variable) found))))))
970 (error "No user option defaults have been changed since Emacs %s"
975 (cdr (assoc (car versions) custom-versions-load-alist)))
977 (setq versions (cdr versions)))
978 (put 'custom-versions-load-alist 'custom-loads
979 ;; Get all the files that correspond to element from the
980 ;; VERSIONS list. This could use some simplification.
981 (apply 'nconc flist)))
982 ;; Because we set all the files needed to be loaded as a
983 ;; `custom-loads' property to `custom-versions-load-alist' this
984 ;; call will actually load them.
985 (custom-load-symbol 'custom-versions-load-alist)
987 (put 'custom-versions-load-alist 'custom-loads nil)
988 (custom-buffer-create (custom-sort-items found t 'first)
989 "*Customize Changed Options*"))))
991 (defun customize-version-lessp (version1 version2)
992 ;; In case someone made a mistake and left out the quotes
993 ;; in the :version value.
994 (if (numberp version2)
995 (setq version2 (prin1-to-string version2)))
996 (let (major1 major2 minor1 minor2)
997 (string-match "\\([0-9]+\\)[.]\\([0-9]+\\)" version1)
998 (setq major1 (read (match-string 1 version1)))
999 (setq minor1 (read (match-string 2 version1)))
1000 (string-match "\\([0-9]+\\)[.]\\([0-9]+\\)" version2)
1001 (setq major2 (read (match-string 1 version2)))
1002 (setq minor2 (read (match-string 2 version2)))
1003 (or (< major1 major2)
1004 (and (= major1 major2)
1005 (< minor1 minor2)))))
1008 (defalias 'customize-variable-other-window 'customize-option-other-window)
1011 (defun customize-option-other-window (symbol)
1012 "Customize SYMBOL, which must be a user option variable.
1013 Show the buffer in another window, but don't select it."
1014 (interactive (custom-variable-prompt))
1015 (custom-buffer-create-other-window
1016 (list (list symbol 'custom-variable))
1017 (format "*Customize Option: %s*" (custom-unlispify-tag-name symbol))))
1020 (defun customize-face (&optional symbol)
1021 "Customize SYMBOL, which should be a face name or nil.
1022 If SYMBOL is nil, customize all faces."
1023 (interactive (list (completing-read "Customize face: (default all) "
1024 obarray 'custom-facep t)))
1025 (if (or (null symbol) (and (stringp symbol) (zerop (length symbol))))
1026 (custom-buffer-create (custom-sort-items
1027 (mapcar (lambda (symbol)
1028 (list symbol 'custom-face))
1031 "*Customize Faces*")
1032 (when (stringp symbol)
1033 (setq symbol (intern symbol)))
1034 (unless (symbolp symbol)
1035 (error "Should be a symbol %S" symbol))
1036 (custom-buffer-create (list (list symbol 'custom-face))
1037 (format "*Customize Face: %s*"
1038 (custom-unlispify-tag-name symbol)))))
1041 (defun customize-face-other-window (&optional symbol)
1042 "Show customization buffer for FACE in other window."
1043 (interactive (list (completing-read "Customize face: "
1044 obarray 'custom-facep t)))
1045 (if (or (null symbol) (and (stringp symbol) (zerop (length symbol))))
1047 (if (stringp symbol)
1048 (setq symbol (intern symbol)))
1049 (unless (symbolp symbol)
1050 (error "Should be a symbol %S" symbol))
1051 (custom-buffer-create-other-window
1052 (list (list symbol 'custom-face))
1053 (format "*Customize Face: %s*" (custom-unlispify-tag-name symbol)))))
1056 (defun customize-customized ()
1057 "Customize all user options set since the last save in this session."
1060 (mapatoms (lambda (symbol)
1061 (and (or (get symbol 'customized-face)
1062 (get symbol 'customized-face-comment))
1063 (custom-facep symbol)
1064 (push (list symbol 'custom-face) found))
1065 (and (or (get symbol 'customized-value)
1066 (get symbol 'customized-variable-comment))
1068 (push (list symbol 'custom-variable) found))))
1070 (error "No customized user options")
1071 (custom-buffer-create (custom-sort-items found t nil)
1072 "*Customize Customized*"))))
1075 (defun customize-saved ()
1076 "Customize all already saved user options."
1079 (mapatoms (lambda (symbol)
1080 (and (or (get symbol 'saved-face)
1081 (get symbol 'saved-face-comment))
1082 (custom-facep symbol)
1083 (push (list symbol 'custom-face) found))
1084 (and (or (get symbol 'saved-value)
1085 (get symbol 'saved-variable-comment))
1087 (push (list symbol 'custom-variable) found))))
1089 (error "No saved user options")
1090 (custom-buffer-create (custom-sort-items found t nil)
1091 "*Customize Saved*"))))
1094 (defun customize-apropos (regexp &optional all)
1095 "Customize all user options matching REGEXP.
1096 If ALL is `options', include only options.
1097 If ALL is `faces', include only faces.
1098 If ALL is `groups', include only groups.
1099 If ALL is t (interactively, with prefix arg), include options which are not
1100 user-settable, as well as faces and groups."
1101 (interactive "sCustomize regexp: \nP")
1103 (mapatoms (lambda (symbol)
1104 (when (string-match regexp (symbol-name symbol))
1105 (when (and (not (memq all '(faces options)))
1106 (get symbol 'custom-group))
1107 (push (list symbol 'custom-group) found))
1108 (when (and (not (memq all '(options groups)))
1109 (custom-facep symbol))
1110 (push (list symbol 'custom-face) found))
1111 (when (and (not (memq all '(groups faces)))
1113 (or (get symbol 'saved-value)
1114 (get symbol 'standard-value)
1115 (if (memq all '(nil options))
1116 (user-variable-p symbol)
1117 (get symbol 'variable-documentation))))
1118 (push (list symbol 'custom-variable) found)))))
1120 (error "No matches")
1121 (custom-buffer-create (custom-sort-items found t
1122 custom-buffer-order-groups)
1123 "*Customize Apropos*"))))
1126 (defun customize-apropos-options (regexp &optional arg)
1127 "Customize all user options matching REGEXP.
1128 With prefix arg, include options which are not user-settable."
1129 (interactive "sCustomize regexp: \nP")
1130 (customize-apropos regexp (or arg 'options)))
1133 (defun customize-apropos-faces (regexp)
1134 "Customize all user faces matching REGEXP."
1135 (interactive "sCustomize regexp: \n")
1136 (customize-apropos regexp 'faces))
1139 (defun customize-apropos-groups (regexp)
1140 "Customize all user groups matching REGEXP."
1141 (interactive "sCustomize regexp: \n")
1142 (customize-apropos regexp 'groups))
1146 (defcustom custom-buffer-style 'links
1147 "Control the presentation style for customization buffers.
1148 The value should be a symbol, one of:
1150 brackets: groups nest within each other with big horizontal brackets.
1151 links: groups have links to subgroups."
1152 :type '(radio (const brackets)
1154 :group 'custom-buffer)
1156 ;; If we pass BUFFER to `bury-buffer', the buffer isn't removed from
1158 (defun custom-bury-buffer (buffer)
1161 (defcustom custom-buffer-done-function 'custom-bury-buffer
1162 "*Function called to remove a Custom buffer when the user is done with it.
1163 Called with one argument, the buffer to remove."
1164 :type '(choice (function-item :tag "Bury buffer" custom-bury-buffer)
1165 (function-item :tag "Kill buffer" kill-buffer)
1166 (function :tag "Other"))
1168 :group 'custom-buffer)
1170 (defcustom custom-buffer-indent 3
1171 "Number of spaces to indent nested groups."
1173 :group 'custom-buffer)
1176 (defun custom-buffer-create (options &optional name description)
1177 "Create a buffer containing OPTIONS.
1178 Optional NAME is the name of the buffer.
1179 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1180 SYMBOL is a customization option, and WIDGET is a widget for editing
1182 (unless name (setq name "*Customization*"))
1183 (kill-buffer (get-buffer-create name))
1184 (pop-to-buffer (get-buffer-create name))
1185 (custom-buffer-create-internal options description))
1188 (defun custom-buffer-create-other-window (options &optional name description)
1189 "Create a buffer containing OPTIONS.
1190 Optional NAME is the name of the buffer.
1191 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1192 SYMBOL is a customization option, and WIDGET is a widget for editing
1194 (unless name (setq name "*Customization*"))
1195 (kill-buffer (get-buffer-create name))
1196 (let ((window (selected-window))
1198 (special-display-buffer-names nil)
1199 (special-display-regexps nil)
1200 (same-window-buffer-names nil)
1201 (same-window-regexps nil))
1202 (pop-to-buffer (get-buffer-create name))
1203 (custom-buffer-create-internal options description)
1204 (select-window window)))
1206 (defcustom custom-reset-button-menu nil
1207 "If non-nil, only show a single reset button in customize buffers.
1208 This button will have a menu with all three reset operations."
1210 :group 'custom-buffer)
1212 (defun Custom-buffer-done (&rest ignore)
1213 "Remove current buffer by calling `custom-buffer-done-function'."
1215 (funcall custom-buffer-done-function (current-buffer)))
1217 (defcustom custom-raised-buttons (not (equal (face-valid-attribute-values :box)
1218 '(("unspecified" . unspecified))))
1219 "If non-nil, indicate active buttons in a `raised-button' style.
1220 Otherwise use brackets."
1223 :group 'custom-buffer)
1225 (defun custom-buffer-create-internal (options &optional description)
1226 (message "Creating customization buffer...")
1228 (widget-insert "This is a customization buffer")
1230 (widget-insert description))
1231 (widget-insert (format ".
1232 %s show active fields; type RET or click mouse-1
1233 on an active field to invoke its action. Editing an option value
1234 changes the text in the buffer; invoke the State button and
1235 choose the Set operation to set the option value.
1236 Invoke " (if custom-raised-buttons
1238 "Square brackets")))
1239 (widget-create 'info-link
1241 :help-echo "Read the online help."
1242 "(emacs)Easy Customization")
1243 (widget-insert " for more information.\n\n")
1244 (message "Creating customization buttons...")
1245 (widget-insert "Operate on everything in this buffer:\n ")
1246 (widget-create 'push-button
1247 :tag "Set for Current Session"
1249 Make your editing in this buffer take effect for this session."
1250 :action (lambda (widget &optional event)
1253 (widget-create 'push-button
1254 :tag "Save for Future Sessions"
1256 Make your editing in this buffer take effect for future Emacs sessions."
1257 :action (lambda (widget &optional event)
1259 (if custom-reset-button-menu
1262 (widget-create 'push-button
1264 :help-echo "Show a menu with reset operations."
1265 :mouse-down-action (lambda (&rest junk) t)
1266 :action (lambda (widget &optional event)
1267 (custom-reset event))))
1268 (widget-insert "\n ")
1269 (widget-create 'push-button
1272 Reset all edited text in this buffer to reflect current values."
1273 :action 'Custom-reset-current)
1275 (widget-create 'push-button
1276 :tag "Reset to Saved"
1278 Reset all values in this buffer to their saved settings."
1279 :action 'Custom-reset-saved)
1281 (widget-create 'push-button
1282 :tag "Reset to Standard"
1284 Reset all values in this buffer to their standard settings."
1285 :action 'Custom-reset-standard))
1287 (widget-create 'push-button
1289 :help-echo "Bury or kill the buffer."
1290 :action #'Custom-buffer-done)
1291 (widget-insert "\n\n")
1292 (message "Creating customization items...")
1293 (setq custom-options
1294 (if (= (length options) 1)
1295 (mapcar (lambda (entry)
1296 (widget-create (nth 1 entry)
1297 :documentation-shown t
1298 :custom-state 'unknown
1299 :tag (custom-unlispify-tag-name
1301 :value (nth 0 entry)))
1304 (length (length options)))
1305 (mapcar (lambda (entry)
1307 (message "Creating customization items ...%2d%%"
1308 (/ (* 100.0 count) length))
1309 (widget-create (nth 1 entry)
1310 :tag (custom-unlispify-tag-name
1312 :value (nth 0 entry))
1313 (setq count (1+ count))
1314 (unless (eq (preceding-char) ?\n)
1315 (widget-insert "\n"))
1316 (widget-insert "\n")))
1318 (unless (eq (preceding-char) ?\n)
1319 (widget-insert "\n"))
1320 (message "Creating customization items ...%2d%%done" 100)
1321 (unless (eq custom-buffer-style 'tree)
1322 (mapcar 'custom-magic-reset custom-options))
1323 (message "Creating customization setup...")
1325 (goto-char (point-min))
1326 (message "Creating customization buffer...done"))
1328 ;;; The Tree Browser.
1331 (defun customize-browse (&optional group)
1332 "Create a tree browser for the customize hierarchy."
1335 (setq group 'emacs))
1336 (let ((name "*Customize Browser*"))
1337 (kill-buffer (get-buffer-create name))
1338 (pop-to-buffer (get-buffer-create name)))
1341 Square brackets show active fields; type RET or click mouse-1
1342 on an active field to invoke its action.
1343 Invoke [+] below to expand a group, and [-] to collapse an expanded group.\n")
1344 (if custom-browse-only-groups
1346 Invoke the [Group] button below to edit that item in another window.\n\n")
1347 (widget-insert "Invoke the ")
1348 (widget-create 'item
1351 :tag-glyph "folder")
1352 (widget-insert ", ")
1353 (widget-create 'item
1357 (widget-insert ", and ")
1358 (widget-create 'item
1361 :tag-glyph "option")
1362 (widget-insert " buttons below to edit that
1363 item in another window.\n\n"))
1364 (let ((custom-buffer-style 'tree))
1365 (widget-create 'custom-group
1367 :custom-state 'unknown
1368 :tag (custom-unlispify-tag-name group)
1370 (goto-char (point-min)))
1372 (define-widget 'custom-browse-visibility 'item
1373 "Control visibility of items in the customize tree browser."
1375 :action 'custom-browse-visibility-action)
1377 (defun custom-browse-visibility-action (widget &rest ignore)
1378 (let ((custom-buffer-style 'tree))
1379 (custom-toggle-parent widget)))
1381 (define-widget 'custom-browse-group-tag 'push-button
1382 "Show parent in other window when activated."
1385 :action 'custom-browse-group-tag-action)
1387 (defun custom-browse-group-tag-action (widget &rest ignore)
1388 (let ((parent (widget-get widget :parent)))
1389 (customize-group-other-window (widget-value parent))))
1391 (define-widget 'custom-browse-variable-tag 'push-button
1392 "Show parent in other window when activated."
1395 :action 'custom-browse-variable-tag-action)
1397 (defun custom-browse-variable-tag-action (widget &rest ignore)
1398 (let ((parent (widget-get widget :parent)))
1399 (customize-variable-other-window (widget-value parent))))
1401 (define-widget 'custom-browse-face-tag 'push-button
1402 "Show parent in other window when activated."
1405 :action 'custom-browse-face-tag-action)
1407 (defun custom-browse-face-tag-action (widget &rest ignore)
1408 (let ((parent (widget-get widget :parent)))
1409 (customize-face-other-window (widget-value parent))))
1411 (defconst custom-browse-alist '((" " "space")
1417 (defun custom-browse-insert-prefix (prefix)
1418 "Insert PREFIX. On XEmacs convert it to line graphics."
1419 ;; Fixme: do graphics.
1420 (if nil ; (string-match "XEmacs" emacs-version)
1423 (while (not (string-equal prefix ""))
1424 (let ((entry (substring prefix 0 3)))
1425 (setq prefix (substring prefix 3))
1426 (let ((overlay (make-overlay (1- (point)) (point) nil t nil))
1427 (name (nth 1 (assoc entry custom-browse-alist))))
1428 (overlay-put overlay 'end-glyph (widget-glyph-find name entry))
1429 (overlay-put overlay 'start-open t)
1430 (overlay-put overlay 'end-open t)))))
1433 ;;; Modification of Basic Widgets.
1435 ;; We add extra properties to the basic widgets needed here. This is
1436 ;; fine, as long as we are careful to stay within out own namespace.
1438 ;; We want simple widgets to be displayed by default, but complex
1439 ;; widgets to be hidden.
1441 (widget-put (get 'item 'widget-type) :custom-show t)
1442 (widget-put (get 'editable-field 'widget-type)
1443 :custom-show (lambda (widget value)
1444 (let ((pp (pp-to-string value)))
1445 (cond ((string-match "\n" pp)
1450 (widget-put (get 'menu-choice 'widget-type) :custom-show t)
1452 ;;; The `custom-manual' Widget.
1454 (define-widget 'custom-manual 'info-link
1455 "Link to the manual entry for this customization option."
1456 :help-echo "Read the manual entry for this option."
1459 ;;; The `custom-magic' Widget.
1461 (defgroup custom-magic-faces nil
1462 "Faces used by the magic button."
1463 :group 'custom-faces
1464 :group 'custom-buffer)
1466 (defface custom-invalid-face '((((class color))
1467 (:foreground "yellow" :background "red"))
1469 (:bold t :italic t :underline t)))
1470 "Face used when the customize item is invalid."
1471 :group 'custom-magic-faces)
1473 (defface custom-rogue-face '((((class color))
1474 (:foreground "pink" :background "black"))
1477 "Face used when the customize item is not defined for customization."
1478 :group 'custom-magic-faces)
1480 (defface custom-modified-face '((((class color))
1481 (:foreground "white" :background "blue"))
1484 "Face used when the customize item has been modified."
1485 :group 'custom-magic-faces)
1487 (defface custom-set-face '((((class color))
1488 (:foreground "blue" :background "white"))
1491 "Face used when the customize item has been set."
1492 :group 'custom-magic-faces)
1494 (defface custom-changed-face '((((class color))
1495 (:foreground "white" :background "blue"))
1498 "Face used when the customize item has been changed."
1499 :group 'custom-magic-faces)
1501 (defface custom-saved-face '((t (:underline t)))
1502 "Face used when the customize item has been saved."
1503 :group 'custom-magic-faces)
1505 (defconst custom-magic-alist '((nil "#" underline "\
1506 uninitialized, you should not see this.")
1507 (unknown "?" italic "\
1508 unknown, you should not see this.")
1509 (hidden "-" default "\
1510 hidden, invoke \"Show\" in the previous line to show." "\
1511 group now hidden, invoke \"Show\", above, to show contents.")
1512 (invalid "x" custom-invalid-face "\
1513 the value displayed for this %c is invalid and cannot be set.")
1514 (modified "*" custom-modified-face "\
1515 you have edited the value as text, but you have not set the %c." "\
1516 you have edited something in this group, but not set it.")
1517 (set "+" custom-set-face "\
1518 you have set this %c, but not saved it for future sessions." "\
1519 something in this group has been set, but not saved.")
1520 (changed ":" custom-changed-face "\
1521 this %c has been changed outside the customize buffer." "\
1522 something in this group has been changed outside customize.")
1523 (saved "!" custom-saved-face "\
1524 this %c has been set and saved." "\
1525 something in this group has been set and saved.")
1526 (rogue "@" custom-rogue-face "\
1527 this %c has not been changed with customize." "\
1528 something in this group is not prepared for customization.")
1529 (standard " " nil "\
1530 this %c is unchanged from its standard setting." "\
1531 visible group members are all at standard settings."))
1532 "Alist of customize option states.
1533 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1535 STATE is one of the following symbols:
1538 For internal use, should never occur.
1540 For internal use, should never occur.
1542 This item is not being displayed.
1544 This item is modified, but has an invalid form.
1546 This item is modified, and has a valid form.
1548 This item has been set but not saved.
1550 The current value of this item has been changed temporarily.
1552 This item is marked for saving.
1554 This item has no customization information.
1556 This item is unchanged from the standard setting.
1558 MAGIC is a string used to present that state.
1560 FACE is a face used to present the state.
1562 ITEM-DESC is a string describing the state for options.
1564 GROUP-DESC is a string describing the state for groups. If this is
1565 left out, ITEM-DESC will be used.
1567 The string %c in either description will be replaced with the
1568 category of the item. These are `group'. `option', and `face'.
1570 The list should be sorted most significant first.")
1572 (defcustom custom-magic-show 'long
1573 "If non-nil, show textual description of the state.
1574 If `long', show a full-line description, not just one word."
1575 :type '(choice (const :tag "no" nil)
1577 (other :tag "short" short))
1578 :group 'custom-buffer)
1580 (defcustom custom-magic-show-hidden '(option face)
1581 "Control whether the State button is shown for hidden items.
1582 The value should be a list with the custom categories where the State
1583 button should be visible. Possible categories are `group', `option',
1585 :type '(set (const group) (const option) (const face))
1586 :group 'custom-buffer)
1588 (defcustom custom-magic-show-button nil
1589 "Show a \"magic\" button indicating the state of each customization option."
1591 :group 'custom-buffer)
1593 (define-widget 'custom-magic 'default
1594 "Show and manipulate state for a customization option."
1596 :action 'widget-parent-action
1599 :value-create 'custom-magic-value-create
1600 :value-delete 'widget-children-value-delete)
1602 (defun widget-magic-mouse-down-action (widget &optional event)
1603 ;; Non-nil unless hidden.
1604 (not (eq (widget-get (widget-get (widget-get widget :parent) :parent)
1608 (defun custom-magic-value-create (widget)
1609 ;; Create compact status report for WIDGET.
1610 (let* ((parent (widget-get widget :parent))
1611 (state (widget-get parent :custom-state))
1612 (hidden (eq state 'hidden))
1613 (entry (assq state custom-magic-alist))
1614 (magic (nth 1 entry))
1615 (face (nth 2 entry))
1616 (category (widget-get parent :custom-category))
1617 (text (or (and (eq category 'group)
1620 (form (widget-get parent :custom-form))
1622 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text)
1623 (setq text (concat (match-string 1 text)
1624 (symbol-name category)
1625 (match-string 2 text))))
1626 (when (and custom-magic-show
1628 (memq category custom-magic-show-hidden)))
1630 (when (and (eq category 'group)
1631 (not (and (eq custom-buffer-style 'links)
1632 (> (widget-get parent :custom-level) 1))))
1633 (insert-char ?\ (* custom-buffer-indent
1634 (widget-get parent :custom-level))))
1635 (push (widget-create-child-and-convert
1637 :help-echo "Change the state of this item."
1638 :format (if hidden "%t" "%[%t%]")
1639 :button-prefix 'widget-push-button-prefix
1640 :button-suffix 'widget-push-button-suffix
1641 :mouse-down-action 'widget-magic-mouse-down-action
1645 (let ((start (point)))
1646 (if (eq custom-magic-show 'long)
1648 (insert (symbol-name state)))
1649 (cond ((eq form 'lisp)
1651 ((eq form 'mismatch)
1652 (insert " (mismatch)")))
1653 (put-text-property start (point) 'face 'custom-state-face))
1655 (when (and (eq category 'group)
1656 (not (and (eq custom-buffer-style 'links)
1657 (> (widget-get parent :custom-level) 1))))
1658 (insert-char ?\ (* custom-buffer-indent
1659 (widget-get parent :custom-level))))
1660 (when custom-magic-show-button
1661 (when custom-magic-show
1662 (let ((indent (widget-get parent :indent)))
1664 (insert-char ? indent))))
1665 (push (widget-create-child-and-convert
1667 :mouse-down-action 'widget-magic-mouse-down-action
1671 :help-echo "Change the state."
1672 :format (if hidden "%t" "%[%t%]")
1673 :tag (if (memq form '(lisp mismatch))
1674 (concat "(" magic ")")
1675 (concat "[" magic "]")))
1678 (widget-put widget :children children)))
1680 (defun custom-magic-reset (widget)
1681 "Redraw the :custom-magic property of WIDGET."
1682 (let ((magic (widget-get widget :custom-magic)))
1683 (widget-value-set magic (widget-value magic))))
1685 ;;; The `custom' Widget.
1687 (defface custom-button-face
1688 '((((type x) (class color)) ; Like default modeline
1689 (:box (:line-width 2 :style released-button) :background "lightgrey"))
1692 "Face used for buttons in customization buffers."
1694 :group 'custom-faces)
1696 (defface custom-button-pressed-face
1697 '((((type x) (class color))
1698 (:box (:line-width 2 :style pressed-button) :background "lightgrey"))
1700 (:inverse-video t)))
1701 "Face used for buttons in customization buffers."
1703 :group 'custom-faces)
1705 (defface custom-documentation-face nil
1706 "Face used for documentation strings in customization buffers."
1707 :group 'custom-faces)
1709 (defface custom-state-face '((((class color)
1711 (:foreground "lime green"))
1714 (:foreground "dark green"))
1716 "Face used for State descriptions in the customize buffer."
1717 :group 'custom-faces)
1719 (define-widget 'custom 'default
1720 "Customize a user option."
1722 :convert-widget 'custom-convert-widget
1723 :notify 'custom-notify
1726 :custom-state 'hidden
1727 :documentation-property 'widget-subclass-responsibility
1728 :value-create 'widget-subclass-responsibility
1729 :value-delete 'widget-children-value-delete
1730 :value-get 'widget-value-value-get
1731 :validate 'widget-children-validate
1732 :match (lambda (widget value) (symbolp value)))
1734 (defun custom-convert-widget (widget)
1735 ;; Initialize :value and :tag from :args in WIDGET.
1736 (let ((args (widget-get widget :args)))
1738 (widget-put widget :value (widget-apply widget
1739 :value-to-internal (car args)))
1740 (widget-put widget :tag (custom-unlispify-tag-name (car args)))
1741 (widget-put widget :args nil)))
1744 (defun custom-notify (widget &rest args)
1745 "Keep track of changes."
1746 (let ((state (widget-get widget :custom-state)))
1747 (unless (eq state 'modified)
1748 (unless (memq state '(nil unknown hidden))
1749 (widget-put widget :custom-state 'modified))
1750 (custom-magic-reset widget)
1751 (apply 'widget-default-notify widget args))))
1753 (defun custom-redraw (widget)
1754 "Redraw WIDGET with current settings."
1755 (let ((line (count-lines (point-min) (point)))
1756 (column (current-column))
1758 (from (marker-position (widget-get widget :from)))
1759 (to (marker-position (widget-get widget :to))))
1761 (widget-value-set widget (widget-value widget))
1762 (custom-redraw-magic widget))
1763 (when (and (>= pos from) (<= pos to))
1768 (goto-line (1+ line)))
1769 (move-to-column column))
1772 (defun custom-redraw-magic (widget)
1773 "Redraw WIDGET state with current settings."
1775 (let ((magic (widget-get widget :custom-magic)))
1777 (widget-value-set magic (widget-value magic))
1778 (when (setq widget (widget-get widget :group))
1779 (custom-group-state-update widget)))
1781 (setq widget nil)))))
1784 (defun custom-show (widget value)
1785 "Non-nil if WIDGET should be shown with VALUE by default."
1786 (let ((show (widget-get widget :custom-show)))
1792 (funcall show widget value)))))
1794 (defvar custom-load-recursion nil
1795 "Hack to avoid recursive dependencies.")
1797 (defun custom-load-symbol (symbol)
1798 "Load all dependencies for SYMBOL."
1799 (unless custom-load-recursion
1800 (let ((custom-load-recursion t)
1801 (loads (get symbol 'custom-loads))
1804 (setq load (car loads)
1806 (cond ((symbolp load)
1810 ;; Don't reload a file already loaded.
1811 ((and (boundp 'preloaded-file-list)
1812 (member load preloaded-file-list)))
1813 ((assoc load load-history))
1814 ((assoc (locate-library load) load-history))
1817 ;; Without this, we would load cus-edit recursively.
1818 ;; We are still loading it when we call this,
1819 ;; and it is not in load-history yet.
1820 (or (equal load "cus-edit")
1821 (load-library load))
1824 (defun custom-load-widget (widget)
1825 "Load all dependencies for WIDGET."
1826 (custom-load-symbol (widget-value widget)))
1828 (defun custom-unloaded-symbol-p (symbol)
1829 "Return non-nil if the dependencies of SYMBOL has not yet been loaded."
1831 (loads (get symbol 'custom-loads))
1834 (setq load (car loads)
1836 (cond ((symbolp load)
1837 (unless (featurep load)
1839 ((assoc load load-history))
1840 ((assoc (locate-library load) load-history)
1846 (defun custom-unloaded-widget-p (widget)
1847 "Return non-nil if the dependencies of WIDGET has not yet been loaded."
1848 (custom-unloaded-symbol-p (widget-value widget)))
1850 (defun custom-toggle-hide (widget)
1851 "Toggle visibility of WIDGET."
1852 (custom-load-widget widget)
1853 (let ((state (widget-get widget :custom-state)))
1854 (cond ((memq state '(invalid modified))
1855 (error "There are unset changes"))
1857 (widget-put widget :custom-state 'unknown))
1859 (widget-put widget :documentation-shown nil)
1860 (widget-put widget :custom-state 'hidden)))
1861 (custom-redraw widget)
1864 (defun custom-toggle-parent (widget &rest ignore)
1865 "Toggle visibility of parent of WIDGET."
1866 (custom-toggle-hide (widget-get widget :parent)))
1868 (defun custom-add-see-also (widget &optional prefix)
1869 "Add `See also ...' to WIDGET if there are any links.
1870 Insert PREFIX first if non-nil."
1871 (let* ((symbol (widget-get widget :value))
1872 (links (get symbol 'custom-links))
1873 (many (> (length links) 2))
1874 (buttons (widget-get widget :buttons))
1875 (indent (widget-get widget :indent)))
1878 (insert-char ?\ indent))
1881 (insert "See also ")
1883 (push (widget-create-child-and-convert widget (car links))
1885 (setq links (cdr links))
1894 (widget-put widget :buttons buttons))))
1896 (defun custom-add-parent-links (widget &optional initial-string)
1897 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
1898 The value if non-nil if any parents were found.
1899 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
1900 (let ((name (widget-value widget))
1901 (type (widget-type widget))
1902 (buttons (widget-get widget :buttons))
1905 (insert (or initial-string "Parent groups:"))
1906 (mapatoms (lambda (symbol)
1907 (let ((entry (assq name (get symbol 'custom-group))))
1908 (when (eq (nth 1 entry) type)
1910 (push (widget-create-child-and-convert
1911 widget 'custom-group-link
1912 :tag (custom-unlispify-tag-name symbol)
1916 (widget-put widget :buttons buttons)
1919 (delete-region start (point)))
1922 ;;; The `custom-comment' Widget.
1924 ;; like the editable field
1925 (defface custom-comment-face '((((class grayscale color)
1927 (:background "gray85"))
1928 (((class grayscale color)
1930 (:background "dim gray"))
1933 "Face used for comments on variables or faces"
1935 :group 'custom-faces)
1937 ;; like font-lock-comment-face
1938 (defface custom-comment-tag-face
1939 '((((class color) (background dark)) (:foreground "gray80"))
1940 (((class color) (background light)) (:foreground "blue4"))
1941 (((class grayscale) (background light))
1942 (:foreground "DimGray" :bold t :italic t))
1943 (((class grayscale) (background dark))
1944 (:foreground "LightGray" :bold t :italic t))
1946 "Face used for variables or faces comment tags"
1947 :group 'custom-faces)
1949 (define-widget 'custom-comment 'string
1952 :help-echo "Edit a comment here."
1953 :sample-face 'custom-comment-tag-face
1954 :value-face 'custom-comment-face
1956 :create 'custom-comment-create)
1958 (defun custom-comment-create (widget)
1959 (let* ((null-comment (equal "" (widget-value widget))))
1960 (if (or (widget-get (widget-get widget :parent) :comment-shown)
1962 (widget-default-create widget)
1963 ;; `widget-default-delete' expects markers in these slots --
1964 ;; maybe it shouldn't.
1965 (widget-put widget :from (point-marker))
1966 (widget-put widget :to (point-marker)))))
1968 (defun custom-comment-hide (widget)
1969 (widget-put (widget-get widget :parent) :comment-shown nil))
1971 ;; Those functions are for the menu. WIDGET is NOT the comment widget. It's
1972 ;; the global custom one
1973 (defun custom-comment-show (widget)
1974 (widget-put widget :comment-shown t)
1975 (custom-redraw widget)
1978 (defun custom-comment-invisible-p (widget)
1979 (let ((val (widget-value (widget-get widget :comment-widget))))
1981 (not (widget-get widget :comment-shown)))))
1983 ;;; The `custom-variable' Widget.
1985 (defface custom-variable-tag-face '((((class color)
1987 (:foreground "light blue" :underline t))
1990 (:foreground "blue" :underline t))
1992 "Face used for unpushable variable tags."
1993 :group 'custom-faces)
1995 (defface custom-variable-button-face '((t (:underline t :bold t)))
1996 "Face used for pushable variable tags."
1997 :group 'custom-faces)
1999 (defcustom custom-variable-default-form 'edit
2000 "Default form of displaying variable values."
2001 :type '(choice (const edit)
2003 :group 'custom-buffer
2006 (define-widget 'custom-variable 'custom
2007 "Customize variable."
2009 :help-echo "Set or reset this variable."
2010 :documentation-property 'variable-documentation
2011 :custom-category 'option
2013 :custom-menu 'custom-variable-menu-create
2014 :custom-form nil ; defaults to value of `custom-variable-default-form'
2015 :value-create 'custom-variable-value-create
2016 :action 'custom-variable-action
2017 :custom-set 'custom-variable-set
2018 :custom-save 'custom-variable-save
2019 :custom-reset-current 'custom-redraw
2020 :custom-reset-saved 'custom-variable-reset-saved
2021 :custom-reset-standard 'custom-variable-reset-standard)
2023 (defun custom-variable-type (symbol)
2024 "Return a widget suitable for editing the value of SYMBOL.
2025 If SYMBOL has a `custom-type' property, use that.
2026 Otherwise, look up symbol in `custom-guess-type-alist'."
2027 (let* ((type (or (get symbol 'custom-type)
2028 (and (not (get symbol 'standard-value))
2029 (custom-guess-type symbol))
2031 (options (get symbol 'custom-options))
2032 (tmp (if (listp type)
2033 (copy-sequence type)
2036 (widget-put tmp :options options))
2039 (defun custom-variable-value-create (widget)
2040 "Here is where you edit the variable's value."
2041 (custom-load-widget widget)
2042 (unless (widget-get widget :custom-form)
2043 (widget-put widget :custom-form custom-variable-default-form))
2044 (let* ((buttons (widget-get widget :buttons))
2045 (children (widget-get widget :children))
2046 (form (widget-get widget :custom-form))
2047 (state (widget-get widget :custom-state))
2048 (symbol (widget-get widget :value))
2049 (tag (widget-get widget :tag))
2050 (type (custom-variable-type symbol))
2051 (conv (widget-convert type))
2052 (get (or (get symbol 'custom-get) 'default-value))
2053 (prefix (widget-get widget :custom-prefix))
2054 (last (widget-get widget :custom-last))
2055 (value (if (default-boundp symbol)
2056 (funcall get symbol)
2057 (widget-get conv :value))))
2058 ;; If the widget is new, the child determines whether it is hidden.
2060 ((custom-show type value)
2061 (setq state 'unknown))
2063 (setq state 'hidden)))
2064 ;; If we don't know the state, see if we need to edit it in lisp form.
2065 (when (eq state 'unknown)
2066 (unless (widget-apply conv :match value)
2067 ;; (widget-apply (widget-convert type) :match value)
2068 (setq form 'mismatch)))
2069 ;; Now we can create the child widget.
2070 (cond ((eq custom-buffer-style 'tree)
2071 (insert prefix (if last " `--- " " |--- "))
2072 (push (widget-create-child-and-convert
2073 widget 'custom-browse-variable-tag)
2075 (insert " " tag "\n")
2076 (widget-put widget :buttons buttons))
2078 ;; Indicate hidden value.
2079 (push (widget-create-child-and-convert
2082 :sample-face 'custom-variable-tag-face
2086 (push (widget-create-child-and-convert
2088 :help-echo "Show the value of this option."
2089 :action 'custom-toggle-parent
2092 ((memq form '(lisp mismatch))
2093 ;; In lisp mode edit the saved value when possible.
2094 (let* ((value (cond ((get symbol 'saved-value)
2095 (car (get symbol 'saved-value)))
2096 ((get symbol 'standard-value)
2097 (car (get symbol 'standard-value)))
2098 ((default-boundp symbol)
2099 (custom-quote (funcall get symbol)))
2101 (custom-quote (widget-get conv :value))))))
2102 (insert (symbol-name symbol) ": ")
2103 (push (widget-create-child-and-convert
2105 :help-echo "Hide the value of this option."
2106 :action 'custom-toggle-parent
2110 (push (widget-create-child-and-convert
2112 :button-face 'custom-variable-button-face
2114 :tag (symbol-name symbol)
2120 (let* ((format (widget-get type :format))
2121 tag-format value-format)
2122 (unless (string-match ":" format)
2123 (error "Bad format"))
2124 (setq tag-format (substring format 0 (match-end 0)))
2125 (setq value-format (substring format (match-end 0)))
2126 (push (widget-create-child-and-convert
2129 :action 'custom-tag-action
2130 :help-echo "Change value of this option."
2131 :mouse-down-action 'custom-tag-mouse-down-action
2132 :button-face 'custom-variable-button-face
2133 :sample-face 'custom-variable-tag-face
2137 (push (widget-create-child-and-convert
2139 :help-echo "Hide the value of this option."
2140 :action 'custom-toggle-parent
2143 (push (widget-create-child-and-convert
2145 :format value-format
2148 (unless (eq custom-buffer-style 'tree)
2149 (unless (eq (preceding-char) ?\n)
2150 (widget-insert "\n"))
2151 ;; Create the magic button.
2152 (let ((magic (widget-create-child-and-convert
2153 widget 'custom-magic nil)))
2154 (widget-put widget :custom-magic magic)
2155 (push magic buttons))
2156 ;; ### NOTE: this is ugly!!!! I need to update the :buttons property
2157 ;; before the call to `widget-default-format-handler'. Otherwise, I
2158 ;; loose my current `buttons'. This function shouldn't be called like
2159 ;; this anyway. The doc string widget should be added like the others.
2161 (widget-put widget :buttons buttons)
2162 ;; Insert documentation.
2163 (widget-default-format-handler widget ?h)
2165 ;; The comment field
2166 (unless (eq state 'hidden)
2167 (let* ((comment (get symbol 'variable-comment))
2169 (widget-create-child-and-convert
2170 widget 'custom-comment
2172 :value (or comment ""))))
2173 (widget-put widget :comment-widget comment-widget)
2174 ;; Don't push it !!! Custom assumes that the first child is the
2176 (setq children (append children (list comment-widget)))))
2177 ;; Update the rest of the properties properties.
2178 (widget-put widget :custom-form form)
2179 (widget-put widget :children children)
2180 ;; Now update the state.
2181 (if (eq state 'hidden)
2182 (widget-put widget :custom-state state)
2183 (custom-variable-state-set widget))
2185 (unless (eq state 'hidden)
2186 (when (eq (widget-get widget :custom-level) 1)
2187 (custom-add-parent-links widget))
2188 (custom-add-see-also widget)))))
2190 (defun custom-tag-action (widget &rest args)
2191 "Pass :action to first child of WIDGET's parent."
2192 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
2195 (defun custom-tag-mouse-down-action (widget &rest args)
2196 "Pass :mouse-down-action to first child of WIDGET's parent."
2197 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
2198 :mouse-down-action args))
2200 (defun custom-variable-state-set (widget)
2201 "Set the state of WIDGET."
2202 (let* ((symbol (widget-value widget))
2203 (get (or (get symbol 'custom-get) 'default-value))
2204 (value (if (default-boundp symbol)
2205 (funcall get symbol)
2206 (widget-get widget :value)))
2207 (comment (get symbol 'variable-comment))
2210 (state (cond ((progn (setq tmp (get symbol 'customized-value))
2212 (get symbol 'customized-variable-comment))
2214 (if (condition-case nil
2215 (and (equal value (eval (car tmp)))
2216 (equal comment temp))
2220 ((progn (setq tmp (get symbol 'saved-value))
2221 (setq temp (get symbol 'saved-variable-comment))
2223 (if (condition-case nil
2224 (and (equal value (eval (car tmp)))
2225 (equal comment temp))
2229 ((setq tmp (get symbol 'standard-value))
2230 (if (condition-case nil
2231 (and (equal value (eval (car tmp)))
2232 (equal comment nil))
2237 (widget-put widget :custom-state state)))
2239 (defvar custom-variable-menu
2240 '(("Set for Current Session" custom-variable-set
2242 (eq (widget-get widget :custom-state) 'modified)))
2243 ("Save for Future Sessions" custom-variable-save
2245 (memq (widget-get widget :custom-state) '(modified set changed rogue))))
2246 ("Reset to Current" custom-redraw
2248 (and (default-boundp (widget-value widget))
2249 (memq (widget-get widget :custom-state) '(modified changed)))))
2250 ("Reset to Saved" custom-variable-reset-saved
2252 (and (or (get (widget-value widget) 'saved-value)
2253 (get (widget-value widget) 'saved-variable-comment))
2254 (memq (widget-get widget :custom-state)
2255 '(modified set changed rogue)))))
2256 ("Reset to Standard Settings" custom-variable-reset-standard
2258 (and (get (widget-value widget) 'standard-value)
2259 (memq (widget-get widget :custom-state)
2260 '(modified set changed saved rogue)))))
2261 ("---" ignore ignore)
2262 ("Add Comment" custom-comment-show custom-comment-invisible-p)
2263 ("---" ignore ignore)
2264 ("Don't show as Lisp expression" custom-variable-edit
2266 (eq (widget-get widget :custom-form) 'lisp)))
2267 ("Show initial Lisp expression" custom-variable-edit-lisp
2269 (eq (widget-get widget :custom-form) 'edit))))
2270 "Alist of actions for the `custom-variable' widget.
2271 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2272 the menu entry, ACTION is the function to call on the widget when the
2273 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2274 widget as an argument, and returns non-nil if ACTION is valid on that
2275 widget. If FILTER is nil, ACTION is always valid.")
2277 (defun custom-variable-action (widget &optional event)
2278 "Show the menu for `custom-variable' WIDGET.
2279 Optional EVENT is the location for the menu."
2280 (if (eq (widget-get widget :custom-state) 'hidden)
2281 (custom-toggle-hide widget)
2282 (unless (eq (widget-get widget :custom-state) 'modified)
2283 (custom-variable-state-set widget))
2284 (custom-redraw-magic widget)
2285 (let* ((completion-ignore-case t)
2286 (answer (widget-choose (concat "Operation on "
2287 (custom-unlispify-tag-name
2288 (widget-get widget :value)))
2289 (custom-menu-filter custom-variable-menu
2293 (funcall answer widget)))))
2295 (defun custom-variable-edit (widget)
2296 "Edit value of WIDGET."
2297 (widget-put widget :custom-state 'unknown)
2298 (widget-put widget :custom-form 'edit)
2299 (custom-redraw widget))
2301 (defun custom-variable-edit-lisp (widget)
2302 "Edit the lisp representation of the value of WIDGET."
2303 (widget-put widget :custom-state 'unknown)
2304 (widget-put widget :custom-form 'lisp)
2305 (custom-redraw widget))
2307 (defun custom-variable-set (widget)
2308 "Set the current value for the variable being edited by WIDGET."
2309 (let* ((form (widget-get widget :custom-form))
2310 (state (widget-get widget :custom-state))
2311 (child (car (widget-get widget :children)))
2312 (symbol (widget-value widget))
2313 (set (or (get symbol 'custom-set) 'set-default))
2314 (comment-widget (widget-get widget :comment-widget))
2315 (comment (widget-value comment-widget))
2317 (cond ((eq state 'hidden)
2318 (error "Cannot set hidden variable"))
2319 ((setq val (widget-apply child :validate))
2320 (goto-char (widget-get val :from))
2321 (error "%s" (widget-get val :error)))
2322 ((memq form '(lisp mismatch))
2323 (when (equal comment "")
2325 ;; Make the comment invisible by hand if it's empty
2326 (custom-comment-hide comment-widget))
2327 (funcall set symbol (eval (setq val (widget-value child))))
2328 (put symbol 'customized-value (list val))
2329 (put symbol 'variable-comment comment)
2330 (put symbol 'customized-variable-comment comment))
2332 (when (equal comment "")
2334 ;; Make the comment invisible by hand if it's empty
2335 (custom-comment-hide comment-widget))
2336 (funcall set symbol (setq val (widget-value child)))
2337 (put symbol 'customized-value (list (custom-quote val)))
2338 (put symbol 'variable-comment comment)
2339 (put symbol 'customized-variable-comment comment)))
2340 (custom-variable-state-set widget)
2341 (custom-redraw-magic widget)))
2343 (defun custom-variable-save (widget)
2344 "Set and save the value for the variable being edited by WIDGET."
2345 (let* ((form (widget-get widget :custom-form))
2346 (state (widget-get widget :custom-state))
2347 (child (car (widget-get widget :children)))
2348 (symbol (widget-value widget))
2349 (set (or (get symbol 'custom-set) 'set-default))
2350 (comment-widget (widget-get widget :comment-widget))
2351 (comment (widget-value comment-widget))
2353 (cond ((eq state 'hidden)
2354 (error "Cannot set hidden variable"))
2355 ((setq val (widget-apply child :validate))
2356 (goto-char (widget-get val :from))
2357 (error "%s" (widget-get val :error)))
2358 ((memq form '(lisp mismatch))
2359 (when (equal comment "")
2361 ;; Make the comment invisible by hand if it's empty
2362 (custom-comment-hide comment-widget))
2363 (put symbol 'saved-value (list (widget-value child)))
2364 (funcall set symbol (eval (widget-value child)))
2365 (put symbol 'variable-comment comment)
2366 (put symbol 'saved-variable-comment comment))
2368 (when (equal comment "")
2370 ;; Make the comment invisible by hand if it's empty
2371 (custom-comment-hide comment-widget))
2372 (put symbol 'saved-value
2373 (list (custom-quote (widget-value child))))
2374 (funcall set symbol (widget-value child))
2375 (put symbol 'variable-comment comment)
2376 (put symbol 'saved-variable-comment comment)))
2377 (put symbol 'customized-value nil)
2378 (put symbol 'customized-variable-comment nil)
2380 (custom-variable-state-set widget)
2381 (custom-redraw-magic widget)))
2383 (defun custom-variable-reset-saved (widget)
2384 "Restore the saved value for the variable being edited by WIDGET."
2385 (let* ((symbol (widget-value widget))
2386 (set (or (get symbol 'custom-set) 'set-default))
2387 (comment-widget (widget-get widget :comment-widget))
2388 (value (get symbol 'saved-value))
2389 (comment (get symbol 'saved-variable-comment)))
2390 (cond ((or value comment)
2391 (put symbol 'variable-comment comment)
2393 (funcall set symbol (eval (car value)))
2396 (error "No saved value for %s" symbol)))
2397 (put symbol 'customized-value nil)
2398 (put symbol 'customized-variable-comment nil)
2399 (widget-put widget :custom-state 'unknown)
2400 ;; This call will possibly make the comment invisible
2401 (custom-redraw widget)))
2403 (defun custom-variable-reset-standard (widget)
2404 "Restore the standard setting for the variable being edited by WIDGET."
2405 (let* ((symbol (widget-value widget))
2406 (set (or (get symbol 'custom-set) 'set-default))
2407 (comment-widget (widget-get widget :comment-widget)))
2408 (if (get symbol 'standard-value)
2409 (funcall set symbol (eval (car (get symbol 'standard-value))))
2410 (error "No standard setting known for %S" symbol))
2411 (put symbol 'variable-comment nil)
2412 (put symbol 'customized-value nil)
2413 (put symbol 'customized-variable-comment nil)
2414 (when (or (get symbol 'saved-value) (get symbol 'saved-variable-comment))
2415 (put symbol 'saved-value nil)
2416 (put symbol 'saved-variable-comment nil)
2418 (widget-put widget :custom-state 'unknown)
2419 ;; This call will possibly make the comment invisible
2420 (custom-redraw widget)))
2422 ;;; The `custom-face-edit' Widget.
2424 (define-widget 'custom-face-edit 'checklist
2425 "Edit face attributes."
2429 :button-args '(:help-echo "Control whether this attribute has any effect.")
2430 :args (mapcar (lambda (att)
2433 :sibling-args (widget-get (nth 1 att) :sibling-args)
2434 (list 'const :format "" :value (nth 0 att))
2436 custom-face-attributes))
2438 ;;; The `custom-display' Widget.
2440 (define-widget 'custom-display 'menu-choice
2441 "Select a display type."
2444 :help-echo "Specify frames where the face attributes should be used."
2445 :args '((const :tag "all" t)
2449 :args ((group :sibling-args (:help-echo "\
2450 Only match the specified window systems.")
2451 (const :format "Type: "
2453 (checklist :inline t
2456 :sibling-args (:help-echo "\
2457 The X11 Window System.")
2459 (const :format "PM "
2460 :sibling-args (:help-echo "\
2461 OS/2 Presentation Manager.")
2463 (const :format "W32 "
2464 :sibling-args (:help-echo "\
2467 (const :format "DOS "
2468 :sibling-args (:help-echo "\
2471 (const :format "TTY%n"
2472 :sibling-args (:help-echo "\
2473 Plain text terminals.")
2475 (group :sibling-args (:help-echo "\
2476 Only match the frames with the specified color support.")
2477 (const :format "Class: "
2479 (checklist :inline t
2481 (const :format "Color "
2482 :sibling-args (:help-echo "\
2483 Match color frames.")
2485 (const :format "Grayscale "
2486 :sibling-args (:help-echo "\
2487 Match grayscale frames.")
2489 (const :format "Monochrome%n"
2490 :sibling-args (:help-echo "\
2491 Match frames with no color support.")
2493 (group :sibling-args (:help-echo "\
2494 Only match frames with the specified intensity.")
2496 Background brightness: "
2498 (checklist :inline t
2500 (const :format "Light "
2501 :sibling-args (:help-echo "\
2502 Match frames with light backgrounds.")
2504 (const :format "Dark\n"
2505 :sibling-args (:help-echo "\
2506 Match frames with dark backgrounds.")
2509 ;;; The `custom-face' Widget.
2511 (defface custom-face-tag-face '((t (:underline t)))
2512 "Face used for face tags."
2513 :group 'custom-faces)
2515 (defcustom custom-face-default-form 'selected
2516 "Default form of displaying face definition."
2517 :type '(choice (const all)
2520 :group 'custom-buffer
2523 (define-widget 'custom-face 'custom
2525 :sample-face 'custom-face-tag-face
2526 :help-echo "Set or reset this face."
2527 :documentation-property '(lambda (face)
2528 (face-doc-string face))
2529 :value-create 'custom-face-value-create
2530 :action 'custom-face-action
2531 :custom-category 'face
2532 :custom-form nil ; defaults to value of `custom-face-default-form'
2533 :custom-set 'custom-face-set
2534 :custom-save 'custom-face-save
2535 :custom-reset-current 'custom-redraw
2536 :custom-reset-saved 'custom-face-reset-saved
2537 :custom-reset-standard 'custom-face-reset-standard
2538 :custom-menu 'custom-face-menu-create)
2540 (define-widget 'custom-face-all 'editable-list
2541 "An editable list of display specifications and attributes."
2542 :entry-format "%i %d %v"
2543 :insert-button-args '(:help-echo "Insert new display specification here.")
2544 :append-button-args '(:help-echo "Append new display specification here.")
2545 :delete-button-args '(:help-echo "Delete this display specification.")
2546 :args '((group :format "%v" custom-display custom-face-edit)))
2548 (defconst custom-face-all (widget-convert 'custom-face-all)
2549 "Converted version of the `custom-face-all' widget.")
2551 (define-widget 'custom-display-unselected 'item
2552 "A display specification that doesn't match the selected display."
2553 :match 'custom-display-unselected-match)
2555 (defun custom-display-unselected-match (widget value)
2556 "Non-nil if VALUE is an unselected display specification."
2557 (not (face-spec-set-match-display value (selected-frame))))
2559 (define-widget 'custom-face-selected 'group
2560 "Edit the attributes of the selected display in a face specification."
2561 :args '((repeat :format ""
2563 (group custom-display-unselected sexp))
2564 (group (sexp :format "") custom-face-edit)
2569 (defconst custom-face-selected (widget-convert 'custom-face-selected)
2570 "Converted version of the `custom-face-selected' widget.")
2572 (defun custom-face-value-create (widget)
2573 "Create a list of the display specifications for WIDGET."
2574 (let ((buttons (widget-get widget :buttons))
2576 (symbol (widget-get widget :value))
2577 (tag (widget-get widget :tag))
2578 (state (widget-get widget :custom-state))
2580 (is-last (widget-get widget :custom-last))
2581 (prefix (widget-get widget :custom-prefix)))
2583 (setq tag (prin1-to-string symbol)))
2584 (cond ((eq custom-buffer-style 'tree)
2585 (insert prefix (if is-last " `--- " " |--- "))
2586 (push (widget-create-child-and-convert
2587 widget 'custom-browse-face-tag)
2589 (insert " " tag "\n")
2590 (widget-put widget :buttons buttons))
2594 (if (eq custom-buffer-style 'face)
2596 (widget-specify-sample widget begin (point))
2599 (push (widget-create-child-and-convert widget 'item
2606 (push (widget-create-child-and-convert
2608 :help-echo "Hide or show this face."
2609 :action 'custom-toggle-parent
2610 (not (eq state 'hidden)))
2614 (let ((magic (widget-create-child-and-convert
2615 widget 'custom-magic nil)))
2616 (widget-put widget :custom-magic magic)
2617 (push magic buttons))
2619 (widget-put widget :buttons buttons)
2620 ;; Insert documentation.
2621 (widget-default-format-handler widget ?h)
2622 ;; The comment field
2623 (unless (eq state 'hidden)
2624 (let* ((comment (get symbol 'face-comment))
2626 (widget-create-child-and-convert
2627 widget 'custom-comment
2629 :value (or comment ""))))
2630 (widget-put widget :comment-widget comment-widget)
2631 (push comment-widget children)))
2633 (unless (eq state 'hidden)
2634 (when (eq (widget-get widget :custom-level) 1)
2635 (custom-add-parent-links widget))
2636 (custom-add-see-also widget))
2638 (unless (eq (preceding-char) ?\n)
2640 (unless (eq state 'hidden)
2641 (message "Creating face editor...")
2642 (custom-load-widget widget)
2643 (unless (widget-get widget :custom-form)
2644 (widget-put widget :custom-form custom-face-default-form))
2645 (let* ((symbol (widget-value widget))
2646 (spec (or (get symbol 'saved-face)
2647 (get symbol 'face-defface-spec)
2648 ;; Attempt to construct it.
2649 (list (list t (custom-face-attributes-get
2650 symbol (selected-frame))))))
2651 (form (widget-get widget :custom-form))
2652 (indent (widget-get widget :indent))
2654 ;; If the user has changed this face in some other way,
2655 ;; edit it as the user has specified it.
2656 (if (not (face-spec-match-p symbol spec (selected-frame)))
2657 (setq spec (list (list t (face-attr-construct symbol (selected-frame))))))
2658 (setq edit (widget-create-child-and-convert
2660 (cond ((and (eq form 'selected)
2661 (widget-apply custom-face-selected
2663 (when indent (insert-char ?\ indent))
2664 'custom-face-selected)
2665 ((and (not (eq form 'lisp))
2666 (widget-apply custom-face-all
2670 (when indent (insert-char ?\ indent))
2673 (custom-face-state-set widget)
2674 (push edit children)
2675 (widget-put widget :children children))
2676 (message "Creating face editor...done"))))))
2678 (defvar custom-face-menu
2679 '(("Set for Current Session" custom-face-set)
2680 ("Save for Future Sessions" custom-face-save-command)
2681 ("Reset to Saved" custom-face-reset-saved
2683 (or (get (widget-value widget) 'saved-face)
2684 (get (widget-value widget) 'saved-face-comment))))
2685 ("Reset to Standard Setting" custom-face-reset-standard
2687 (get (widget-value widget) 'face-defface-spec)))
2688 ("---" ignore ignore)
2689 ("Add Comment" custom-comment-show custom-comment-invisible-p)
2690 ("---" ignore ignore)
2691 ("Show all display specs" custom-face-edit-all
2693 (not (eq (widget-get widget :custom-form) 'all))))
2694 ("Just current attributes" custom-face-edit-selected
2696 (not (eq (widget-get widget :custom-form) 'selected))))
2697 ("Show as Lisp expression" custom-face-edit-lisp
2699 (not (eq (widget-get widget :custom-form) 'lisp)))))
2700 "Alist of actions for the `custom-face' widget.
2701 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2702 the menu entry, ACTION is the function to call on the widget when the
2703 menu is selected, and FILTER is a predicate which takes a `custom-face'
2704 widget as an argument, and returns non-nil if ACTION is valid on that
2705 widget. If FILTER is nil, ACTION is always valid.")
2707 (defun custom-face-edit-selected (widget)
2708 "Edit selected attributes of the value of WIDGET."
2709 (widget-put widget :custom-state 'unknown)
2710 (widget-put widget :custom-form 'selected)
2711 (custom-redraw widget))
2713 (defun custom-face-edit-all (widget)
2714 "Edit all attributes of the value of WIDGET."
2715 (widget-put widget :custom-state 'unknown)
2716 (widget-put widget :custom-form 'all)
2717 (custom-redraw widget))
2719 (defun custom-face-edit-lisp (widget)
2720 "Edit the lisp representation of the value of WIDGET."
2721 (widget-put widget :custom-state 'unknown)
2722 (widget-put widget :custom-form 'lisp)
2723 (custom-redraw widget))
2725 (defun custom-face-state-set (widget)
2726 "Set the state of WIDGET."
2727 (let* ((symbol (widget-value widget))
2728 (comment (get symbol 'face-comment))
2730 (widget-put widget :custom-state
2732 (setq tmp (get symbol 'customized-face))
2733 (setq temp (get symbol 'customized-face-comment))
2735 (if (equal temp comment)
2739 (setq tmp (get symbol 'saved-face))
2740 (setq temp (get symbol 'saved-face-comment))
2742 (if (equal temp comment)
2745 ((get symbol 'face-defface-spec)
2746 (if (equal comment nil)
2752 (defun custom-face-action (widget &optional event)
2753 "Show the menu for `custom-face' WIDGET.
2754 Optional EVENT is the location for the menu."
2755 (if (eq (widget-get widget :custom-state) 'hidden)
2756 (custom-toggle-hide widget)
2757 (let* ((completion-ignore-case t)
2758 (symbol (widget-get widget :value))
2759 (answer (widget-choose (concat "Operation on "
2760 (custom-unlispify-tag-name symbol))
2761 (custom-menu-filter custom-face-menu
2765 (funcall answer widget)))))
2767 (defun custom-face-set (widget)
2768 "Make the face attributes in WIDGET take effect."
2769 (let* ((symbol (widget-value widget))
2770 (child (car (widget-get widget :children)))
2771 (value (widget-value child))
2772 (comment-widget (widget-get widget :comment-widget))
2773 (comment (widget-value comment-widget)))
2774 (when (equal comment "")
2776 ;; Make the comment invisible by hand if it's empty
2777 (custom-comment-hide comment-widget))
2778 (put symbol 'customized-face value)
2779 (face-spec-set symbol value)
2780 (put symbol 'customized-face-comment comment)
2781 (put symbol 'face-comment comment)
2782 (custom-face-state-set widget)
2783 (custom-redraw-magic widget)))
2785 (defun custom-face-save-command (widget)
2786 "Save in `.emacs' the face attributes in WIDGET."
2787 (custom-face-save widget)
2790 (defun custom-face-save (widget)
2791 "Prepare for saving WIDGET's face attributes, but don't write `.emacs'."
2792 (let* ((symbol (widget-value widget))
2793 (child (car (widget-get widget :children)))
2794 (value (widget-value child))
2795 (comment-widget (widget-get widget :comment-widget))
2796 (comment (widget-value comment-widget)))
2797 (when (equal comment "")
2799 ;; Make the comment invisible by hand if it's empty
2800 (custom-comment-hide comment-widget))
2801 (face-spec-set symbol value)
2802 (put symbol 'saved-face value)
2803 (put symbol 'customized-face nil)
2804 (put symbol 'face-comment comment)
2805 (put symbol 'customized-face-comment nil)
2806 (put symbol 'saved-face-comment comment)
2808 (custom-face-state-set widget)
2809 (custom-redraw-magic widget)))
2811 (defun custom-face-reset-saved (widget)
2812 "Restore WIDGET to the face's default attributes."
2813 (let* ((symbol (widget-value widget))
2814 (child (car (widget-get widget :children)))
2815 (value (get symbol 'saved-face))
2816 (comment (get symbol 'saved-face-comment))
2817 (comment-widget (widget-get widget :comment-widget)))
2818 (unless (or value comment)
2819 (error "No saved value for this face"))
2820 (put symbol 'customized-face nil)
2821 (put symbol 'customized-face-comment nil)
2822 (face-spec-set symbol value)
2823 (put symbol 'face-comment comment)
2824 (widget-value-set child value)
2825 ;; This call manages the comment visibility
2826 (widget-value-set comment-widget (or comment ""))
2827 (custom-face-state-set widget)
2828 (custom-redraw-magic widget)))
2830 (defun custom-face-reset-standard (widget)
2831 "Restore WIDGET to the face's standard settings."
2832 (let* ((symbol (widget-value widget))
2833 (child (car (widget-get widget :children)))
2834 (value (get symbol 'face-defface-spec))
2835 (comment-widget (widget-get widget :comment-widget)))
2837 (error "No standard setting for this face"))
2838 (put symbol 'customized-face nil)
2839 (put symbol 'customized-face-comment nil)
2840 (when (or (get symbol 'saved-face) (get symbol 'saved-face-comment))
2841 (put symbol 'saved-face nil)
2842 (put symbol 'saved-face-comment nil)
2844 (face-spec-set symbol value)
2845 (put symbol 'face-comment nil)
2846 (widget-value-set child value)
2847 ;; This call manages the comment visibility
2848 (widget-value-set comment-widget "")
2849 (custom-face-state-set widget)
2850 (custom-redraw-magic widget)))
2852 ;;; The `face' Widget.
2854 (define-widget 'face 'default
2855 "Select and customize a face."
2856 :convert-widget 'widget-value-convert-widget
2857 :button-prefix 'widget-push-button-prefix
2858 :button-suffix 'widget-push-button-suffix
2859 :format "%t: %[select face%] %v"
2862 :value-create 'widget-face-value-create
2863 :value-delete 'widget-face-value-delete
2864 :value-get 'widget-value-value-get
2865 :validate 'widget-children-validate
2866 :action 'widget-face-action
2867 :match '(lambda (widget value) (symbolp value)))
2869 (defun widget-face-value-create (widget)
2870 ;; Create a `custom-face' child.
2871 (let* ((symbol (widget-value widget))
2872 (custom-buffer-style 'face)
2873 (child (widget-create-child-and-convert
2877 (custom-magic-reset child)
2878 (setq custom-options (cons child custom-options))
2879 (widget-put widget :children (list child))))
2881 (defun widget-face-value-delete (widget)
2882 ;; Remove the child from the options.
2883 (let ((child (car (widget-get widget :children))))
2884 (setq custom-options (delq child custom-options))
2885 (widget-children-value-delete widget)))
2887 (defvar face-history nil
2888 "History of entered face names.")
2890 (defun widget-face-action (widget &optional event)
2891 "Prompt for a face."
2892 (let ((answer (completing-read "Face: "
2893 (mapcar (lambda (face)
2894 (list (symbol-name face)))
2898 (unless (zerop (length answer))
2899 (widget-value-set widget (intern answer))
2900 (widget-apply widget :notify widget event)
2903 ;;; The `hook' Widget.
2905 (define-widget 'hook 'list
2907 :value-to-internal (lambda (widget value)
2908 (if (and value (symbolp value))
2911 :match (lambda (widget value)
2913 (widget-group-match widget value)))
2914 :convert-widget 'custom-hook-convert-widget
2917 (defun custom-hook-convert-widget (widget)
2918 ;; Handle `:custom-options'.
2919 (let* ((options (widget-get widget :options))
2920 (other `(editable-list :inline t
2921 :entry-format "%i %d%v"
2922 (function :format " %v")))
2924 (list `(checklist :inline t
2925 ,@(mapcar (lambda (entry)
2926 `(function-item ,entry))
2930 (widget-put widget :args args)
2933 ;;; The `custom-group-link' Widget.
2935 (define-widget 'custom-group-link 'link
2936 "Show parent in other window when activated."
2937 :help-echo "Create customization buffer for this group."
2938 :action 'custom-group-link-action)
2940 (defun custom-group-link-action (widget &rest ignore)
2941 (customize-group (widget-value widget)))
2943 ;;; The `custom-group' Widget.
2945 (defcustom custom-group-tag-faces nil
2946 ;; In XEmacs, this ought to play games with font size.
2947 ;; Fixme: make it do so in Emacs.
2948 "Face used for group tags.
2949 The first member is used for level 1 groups, the second for level 2,
2950 and so forth. The remaining group tags are shown with
2951 `custom-group-tag-face'."
2952 :type '(repeat face)
2953 :group 'custom-faces)
2955 (defface custom-group-tag-face-1 '((((class color)
2957 (:foreground "pink" :underline t))
2960 (:foreground "red" :underline t))
2962 "Face used for group tags.")
2964 (defface custom-group-tag-face '((((class color)
2966 (:foreground "light blue" :underline t))
2969 (:foreground "blue" :underline t))
2971 "Face used for low level group tags."
2972 :group 'custom-faces)
2974 (define-widget 'custom-group 'custom
2977 :sample-face-get 'custom-group-sample-face-get
2978 :documentation-property 'group-documentation
2979 :help-echo "Set or reset all members of this group."
2980 :value-create 'custom-group-value-create
2981 :action 'custom-group-action
2982 :custom-category 'group
2983 :custom-set 'custom-group-set
2984 :custom-save 'custom-group-save
2985 :custom-reset-current 'custom-group-reset-current
2986 :custom-reset-saved 'custom-group-reset-saved
2987 :custom-reset-standard 'custom-group-reset-standard
2988 :custom-menu 'custom-group-menu-create)
2990 (defun custom-group-sample-face-get (widget)
2991 ;; Use :sample-face.
2992 (or (nth (1- (widget-get widget :custom-level)) custom-group-tag-faces)
2993 'custom-group-tag-face))
2995 (define-widget 'custom-group-visibility 'visibility
2996 "An indicator and manipulator for hidden group contents."
2997 :create 'custom-group-visibility-create)
2999 (defun custom-group-visibility-create (widget)
3000 (let ((visible (widget-value widget)))
3002 (insert "--------")))
3003 (widget-default-create widget))
3005 (defun custom-group-members (symbol groups-only)
3006 "Return SYMBOL's custom group members.
3007 If GROUPS-ONLY non-nil, return only those members that are groups."
3008 (if (not groups-only)
3009 (get symbol 'custom-group)
3011 (dolist (entry (get symbol 'custom-group))
3012 (when (eq (nth 1 entry) 'custom-group)
3013 (push entry members)))
3014 (nreverse members))))
3016 (defun custom-group-value-create (widget)
3017 "Insert a customize group for WIDGET in the current buffer."
3018 (let* ((state (widget-get widget :custom-state))
3019 (level (widget-get widget :custom-level))
3020 ;; (indent (widget-get widget :indent))
3021 (prefix (widget-get widget :custom-prefix))
3022 (buttons (widget-get widget :buttons))
3023 (tag (widget-get widget :tag))
3024 (symbol (widget-value widget))
3025 (members (custom-group-members symbol
3026 (and (eq custom-buffer-style 'tree)
3027 custom-browse-only-groups))))
3028 (cond ((and (eq custom-buffer-style 'tree)
3030 (or members (custom-unloaded-widget-p widget)))
3031 (custom-browse-insert-prefix prefix)
3032 (push (widget-create-child-and-convert
3033 widget 'custom-browse-visibility
3034 ;; :tag-glyph "plus"
3038 ;; (widget-glyph-insert nil "-- " "horizontal")
3039 (push (widget-create-child-and-convert
3040 widget 'custom-browse-group-tag)
3042 (insert " " tag "\n")
3043 (widget-put widget :buttons buttons))
3044 ((and (eq custom-buffer-style 'tree)
3045 (zerop (length members)))
3046 (custom-browse-insert-prefix prefix)
3048 ;; (widget-glyph-insert nil "[ ]" "empty")
3049 ;; (widget-glyph-insert nil "-- " "horizontal")
3050 (push (widget-create-child-and-convert
3051 widget 'custom-browse-group-tag)
3053 (insert " " tag "\n")
3054 (widget-put widget :buttons buttons))
3055 ((eq custom-buffer-style 'tree)
3056 (custom-browse-insert-prefix prefix)
3057 (custom-load-widget widget)
3058 (if (zerop (length members))
3060 (custom-browse-insert-prefix prefix)
3062 ;; (widget-glyph-insert nil "[ ]" "empty")
3063 ;; (widget-glyph-insert nil "-- " "horizontal")
3064 (push (widget-create-child-and-convert
3065 widget 'custom-browse-group-tag)
3067 (insert " " tag "\n")
3068 (widget-put widget :buttons buttons))
3069 (push (widget-create-child-and-convert
3070 widget 'custom-browse-visibility
3071 ;; :tag-glyph "minus"
3075 ;; (widget-glyph-insert nil "-\\ " "top")
3076 (push (widget-create-child-and-convert
3077 widget 'custom-browse-group-tag)
3079 (insert " " tag "\n")
3080 (widget-put widget :buttons buttons)
3081 (message "Creating group...")
3082 (let* ((members (custom-sort-items members
3083 custom-browse-sort-alphabetically
3084 custom-browse-order-groups))
3085 (prefixes (widget-get widget :custom-prefixes))
3086 (custom-prefix-list (custom-prefix-add symbol prefixes))
3087 (extra-prefix (if (widget-get widget :custom-last)
3090 (prefix (concat prefix extra-prefix))
3093 (setq entry (car members)
3094 members (cdr members))
3095 (push (widget-create-child-and-convert
3096 widget (nth 1 entry)
3098 :tag (custom-unlispify-tag-name (nth 0 entry))
3099 :custom-prefixes custom-prefix-list
3100 :custom-level (1+ level)
3101 :custom-last (null members)
3102 :value (nth 0 entry)
3103 :custom-prefix prefix)
3105 (widget-put widget :children (reverse children)))
3106 (message "Creating group...done")))
3109 ;; Create level indicator.
3110 (unless (eq custom-buffer-style 'links)
3111 (insert-char ?\ (* custom-buffer-indent (1- level)))
3114 (let ((begin (point)))
3116 (widget-specify-sample widget begin (point)))
3118 ;; Create link/visibility indicator.
3119 (if (eq custom-buffer-style 'links)
3120 (push (widget-create-child-and-convert
3121 widget 'custom-group-link
3125 (push (widget-create-child-and-convert
3126 widget 'custom-group-visibility
3127 :help-echo "Show members of this group."
3128 :action 'custom-toggle-parent
3129 (not (eq state 'hidden)))
3132 ;; Create magic button.
3133 (let ((magic (widget-create-child-and-convert
3134 widget 'custom-magic nil)))
3135 (widget-put widget :custom-magic magic)
3136 (push magic buttons))
3138 (widget-put widget :buttons buttons)
3139 ;; Insert documentation.
3140 (if (and (eq custom-buffer-style 'links) (> level 1))
3141 (widget-put widget :documentation-indent 0))
3142 (widget-default-format-handler widget ?h))
3145 ;; Add parent groups references above the group.
3146 (if t ;;; This should test that the buffer
3147 ;;; was made to display a group.
3149 (if (custom-add-parent-links widget
3150 "Go to parent group:")
3152 ;; Create level indicator.
3153 (insert-char ?\ (* custom-buffer-indent (1- level)))
3156 (let ((start (point)))
3158 (widget-specify-sample widget start (point)))
3160 ;; Create visibility indicator.
3161 (unless (eq custom-buffer-style 'links)
3163 (push (widget-create-child-and-convert
3165 :help-echo "Hide members of this group."
3166 :action 'custom-toggle-parent
3167 (not (eq state 'hidden)))
3170 ;; Create more dashes.
3171 ;; Use 76 instead of 75 to compensate for the temporary "<"
3172 ;; added by `widget-insert'.
3173 (insert-char ?- (- 76 (current-column)
3174 (* custom-buffer-indent level)))
3176 ;; Create magic button.
3177 (let ((magic (widget-create-child-and-convert
3178 widget 'custom-magic
3181 (widget-put widget :custom-magic magic)
3182 (push magic buttons))
3184 (widget-put widget :buttons buttons)
3185 ;; Insert documentation.
3186 (widget-default-format-handler widget ?h)
3188 (if nil ;;; This should test that the buffer
3189 ;;; was not made to display a group.
3191 (insert-char ?\ custom-buffer-indent)
3192 (custom-add-parent-links widget)))
3193 (custom-add-see-also widget
3194 (make-string (* custom-buffer-indent level)
3197 (message "Creating group...")
3198 (custom-load-widget widget)
3199 (let* ((members (custom-sort-items members
3200 custom-buffer-sort-alphabetically
3201 custom-buffer-order-groups))
3202 (prefixes (widget-get widget :custom-prefixes))
3203 (custom-prefix-list (custom-prefix-add symbol prefixes))
3204 (length (length members))
3206 (children (mapcar (lambda (entry)
3207 (widget-insert "\n")
3209 Creating group members... %2d%%"
3210 (/ (* 100.0 count) length))
3211 (setq count (1+ count))
3213 (widget-create-child-and-convert
3214 widget (nth 1 entry)
3216 :tag (custom-unlispify-tag-name
3218 :custom-prefixes custom-prefix-list
3219 :custom-level (1+ level)
3220 :value (nth 0 entry))
3221 (unless (eq (preceding-char) ?\n)
3222 (widget-insert "\n"))))
3224 (message "Creating group magic...")
3225 (mapcar 'custom-magic-reset children)
3226 (message "Creating group state...")
3227 (widget-put widget :children children)
3228 (custom-group-state-update widget)
3229 (message "Creating group... done"))
3232 (insert-char ?\ (* custom-buffer-indent (1- level)))
3233 (insert "\\- " (widget-get widget :tag) " group end ")
3234 (insert-char ?- (- 75 (current-column) (* custom-buffer-indent level)))
3237 (defvar custom-group-menu
3238 '(("Set for Current Session" custom-group-set
3240 (eq (widget-get widget :custom-state) 'modified)))
3241 ("Save for Future Sessions" custom-group-save
3243 (memq (widget-get widget :custom-state) '(modified set))))
3244 ("Reset to Current" custom-group-reset-current
3246 (memq (widget-get widget :custom-state) '(modified))))
3247 ("Reset to Saved" custom-group-reset-saved
3249 (memq (widget-get widget :custom-state) '(modified set))))
3250 ("Reset to standard setting" custom-group-reset-standard
3252 (memq (widget-get widget :custom-state) '(modified set saved)))))
3253 "Alist of actions for the `custom-group' widget.
3254 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3255 the menu entry, ACTION is the function to call on the widget when the
3256 menu is selected, and FILTER is a predicate which takes a `custom-group'
3257 widget as an argument, and returns non-nil if ACTION is valid on that
3258 widget. If FILTER is nil, ACTION is always valid.")
3260 (defun custom-group-action (widget &optional event)
3261 "Show the menu for `custom-group' WIDGET.
3262 Optional EVENT is the location for the menu."
3263 (if (eq (widget-get widget :custom-state) 'hidden)
3264 (custom-toggle-hide widget)
3265 (let* ((completion-ignore-case t)
3266 (answer (widget-choose (concat "Operation on "
3267 (custom-unlispify-tag-name
3268 (widget-get widget :value)))
3269 (custom-menu-filter custom-group-menu
3273 (funcall answer widget)))))
3275 (defun custom-group-set (widget)
3276 "Set changes in all modified group members."
3277 (let ((children (widget-get widget :children)))
3278 (mapcar (lambda (child)
3279 (when (eq (widget-get child :custom-state) 'modified)
3280 (widget-apply child :custom-set)))
3283 (defun custom-group-save (widget)
3284 "Save all modified group members."
3285 (let ((children (widget-get widget :children)))
3286 (mapcar (lambda (child)
3287 (when (memq (widget-get child :custom-state) '(modified set))
3288 (widget-apply child :custom-save)))
3291 (defun custom-group-reset-current (widget)
3292 "Reset all modified group members."
3293 (let ((children (widget-get widget :children)))
3294 (mapcar (lambda (child)
3295 (when (eq (widget-get child :custom-state) 'modified)
3296 (widget-apply child :custom-reset-current)))
3299 (defun custom-group-reset-saved (widget)
3300 "Reset all modified or set group members."
3301 (let ((children (widget-get widget :children)))
3302 (mapcar (lambda (child)
3303 (when (memq (widget-get child :custom-state) '(modified set))
3304 (widget-apply child :custom-reset-saved)))
3307 (defun custom-group-reset-standard (widget)
3308 "Reset all modified, set, or saved group members."
3309 (let ((children (widget-get widget :children)))
3310 (mapcar (lambda (child)
3311 (when (memq (widget-get child :custom-state)
3312 '(modified set saved))
3313 (widget-apply child :custom-reset-standard)))
3316 (defun custom-group-state-update (widget)
3318 (unless (eq (widget-get widget :custom-state) 'hidden)
3319 (let* ((children (widget-get widget :children))
3320 (states (mapcar (lambda (child)
3321 (widget-get child :custom-state))
3323 (magics custom-magic-alist)
3326 (let ((magic (car (car magics))))
3327 (if (and (not (eq magic 'hidden))
3328 (memq magic states))
3331 (setq magics (cdr magics)))))
3332 (widget-put widget :custom-state found)))
3333 (custom-magic-reset widget))
3335 ;;; The `custom-save-all' Function.
3337 (defcustom custom-file nil
3338 "File used for storing customization information.
3339 The default is nil, which means to use your init file
3340 as specified by `user-init-file'. If you specify some other file,
3341 you need to explicitly load that file for the settings to take effect."
3342 :type '(choice (const :tag "Your Emacs init file" nil) file)
3345 (defun custom-file ()
3346 "Return the file name for saving customizations."
3350 (read-file-name "File for customizations: "
3351 "~/" nil nil ".emacs"))))
3353 (defun custom-save-delete (symbol)
3354 "Delete the call to SYMBOL from `custom-file'.
3355 Leave point at the location of the call, or after the last expression."
3356 (let ((default-major-mode))
3357 (set-buffer (find-file-noselect (custom-file))))
3358 (goto-char (point-min))
3359 ;; Skip all whitespace and comments.
3360 (while (forward-comment 1))
3362 (save-excursion (forward-sexp (buffer-size)))) ; Test for scan errors.
3365 ;; Skip all whitespace and comments.
3366 (while (forward-comment 1))
3367 (let ((start (point))
3368 (sexp (condition-case nil
3369 (read (current-buffer))
3370 (end-of-file (throw 'found nil)))))
3371 (when (and (listp sexp)
3372 (eq (car sexp) symbol))
3373 (delete-region start (point))
3374 (throw 'found nil))))))
3376 (defun custom-save-variables ()
3377 "Save all customized variables in `custom-file'."
3379 (custom-save-delete 'custom-set-variables)
3380 (let ((standard-output (current-buffer))
3381 (saved-list (make-list 1 0))
3383 ;; First create a sorted list of saved variables.
3386 (if (get symbol 'saved-value)
3387 (nconc saved-list (list symbol)))))
3388 (setq saved-list (sort (cdr saved-list) 'string<))
3391 (princ "(custom-set-variables")
3394 (let ((value (get symbol 'saved-value))
3395 (requests (get symbol 'custom-requests))
3396 (now (not (or (get symbol 'standard-value)
3397 (and (not (boundp symbol))
3398 (not (get symbol 'force-value))))))
3399 (comment (get symbol 'saved-variable-comment))
3401 (when (or value comment)
3406 (cond ((or now requests comment)
3411 (cond ((or requests comment)
3428 (unless (looking-at "\n")
3431 (defun custom-save-faces ()
3432 "Save all customized faces in `custom-file'."
3434 (custom-save-delete 'custom-set-faces)
3435 (let ((standard-output (current-buffer))
3436 (saved-list (make-list 1 0))
3438 ;; First create a sorted list of saved faces.
3441 (if (get symbol 'saved-face)
3442 (nconc saved-list (list symbol)))))
3443 (setq saved-list (sort (cdr saved-list) 'string<))
3444 ;; The default face must be first, since it affects the others.
3445 (if (memq 'default saved-list)
3446 (setq saved-list (cons 'default (delq 'default saved-list))))
3449 (princ "(custom-set-faces")
3452 (let ((value (get symbol 'saved-face))
3453 (now (not (or (get 'default 'face-defface-spec)
3454 (and (not (custom-facep 'default))
3455 (not (get 'default 'force-face))))))
3456 (comment (get 'default 'saved-face-comment)))
3457 (unless (eq symbol 'default))
3458 ;; Don't print default face here.
3463 (cond ((or now comment)
3478 (unless (looking-at "\n")
3482 (defun customize-save-customized ()
3483 "Save all user options which have been set in this session."
3485 (mapatoms (lambda (symbol)
3486 (let ((face (get symbol 'customized-face))
3487 (value (get symbol 'customized-value))
3488 (face-comment (get symbol 'customized-face-comment))
3490 (get symbol 'customized-variable-comment)))
3492 (put symbol 'saved-face face)
3493 (put symbol 'customized-face nil))
3495 (put symbol 'saved-value value)
3496 (put symbol 'customized-value nil))
3497 (when variable-comment
3498 (put symbol 'saved-variable-comment variable-comment)
3499 (put symbol 'customized-variable-comment nil))
3501 (put symbol 'saved-face-comment face-comment)
3502 (put symbol 'customized-face-comment nil)))))
3503 ;; We really should update all custom buffers here.
3507 (defun custom-save-all ()
3508 "Save all customizations in `custom-file'."
3509 (let ((inhibit-read-only t))
3510 (custom-save-variables)
3513 (let ((default-major-mode nil))
3514 (set-buffer (find-file-noselect (custom-file))))
3517 ;;; The Customize Menu.
3521 (defcustom custom-menu-nesting 2
3522 "Maximum nesting in custom menus."
3524 :group 'custom-menu)
3526 (defun custom-face-menu-create (widget symbol)
3527 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
3528 (vector (custom-unlispify-menu-entry symbol)
3529 `(customize-face ',symbol)
3532 (defun custom-variable-menu-create (widget symbol)
3533 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
3534 (let ((type (get symbol 'custom-type)))
3535 (unless (listp type)
3536 (setq type (list type)))
3537 (if (and type (widget-get type :custom-menu))
3538 (widget-apply type :custom-menu symbol)
3539 (vector (custom-unlispify-menu-entry symbol)
3540 `(customize-variable ',symbol)
3543 ;; Add checkboxes to boolean variable entries.
3544 (widget-put (get 'boolean 'widget-type)
3545 :custom-menu (lambda (widget symbol)
3546 (vector (custom-unlispify-menu-entry symbol)
3547 `(customize-variable ',symbol)
3549 ':selected symbol)))
3551 ;; Fixme: sort out use of :filter in Emacs 21.
3552 (if nil ; (string-match "XEmacs" emacs-version)
3553 ;; XEmacs can create menus dynamically.
3554 (defun custom-group-menu-create (widget symbol)
3555 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
3556 `( ,(custom-unlispify-menu-entry symbol t)
3557 :filter (lambda (&rest junk)
3558 (cdr (custom-menu-create ',symbol)))))
3560 (defun custom-group-menu-create (widget symbol)
3561 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
3562 ;; Limit the nesting.
3563 (let ((custom-menu-nesting (1- custom-menu-nesting)))
3564 (custom-menu-create symbol))))
3567 (defun custom-menu-create (symbol)
3568 "Create menu for customization group SYMBOL.
3569 The menu is in a format applicable to `easy-menu-define'."
3570 (let* ((item (vector (custom-unlispify-menu-entry symbol)
3571 `(customize-group ',symbol)
3573 (if (and (or (not (boundp 'custom-menu-nesting))
3574 (>= custom-menu-nesting 0))
3575 (< (length (get symbol 'custom-group)) widget-menu-max-size))
3576 (let ((custom-prefix-list (custom-prefix-add symbol
3577 custom-prefix-list))
3578 (members (custom-sort-items (get symbol 'custom-group)
3579 custom-menu-sort-alphabetically
3580 custom-menu-order-groups)))
3581 (custom-load-symbol symbol)
3582 `(,(custom-unlispify-menu-entry symbol t)
3585 ,@(mapcar (lambda (entry)
3586 (widget-apply (if (listp (nth 1 entry))
3588 (list (nth 1 entry)))
3589 :custom-menu (nth 0 entry)))
3594 (defun customize-menu-create (symbol &optional name)
3595 "Return a customize menu for customization group SYMBOL.
3596 If optional NAME is given, use that as the name of the menu.
3597 Otherwise the menu will be named `Customize'.
3598 The format is suitable for use with `easy-menu-define'."
3600 (setq name "Customize"))
3601 ;; Fixme: sort out use of :filter in Emacs 21.
3602 (if nil ;(string-match "XEmacs" emacs-version)
3603 ;; We can delay it under XEmacs.
3605 :filter (lambda (&rest junk)
3606 (cdr (custom-menu-create ',symbol))))
3607 ;; But we must create it now under Emacs.
3608 (cons name (cdr (custom-menu-create symbol)))))
3610 ;;; The Custom Mode.
3612 (defvar custom-mode-map nil
3613 "Keymap for `custom-mode'.")
3615 (unless custom-mode-map
3616 (setq custom-mode-map (make-sparse-keymap))
3617 (set-keymap-parent custom-mode-map widget-keymap)
3618 (suppress-keymap custom-mode-map)
3619 (define-key custom-mode-map " " 'scroll-up)
3620 (define-key custom-mode-map "\177" 'scroll-down)
3621 (define-key custom-mode-map "q" 'Custom-buffer-done)
3622 (define-key custom-mode-map "u" 'Custom-goto-parent)
3623 (define-key custom-mode-map "n" 'widget-forward)
3624 (define-key custom-mode-map "p" 'widget-backward)
3625 (define-key custom-mode-map [mouse-1] 'Custom-move-and-invoke))
3627 (defun Custom-move-and-invoke (event)
3628 "Move to where you click, and if it is an active field, invoke it."
3630 (mouse-set-point event)
3631 (if (widget-event-point event)
3632 (let* ((pos (widget-event-point event))
3633 (button (get-char-property pos 'button)))
3635 (widget-button-click event)))))
3637 (easy-menu-define Custom-mode-menu
3639 "Menu used in customization buffers."
3641 ,(customize-menu-create 'customize)
3642 ["Set" Custom-set t]
3643 ["Save" Custom-save t]
3644 ["Reset to Current" Custom-reset-current t]
3645 ["Reset to Saved" Custom-reset-saved t]
3646 ["Reset to Standard Settings" Custom-reset-standard t]
3647 ["Info" (Info-goto-node "(emacs)Easy Customization") t]))
3649 (defun Custom-goto-parent ()
3650 "Go to the parent group listed at the top of this buffer.
3651 If several parents are listed, go to the first of them."
3654 (goto-char (point-min))
3655 (if (search-forward "\nGo to parent group: " nil t)
3656 (let* ((button (get-char-property (point) 'button))
3657 (parent (downcase (widget-get button :tag))))
3658 (customize-group parent)))))
3660 (defcustom custom-mode-hook nil
3661 "Hook called when entering Custom mode."
3663 :group 'custom-buffer )
3665 (defun custom-state-buffer-message (widget)
3666 (if (eq (widget-get (widget-get widget :parent) :custom-state) 'modified)
3667 (message "To install your edits, invoke [State] and choose the Set operation")))
3669 (defun custom-mode ()
3670 "Major mode for editing customization buffers.
3672 The following commands are available:
3674 Move to next button or editable field. \\[widget-forward]
3675 Move to previous button or editable field. \\[widget-backward]
3676 \\<widget-field-keymap>\
3677 Complete content of editable text field. \\[widget-complete]
3678 \\<custom-mode-map>\
3679 Invoke button under the mouse pointer. \\[Custom-move-and-invoke]
3680 Invoke button under point. \\[widget-button-press]
3681 Set all modifications. \\[Custom-set]
3682 Make all modifications default. \\[Custom-save]
3683 Reset all modified options. \\[Custom-reset-current]
3684 Reset all modified or set options. \\[Custom-reset-saved]
3685 Reset all options. \\[Custom-reset-standard]
3687 Entry to this mode calls the value of `custom-mode-hook'
3688 if that value is non-nil."
3689 (kill-all-local-variables)
3690 (setq major-mode 'custom-mode
3692 (use-local-map custom-mode-map)
3693 (easy-menu-add Custom-mode-menu)
3694 (make-local-variable 'custom-options)
3695 (make-local-variable 'widget-documentation-face)
3696 (setq widget-documentation-face 'custom-documentation-face)
3697 (make-local-variable 'widget-button-face)
3698 (setq widget-button-face 'custom-button-face)
3699 (set (make-local-variable 'widget-button-pressed-face)
3700 'custom-button-pressed-face)
3701 (set (make-local-variable 'widget-mouse-face)
3702 'custom-button-pressed-face) ; buttons `depress' when moused
3703 ;; When possible, use relief for buttons, not bracketing. This test
3704 ;; may not be optimal.
3705 (when custom-raised-buttons
3706 (set (make-local-variable 'widget-push-button-prefix) "")
3707 (set (make-local-variable 'widget-push-button-suffix) "")
3708 (set (make-local-variable 'widget-link-prefix) "")
3709 (set (make-local-variable 'widget-link-suffix) ""))
3710 (make-local-hook 'widget-edit-functions)
3711 (add-hook 'widget-edit-functions 'custom-state-buffer-message nil t)
3712 (run-hooks 'custom-mode-hook))
3718 ;;; cus-edit.el ends here