1 ;;; cus-edit.el --- Tools for customizating Emacs and Lisp packages.
3 ;; Copyright (C) 1996, 1997 Free Software Foundation, Inc.
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
6 ;; Keywords: help, faces
8 ;; X-URL: http://www.dina.kvl.dk/~abraham/custom/
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
29 ;; This file implements the code to create and edit customize buffers.
33 ;; No commands should have names starting with `custom-' because
34 ;; that interferes with completion. Use `customize-' for commands
35 ;; that the user will run with M-x, and `Custom-' for interactive commands.
42 (eval-when-compile (require 'cl))
52 (define-widget-keywords :custom-last :custom-prefix :custom-category
53 :custom-prefixes :custom-menu
55 :custom-magic :custom-state :custom-level :custom-form
56 :custom-set :custom-save :custom-reset-current :custom-reset-saved
57 :custom-reset-standard)
59 (put 'custom-define-hook 'custom-type 'hook)
60 (put 'custom-define-hook 'standard-value '(nil))
61 (custom-add-to-group 'customize 'custom-define-hook 'custom-variable)
63 ;;; Customization Groups.
66 "Customization of the One True Editor."
67 :link '(custom-manual "(emacs)Top"))
69 ;; Most of these groups are stolen from `finder.el',
71 "Basic text editing facilities."
75 "Abbreviation handling, typing shortcuts, macros."
79 (defgroup matching nil
80 "Various sorts of searching and matching."
83 (defgroup emulations nil
84 "Emulations of other editors."
91 (defgroup outlines nil
92 "Support for hierarchical outlining."
95 (defgroup external nil
96 "Interfacing to external utilities."
100 "Code related to the `bib' bibliography processor."
104 (defgroup processes nil
105 "Process, subshell, compilation, and job control support."
109 (defgroup convenience nil
110 "Convenience features for faster editing."
113 (defgroup programming nil
114 "Support for programming in other languages."
117 (defgroup languages nil
118 "Specialized modes for editing programming languages."
122 "Lisp support, including Emacs Lisp."
127 "Support for the C language and related languages."
135 "Support for object-oriented programming."
138 (defgroup applications nil
139 "Applications written in Emacs."
142 (defgroup calendar nil
143 "Calendar and time management support."
144 :group 'applications)
147 "Modes for electronic-mail handling."
148 :group 'applications)
151 "Support for netnews reading and posting."
152 :group 'applications)
155 "Games, jokes and amusements."
156 :group 'applications)
158 (defgroup development nil
159 "Support for further development of Emacs."
163 "Support for Emacs documentation."
166 (defgroup extensions nil
167 "Emacs Lisp language extensions."
170 (defgroup internal nil
171 "Code for Emacs internals, build process, defaults."
175 "Maintenance aids for the Emacs development group."
179 (defgroup environment nil
180 "Fitting Emacs with its environment."
184 "Communications, networking, remote access to files."
188 (defgroup hardware nil
189 "Support for interfacing with exotic hardware."
192 (defgroup terminals nil
193 "Support for terminal types."
197 "Front-ends/assistants for, or emulators of, UNIX features."
201 "Support code for vms."
205 "Internationalization and alternate character-set support."
210 "The X Window system."
214 "Support for Emacs frames and window systems."
218 "Support editing files of data."
222 "Support editing files."
230 "Code related to the TeX formatter."
234 "Support for multiple fonts."
237 (defgroup hypermedia nil
238 "Support for links between text or other media types."
242 "Support for on-line help systems."
246 "Code local to your site."
249 (defgroup customize '((widgets custom-group))
250 "Customization of the Customization support."
251 :link '(custom-manual "(elisp)Customization")
252 :link '(url-link :tag "Development Page"
253 "http://www.dina.kvl.dk/~abraham/custom/")
257 (defgroup custom-faces nil
258 "Faces used by customize."
262 (defgroup custom-browse nil
263 "Control customize browser."
267 (defgroup custom-buffer nil
268 "Control customize buffers."
272 (defgroup custom-menu nil
273 "Control customize menus."
277 (defgroup abbrev-mode nil
278 "Word abbreviations mode."
282 "Storage allocation and gc for GNU Emacs Lisp interpreter."
283 :tag "Storage Allocation"
287 "Undoing changes in buffers."
290 (defgroup modeline nil
291 "Content of the modeline."
295 "Indenting and filling text."
298 (defgroup editing-basics nil
299 "Most basic editing facilities."
302 (defgroup display nil
303 "How characters are displayed in buffers."
306 (defgroup execute nil
307 "Executing external commands."
310 (defgroup installation nil
311 "The Emacs installation."
319 "Internal Emacs limits."
323 "Debugging Emacs itself."
326 (defgroup minibuffer nil
327 "Controling the behaviour of the minibuffer."
330 (defgroup keyboard nil
331 "Input from the keyboard."
335 "Input from the mouse."
339 "Input from the menus."
342 (defgroup auto-save nil
343 "Preventing accidential loss of data."
346 (defgroup processes-basics nil
347 "Basic stuff dealing with processes."
351 "MULE Emacs internationalization."
354 (defgroup windows nil
355 "Windows within a frame."
360 (defun custom-last (x &optional n)
361 ;; Stolen from `cl.el'.
362 "Returns the last link in the list LIST.
363 With optional argument N, returns Nth-to-last link (default 1)."
366 (while (consp p) (incf m) (pop p))
368 (if (< n m) (nthcdr (- m n) x) x)))
369 (while (consp (cdr x)) (pop x))
372 (defun custom-quote (sexp)
373 "Quote SEXP iff it is not self quoting."
374 (if (or (memq sexp '(t nil))
376 (eq (aref (symbol-name sexp) 0) ?:))
378 (memq (car sexp) '(lambda)))
381 (and (fboundp 'characterp)
386 (defun custom-split-regexp-maybe (regexp)
387 "If REGEXP is a string, split it to a list at `\\|'.
388 You can get the original back with from the result with:
389 (mapconcat 'identity result \"\\|\")
391 IF REGEXP is not a string, return it unchanged."
395 (while (string-match "\\\\|" regexp start)
396 (setq all (cons (substring regexp start (match-beginning 0)) all)
397 start (match-end 0)))
398 (nreverse (cons (substring regexp start) all)))
401 (defun custom-variable-prompt ()
402 ;; Code stolen from `help.el'.
403 "Prompt for a variable, defaulting to the variable at point.
404 Return a list suitable for use in `interactive'."
405 (let ((v (variable-at-point))
406 (enable-recursive-minibuffers t)
408 (setq val (completing-read
410 (format "Customize option: (default %s) " v)
411 "Customize variable: ")
412 obarray (lambda (symbol)
414 (or (get symbol 'custom-type)
415 (get symbol 'custom-loads)
416 (user-variable-p symbol)))) t))
417 (list (if (equal val "")
418 (if (symbolp v) v nil)
421 (defun custom-menu-filter (menu widget)
422 "Convert MENU to the form used by `widget-choose'.
423 MENU should be in the same format as `custom-variable-menu'.
424 WIDGET is the widget to apply the filter entries of MENU on."
426 current name action filter)
428 (setq current (car menu)
430 action (nth 1 current)
431 filter (nth 2 current)
433 (if (or (null filter) (funcall filter widget))
434 (push (cons name action) result)
440 (defvar custom-prefix-list nil
441 "List of prefixes that should be ignored by `custom-unlispify'")
443 (defcustom custom-unlispify-menu-entries t
444 "Display menu entries as words instead of symbols if non nil."
448 (defcustom custom-unlispify-remove-prefixes nil
449 "Non-nil means remove group prefixes from option names in buffer."
453 (defun custom-unlispify-menu-entry (symbol &optional no-suffix)
454 "Convert symbol into a menu entry."
455 (cond ((not custom-unlispify-menu-entries)
456 (symbol-name symbol))
457 ((get symbol 'custom-tag)
459 (get symbol 'custom-tag)
460 (concat (get symbol 'custom-tag) "...")))
463 (set-buffer (get-buffer-create " *Custom-Work*"))
465 (princ symbol (current-buffer))
466 (goto-char (point-min))
467 (when (and (eq (get symbol 'custom-type) 'boolean)
468 (re-search-forward "-p\\'" nil t))
469 (replace-match "" t t)
470 (goto-char (point-min)))
471 (if custom-unlispify-remove-prefixes
472 (let ((prefixes custom-prefix-list)
475 (setq prefix (car prefixes))
476 (if (search-forward prefix (+ (point) (length prefix)) t)
479 (delete-region (point-min) (point)))
480 (setq prefixes (cdr prefixes))))))
481 (subst-char-in-region (point-min) (point-max) ?- ?\ t)
482 (capitalize-region (point-min) (point-max))
484 (goto-char (point-max))
488 (defcustom custom-unlispify-tag-names t
489 "Display tag names as words instead of symbols if non nil."
490 :group 'custom-buffer
493 (defun custom-unlispify-tag-name (symbol)
494 "Convert symbol into a menu entry."
495 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names))
496 (custom-unlispify-menu-entry symbol t)))
498 (defun custom-prefix-add (symbol prefixes)
499 ;; Addd SYMBOL to list of ignored PREFIXES.
500 (cons (or (get symbol 'custom-prefix)
501 (concat (symbol-name symbol) "-"))
506 (defcustom custom-guess-name-alist
511 ("-function\\'" function)
512 ("-functions\\'" (repeat function))
513 ("-list\\'" (repeat sexp))
514 ("-alist\\'" (repeat (cons sexp sexp))))
515 "Alist of (MATCH TYPE).
517 MATCH should be a regexp matching the name of a symbol, and TYPE should
518 be a widget suitable for editing the value of that symbol. The TYPE
519 of the first entry where MATCH matches the name of the symbol will be
522 This is used for guessing the type of variables not declared with
524 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
527 (defcustom custom-guess-doc-alist
528 '(("\\`\\*?Non-nil " boolean))
529 "Alist of (MATCH TYPE).
531 MATCH should be a regexp matching a documentation string, and TYPE
532 should be a widget suitable for editing the value of a variable with
533 that documentation string. The TYPE of the first entry where MATCH
534 matches the name of the symbol will be used.
536 This is used for guessing the type of variables not declared with
538 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
541 (defun custom-guess-type (symbol)
542 "Guess a widget suitable for editing the value of SYMBOL.
543 This is done by matching SYMBOL with `custom-guess-name-alist' and
544 if that fails, the doc string with `custom-guess-doc-alist'."
545 (let ((name (symbol-name symbol))
546 (names custom-guess-name-alist)
549 (setq current (car names)
551 (when (string-match (nth 0 current) name)
552 (setq found (nth 1 current)
555 (let ((doc (documentation-property symbol 'variable-documentation))
556 (docs custom-guess-doc-alist))
559 (setq current (car docs)
561 (when (string-match (nth 0 current) doc)
562 (setq found (nth 1 current)
568 (defcustom custom-browse-sort-alphabetically nil
569 "If non-nil, sort members of each customization group alphabetically."
571 :group 'custom-browse)
573 (defcustom custom-browse-order-groups nil
574 "If non-nil, order group members within each customization group.
575 If `first', order groups before non-groups.
576 If `last', order groups after non-groups."
577 :type '(choice (const first)
579 (const :tag "none" nil))
580 :group 'custom-browse)
582 (defcustom custom-browse-only-groups nil
583 "If non-nil, show group members only within each customization group."
585 :group 'custom-browse)
587 (defcustom custom-buffer-sort-alphabetically nil
588 "If non-nil, sort members of each customization group alphabetically."
590 :group 'custom-buffer)
592 (defcustom custom-buffer-order-groups 'last
593 "If non-nil, order group members within each customization group.
594 If `first', order groups before non-groups.
595 If `last', order groups after non-groups."
596 :type '(choice (const first)
598 (const :tag "none" nil))
599 :group 'custom-buffer)
601 (defcustom custom-menu-sort-alphabetically nil
602 "If non-nil, sort members of each customization group alphabetically."
606 (defcustom custom-menu-order-groups 'first
607 "If non-nil, order group members within each customization group.
608 If `first', order groups before non-groups.
609 If `last', order groups after non-groups."
610 :type '(choice (const first)
612 (const :tag "none" nil))
615 ;;;###autoload (add-hook 'same-window-regexps "\\`\\*Customiz.*\\*\\'")
617 (defun custom-sort-items (items sort-alphabetically order-groups)
618 "Return a sorted copy of ITEMS.
619 ITEMS should be a `custom-group' property.
620 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
621 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
622 groups after non-groups, if nil do not order groups at all."
623 (sort (copy-sequence items)
625 (let ((typea (nth 1 a)) (typeb (nth 1 b))
626 (namea (symbol-name (nth 0 a))) (nameb (symbol-name (nth 0 b))))
627 (cond ((not order-groups)
628 ;; Since we don't care about A and B order, maybe sort.
629 (when sort-alphabetically
630 (string-lessp namea nameb)))
631 ((eq typea 'custom-group)
632 ;; If B is also a group, maybe sort. Otherwise, order A and B.
633 (if (eq typeb 'custom-group)
634 (when sort-alphabetically
635 (string-lessp namea nameb))
636 (eq order-groups 'first)))
637 ((eq typeb 'custom-group)
638 ;; Since A cannot be a group, order A and B.
639 (eq order-groups 'last))
641 ;; Since A and B cannot be groups, sort.
642 (string-lessp namea nameb)))))))
644 ;;; Custom Mode Commands.
646 (defvar custom-options nil
647 "Customization widgets in the current buffer.")
650 "Set changes in all modified options."
652 (let ((children custom-options))
653 (mapcar (lambda (child)
654 (when (eq (widget-get child :custom-state) 'modified)
655 (widget-apply child :custom-set)))
658 (defun Custom-save ()
659 "Set all modified group members and save them."
661 (let ((children custom-options))
662 (mapcar (lambda (child)
663 (when (memq (widget-get child :custom-state)
664 '(modified set changed rogue))
665 (widget-apply child :custom-save)))
669 (defvar custom-reset-menu
670 '(("Current" . Custom-reset-current)
671 ("Saved" . Custom-reset-saved)
672 ("Standard Settings" . Custom-reset-standard))
673 "Alist of actions for the `Reset' button.
674 The key is a string containing the name of the action, the value is a
675 lisp function taking the widget as an element which will be called
676 when the action is chosen.")
678 (defun custom-reset (event)
679 "Select item from reset menu."
680 (let* ((completion-ignore-case t)
681 (answer (widget-choose "Reset to"
687 (defun Custom-reset-current (&rest ignore)
688 "Reset all modified group members to their current value."
690 (let ((children custom-options))
691 (mapcar (lambda (widget)
692 (and (default-boundp (widget-value widget))
693 (if (memq (widget-get widget :custom-state)
695 (widget-apply widget :custom-reset-current))))
698 (defun Custom-reset-saved (&rest ignore)
699 "Reset all modified or set group members to their saved value."
701 (let ((children custom-options))
702 (mapcar (lambda (widget)
703 (and (get (widget-value widget) 'saved-value)
704 (if (memq (widget-get widget :custom-state)
705 '(modified set changed rogue))
706 (widget-apply widget :custom-reset-saved))))
709 (defun Custom-reset-standard (&rest ignore)
710 "Reset all modified, set, or saved group members to their standard settings."
712 (let ((children custom-options))
713 (mapcar (lambda (widget)
714 (and (get (widget-value widget) 'standard-value)
715 (if (memq (widget-get widget :custom-state)
716 '(modified set changed saved rogue))
717 (widget-apply widget :custom-reset-standard))))
720 ;;; The Customize Commands
722 (defun custom-prompt-variable (prompt-var prompt-val)
723 "Prompt for a variable and a value and return them as a list.
724 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
725 prompt for the value. The %s escape in PROMPT-VAL is replaced with
726 the name of the variable.
728 If the variable has a `variable-interactive' property, that is used as if
729 it were the arg to `interactive' (which see) to interactively read the value.
731 If the variable has a `custom-type' property, it must be a widget and the
732 `:prompt-value' property of that widget will be used for reading the value."
733 (let* ((var (read-variable prompt-var))
734 (minibuffer-help-form '(describe-variable var)))
736 (let ((prop (get var 'variable-interactive))
737 (type (get var 'custom-type))
738 (prompt (format prompt-val var)))
740 (setq type (list type)))
742 ;; Use VAR's `variable-interactive' property
743 ;; as an interactive spec for prompting.
744 (call-interactively (list 'lambda '(arg)
745 (list 'interactive prop)
748 (widget-prompt-value type
754 (eval-minibuffer prompt)))))))
757 (defun customize-set-value (var val)
758 "Set VARIABLE to VALUE. VALUE is a Lisp object.
760 If VARIABLE has a `variable-interactive' property, that is used as if
761 it were the arg to `interactive' (which see) to interactively read the value.
763 If VARIABLE has a `custom-type' property, it must be a widget and the
764 `:prompt-value' property of that widget will be used for reading the value."
765 (interactive (custom-prompt-variable "Set variable: "
766 "Set %s to value: "))
771 (defun customize-set-variable (var val)
772 "Set the default for VARIABLE to VALUE. VALUE is a Lisp object.
774 If VARIABLE has a `custom-set' property, that is used for setting
775 VARIABLE, otherwise `set-default' is used.
777 The `customized-value' property of the VARIABLE will be set to a list
778 with a quoted VALUE as its sole list member.
780 If VARIABLE has a `variable-interactive' property, that is used as if
781 it were the arg to `interactive' (which see) to interactively read the value.
783 If VARIABLE has a `custom-type' property, it must be a widget and the
784 `:prompt-value' property of that widget will be used for reading the value. "
785 (interactive (custom-prompt-variable "Set variable: "
786 "Set customized value for %s to: "))
787 (funcall (or (get var 'custom-set) 'set-default) var val)
788 (put var 'customized-value (list (custom-quote val))))
791 (defun customize-save-variable (var val)
792 "Set the default for VARIABLE to VALUE, and save it for future sessions.
793 If VARIABLE has a `custom-set' property, that is used for setting
794 VARIABLE, otherwise `set-default' is used.
796 The `customized-value' property of the VARIABLE will be set to a list
797 with a quoted VALUE as its sole list member.
799 If VARIABLE has a `variable-interactive' property, that is used as if
800 it were the arg to `interactive' (which see) to interactively read the value.
802 If VARIABLE has a `custom-type' property, it must be a widget and the
803 `:prompt-value' property of that widget will be used for reading the value. "
804 (interactive (custom-prompt-variable "Set and ave variable: "
805 "Set and save value for %s as: "))
806 (funcall (or (get var 'custom-set) 'set-default) var val)
807 (put var 'saved-value (list (custom-quote val)))
812 "Select a customization buffer which you can use to set user options.
813 User options are structured into \"groups\".
814 Initially the top-level group `Emacs' and its immediate subgroups
815 are shown; the contents of those subgroups are initially hidden."
817 (customize-group 'emacs))
820 (defun customize-group (group)
821 "Customize GROUP, which must be a customization group."
822 (interactive (list (let ((completion-ignore-case t))
823 (completing-read "Customize group: (default emacs) "
826 (or (get symbol 'custom-loads)
827 (get symbol 'custom-group)))
829 (when (stringp group)
830 (if (string-equal "" group)
832 (setq group (intern group))))
833 (or (get group 'custom-group)
834 (custom-load-symbol group))
835 (let ((name (format "*Customize Group: %s*"
836 (custom-unlispify-tag-name group))))
837 (if (get-buffer name)
839 (custom-buffer-create (list (list group 'custom-group))
841 (concat " for group "
842 (custom-unlispify-tag-name group))))))
845 (defun customize-group-other-window (group)
846 "Customize GROUP, which must be a customization group."
847 (interactive (list (let ((completion-ignore-case t))
848 (completing-read "Customize group: (default emacs) "
851 (or (get symbol 'custom-loads)
852 (get symbol 'custom-group)))
854 (when (stringp group)
855 (if (string-equal "" group)
857 (setq group (intern group))))
858 (or (get group 'custom-group)
859 (custom-load-symbol group))
860 (let ((name (format "*Customize Group: %s*"
861 (custom-unlispify-tag-name group))))
862 (if (get-buffer name)
863 (let ((window (selected-window)))
865 (select-window window))
866 (custom-buffer-create-other-window
867 (list (list group 'custom-group))
869 (concat " for group "
870 (custom-unlispify-tag-name group))))))
873 (defalias 'customize-variable 'customize-option)
876 (defun customize-option (symbol)
877 "Customize SYMBOL, which must be a user option variable."
878 (interactive (custom-variable-prompt))
879 ;; If we don't have SYMBOL's real definition loaded,
881 (unless (get symbol 'custom-type)
882 (let ((loaddefs-file (locate-library "loaddefs.el" t))
884 ;; See if it is autoloaded from some library.
887 (insert-file-contents loaddefs-file)
888 (when (re-search-forward (concat "^(defvar " (symbol-name symbol))
890 (search-backward "\n;;; Generated autoloads from ")
891 (goto-char (match-end 0))
892 (setq file (buffer-substring (point)
893 (progn (end-of-line) (point)))))))
894 ;; If it is, load that library.
896 (when (string-match "\\.el\\'" file)
897 (setq file (substring file 0 (match-beginning 0))))
899 (unless (get symbol 'custom-type)
900 (error "Variable %s cannot be customized" symbol))
901 (custom-buffer-create (list (list symbol 'custom-variable))
902 (format "*Customize Option: %s*"
903 (custom-unlispify-tag-name symbol))))
905 (defvar customize-changed-options-previous-release "20.2"
906 "Version for `customize-changed-options' to refer back to by default.")
909 (defun customize-changed-options (since-version)
910 "Customize all user option variables changed in Emacs itself.
911 This includes new user option variables and faces, and new
912 customization groups, as well as older options and faces whose default
913 values have changed since the previous major Emacs release.
915 With argument SINCE-VERSION (a string), customize all user option
916 variables that were added (or their meanings were changed) since that
919 (interactive "sCustomize options changed, since version (default all versions): ")
920 (if (equal since-version "")
921 (setq since-version nil))
922 (unless since-version
923 (setq since-version customize-changed-options-previous-release))
926 (mapatoms (lambda (symbol)
927 (and (or (boundp symbol)
928 ;; For variables not yet loaded.
929 (get symbol 'standard-value)
930 ;; For groups the previous test fails, this one
931 ;; could be used to determine if symbol is a
932 ;; group. Is there a better way for this?
933 (get symbol 'group-documentation))
934 (let ((version (get symbol 'custom-version)))
936 (or (null since-version)
937 (customize-version-lessp since-version version))
938 (if (member version versions)
940 ;;; Collect all versions that we use.
941 (push version versions))))
943 ;; We have to set the right thing here,
944 ;; depending if we have a group or a
946 (if (get symbol 'group-documentation)
947 (cons (list symbol 'custom-group) found)
948 (cons (list symbol 'custom-variable) found))))))
950 (error "No user option defaults have been changed since Emacs %s"
955 (cdr (assoc (car versions) custom-versions-load-alist)))
957 (setq versions (cdr versions)))
958 (put 'custom-versions-load-alist 'custom-loads
959 ;; Get all the files that correspond to element from the
960 ;; VERSIONS list. This could use some simplification.
961 (apply 'nconc flist)))
962 ;; Because we set all the files needed to be loaded as a
963 ;; `custom-loads' property to `custom-versions-load-alist' this
964 ;; call will actually load them.
965 (custom-load-symbol 'custom-versions-load-alist)
967 (put 'custom-versions-load-alist 'custom-loads nil)
968 (custom-buffer-create (custom-sort-items found t 'first)
969 "*Customize Changed Options*"))))
971 (defun customize-version-lessp (version1 version2)
972 ;; In case someone made a mistake and left out the quotes
973 ;; in the :version value.
974 (if (numberp version2)
975 (setq version2 (prin1-to-string version2)))
976 (let (major1 major2 minor1 minor2)
977 (string-match "\\([0-9]+\\)[.]\\([0-9]+\\)" version1)
978 (setq major1 (read (match-string 1 version1)))
979 (setq minor1 (read (match-string 2 version1)))
980 (string-match "\\([0-9]+\\)[.]\\([0-9]+\\)" version2)
981 (setq major2 (read (match-string 1 version2)))
982 (setq minor2 (read (match-string 2 version2)))
983 (or (< major1 major2)
984 (and (= major1 major2)
985 (< minor1 minor2)))))
988 (defalias 'customize-variable-other-window 'customize-option-other-window)
991 (defun customize-option-other-window (symbol)
992 "Customize SYMBOL, which must be a user option variable.
993 Show the buffer in another window, but don't select it."
994 (interactive (custom-variable-prompt))
995 (custom-buffer-create-other-window
996 (list (list symbol 'custom-variable))
997 (format "*Customize Option: %s*" (custom-unlispify-tag-name symbol))))
1000 (defun customize-face (&optional symbol)
1001 "Customize SYMBOL, which should be a face name or nil.
1002 If SYMBOL is nil, customize all faces."
1003 (interactive (list (completing-read "Customize face: (default all) "
1004 obarray 'custom-facep)))
1005 (if (or (null symbol) (and (stringp symbol) (zerop (length symbol))))
1006 (custom-buffer-create (custom-sort-items
1007 (mapcar (lambda (symbol)
1008 (list symbol 'custom-face))
1011 "*Customize Faces*")
1012 (when (stringp symbol)
1013 (setq symbol (intern symbol)))
1014 (unless (symbolp symbol)
1015 (error "Should be a symbol %S" symbol))
1016 (custom-buffer-create (list (list symbol 'custom-face))
1017 (format "*Customize Face: %s*"
1018 (custom-unlispify-tag-name symbol)))))
1021 (defun customize-face-other-window (&optional symbol)
1022 "Show customization buffer for FACE in other window."
1023 (interactive (list (completing-read "Customize face: "
1024 obarray 'custom-facep)))
1025 (if (or (null symbol) (and (stringp symbol) (zerop (length symbol))))
1027 (if (stringp symbol)
1028 (setq symbol (intern symbol)))
1029 (unless (symbolp symbol)
1030 (error "Should be a symbol %S" symbol))
1031 (custom-buffer-create-other-window
1032 (list (list symbol 'custom-face))
1033 (format "*Customize Face: %s*" (custom-unlispify-tag-name symbol)))))
1036 (defun customize-customized ()
1037 "Customize all user options set since the last save in this session."
1040 (mapatoms (lambda (symbol)
1041 (and (get symbol 'customized-face)
1042 (custom-facep symbol)
1043 (push (list symbol 'custom-face) found))
1044 (and (get symbol 'customized-value)
1046 (push (list symbol 'custom-variable) found))))
1048 (error "No customized user options")
1049 (custom-buffer-create (custom-sort-items found t nil)
1050 "*Customize Customized*"))))
1053 (defun customize-saved ()
1054 "Customize all already saved user options."
1057 (mapatoms (lambda (symbol)
1058 (and (get symbol 'saved-face)
1059 (custom-facep symbol)
1060 (push (list symbol 'custom-face) found))
1061 (and (get symbol 'saved-value)
1063 (push (list symbol 'custom-variable) found))))
1065 (error "No saved user options")
1066 (custom-buffer-create (custom-sort-items found t nil)
1067 "*Customize Saved*"))))
1070 (defun customize-apropos (regexp &optional all)
1071 "Customize all user options matching REGEXP.
1072 If ALL is `options', include only options.
1073 If ALL is `faces', include only faces.
1074 If ALL is `groups', include only groups.
1075 If ALL is t (interactively, with prefix arg), include options which are not
1076 user-settable, as well as faces and groups."
1077 (interactive "sCustomize regexp: \nP")
1079 (mapatoms (lambda (symbol)
1080 (when (string-match regexp (symbol-name symbol))
1081 (when (and (not (memq all '(faces options)))
1082 (get symbol 'custom-group))
1083 (push (list symbol 'custom-group) found))
1084 (when (and (not (memq all '(options groups)))
1085 (custom-facep symbol))
1086 (push (list symbol 'custom-face) found))
1087 (when (and (not (memq all '(groups faces)))
1089 (or (get symbol 'saved-value)
1090 (get symbol 'standard-value)
1091 (if (memq all '(nil options))
1092 (user-variable-p symbol)
1093 (get symbol 'variable-documentation))))
1094 (push (list symbol 'custom-variable) found)))))
1096 (error "No matches")
1097 (custom-buffer-create (custom-sort-items found t
1098 custom-buffer-order-groups)
1099 "*Customize Apropos*"))))
1102 (defun customize-apropos-options (regexp &optional arg)
1103 "Customize all user options matching REGEXP.
1104 With prefix arg, include options which are not user-settable."
1105 (interactive "sCustomize regexp: \nP")
1106 (customize-apropos regexp (or arg 'options)))
1109 (defun customize-apropos-faces (regexp)
1110 "Customize all user faces matching REGEXP."
1111 (interactive "sCustomize regexp: \n")
1112 (customize-apropos regexp 'faces))
1115 (defun customize-apropos-groups (regexp)
1116 "Customize all user groups matching REGEXP."
1117 (interactive "sCustomize regexp: \n")
1118 (customize-apropos regexp 'groups))
1122 (defcustom custom-buffer-style 'links
1123 "Control the presentation style for customization buffers.
1124 The value should be a symbol, one of:
1126 brackets: groups nest within each other with big horizontal brackets.
1127 links: groups have links to subgroups."
1128 :type '(radio (const brackets)
1130 :group 'custom-buffer)
1132 (defcustom custom-buffer-indent 3
1133 "Number of spaces to indent nested groups."
1135 :group 'custom-buffer)
1138 (defun custom-buffer-create (options &optional name description)
1139 "Create a buffer containing OPTIONS.
1140 Optional NAME is the name of the buffer.
1141 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1142 SYMBOL is a customization option, and WIDGET is a widget for editing
1144 (unless name (setq name "*Customization*"))
1145 (kill-buffer (get-buffer-create name))
1146 (pop-to-buffer (get-buffer-create name))
1147 (custom-buffer-create-internal options description))
1150 (defun custom-buffer-create-other-window (options &optional name description)
1151 "Create a buffer containing OPTIONS.
1152 Optional NAME is the name of the buffer.
1153 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1154 SYMBOL is a customization option, and WIDGET is a widget for editing
1156 (unless name (setq name "*Customization*"))
1157 (kill-buffer (get-buffer-create name))
1158 (let ((window (selected-window))
1160 (special-display-buffer-names nil)
1161 (special-display-regexps nil)
1162 (same-window-buffer-names nil)
1163 (same-window-regexps nil))
1164 (pop-to-buffer (get-buffer-create name))
1165 (custom-buffer-create-internal options description)
1166 (select-window window)))
1168 (defcustom custom-reset-button-menu nil
1169 "If non-nil, only show a single reset button in customize buffers.
1170 This button will have a menu with all three reset operations."
1172 :group 'custom-buffer)
1174 (defun custom-buffer-create-internal (options &optional description)
1175 (message "Creating customization buffer...")
1177 (widget-insert "This is a customization buffer")
1179 (widget-insert description))
1181 Square brackets show active fields; type RET or click mouse-1
1182 on an active field to invoke its action. Editing an option value
1183 changes the text in the buffer; invoke the State button and
1184 choose the Set operation to set the option value.
1186 (widget-create 'info-link
1188 :help-echo "Read the online help."
1189 "(emacs)Easy Customization")
1190 (widget-insert " for more information.\n\n")
1191 (message "Creating customization buttons...")
1192 (widget-insert "Operate on everything in this buffer:\n ")
1193 (widget-create 'push-button
1194 :tag "Set for Current Session"
1196 Make your editing in this buffer take effect for this session."
1197 :action (lambda (widget &optional event)
1200 (widget-create 'push-button
1201 :tag "Save for Future Sessions"
1203 Make your editing in this buffer take effect for future Emacs sessions."
1204 :action (lambda (widget &optional event)
1206 (if custom-reset-button-menu
1209 (widget-create 'push-button
1211 :help-echo "Show a menu with reset operations."
1212 :mouse-down-action (lambda (&rest junk) t)
1213 :action (lambda (widget &optional event)
1214 (custom-reset event))))
1215 (widget-insert "\n ")
1216 (widget-create 'push-button
1219 Reset all edited text in this buffer to reflect current values."
1220 :action 'Custom-reset-current)
1222 (widget-create 'push-button
1223 :tag "Reset to Saved"
1225 Reset all values in this buffer to their saved settings."
1226 :action 'Custom-reset-saved)
1228 (widget-create 'push-button
1229 :tag "Reset to Standard"
1231 Reset all values in this buffer to their standard settings."
1232 :action 'Custom-reset-standard))
1234 (widget-create 'push-button
1236 :help-echo "Bury the buffer."
1237 :action (lambda (widget &optional event)
1239 (widget-insert "\n\n")
1240 (message "Creating customization items...")
1241 (setq custom-options
1242 (if (= (length options) 1)
1243 (mapcar (lambda (entry)
1244 (widget-create (nth 1 entry)
1245 :documentation-shown t
1246 :custom-state 'unknown
1247 :tag (custom-unlispify-tag-name
1249 :value (nth 0 entry)))
1252 (length (length options)))
1253 (mapcar (lambda (entry)
1255 (message "Creating customization items ...%2d%%"
1256 (/ (* 100.0 count) length))
1257 (widget-create (nth 1 entry)
1258 :tag (custom-unlispify-tag-name
1260 :value (nth 0 entry))
1261 (setq count (1+ count))
1262 (unless (eq (preceding-char) ?\n)
1263 (widget-insert "\n"))
1264 (widget-insert "\n")))
1266 (unless (eq (preceding-char) ?\n)
1267 (widget-insert "\n"))
1268 (message "Creating customization items ...%2d%%done" 100)
1269 (unless (eq custom-buffer-style 'tree)
1270 (mapcar 'custom-magic-reset custom-options))
1271 (message "Creating customization setup...")
1273 (goto-char (point-min))
1274 (message "Creating customization buffer...done"))
1276 ;;; The Tree Browser.
1279 (defun customize-browse (&optional group)
1280 "Create a tree browser for the customize hierarchy."
1283 (setq group 'emacs))
1284 (let ((name "*Customize Browser*"))
1285 (kill-buffer (get-buffer-create name))
1286 (pop-to-buffer (get-buffer-create name)))
1289 Square brackets show active fields; type RET or click mouse-1
1290 on an active field to invoke its action.
1291 Invoke [+] below to expand a group, and [-] to collapse an expanded group.\n")
1292 (if custom-browse-only-groups
1294 Invoke the [Group] button below to edit that item in another window.\n\n")
1295 (widget-insert "Invoke the ")
1296 (widget-create 'item
1299 :tag-glyph "folder")
1300 (widget-insert ", ")
1301 (widget-create 'item
1305 (widget-insert ", and ")
1306 (widget-create 'item
1309 :tag-glyph "option")
1310 (widget-insert " buttons below to edit that
1311 item in another window.\n\n"))
1312 (let ((custom-buffer-style 'tree))
1313 (widget-create 'custom-group
1315 :custom-state 'unknown
1316 :tag (custom-unlispify-tag-name group)
1318 (goto-char (point-min)))
1320 (define-widget 'custom-browse-visibility 'item
1321 "Control visibility of items in the customize tree browser."
1323 :action 'custom-browse-visibility-action)
1325 (defun custom-browse-visibility-action (widget &rest ignore)
1326 (let ((custom-buffer-style 'tree))
1327 (custom-toggle-parent widget)))
1329 (define-widget 'custom-browse-group-tag 'push-button
1330 "Show parent in other window when activated."
1333 :action 'custom-browse-group-tag-action)
1335 (defun custom-browse-group-tag-action (widget &rest ignore)
1336 (let ((parent (widget-get widget :parent)))
1337 (customize-group-other-window (widget-value parent))))
1339 (define-widget 'custom-browse-variable-tag 'push-button
1340 "Show parent in other window when activated."
1343 :action 'custom-browse-variable-tag-action)
1345 (defun custom-browse-variable-tag-action (widget &rest ignore)
1346 (let ((parent (widget-get widget :parent)))
1347 (customize-variable-other-window (widget-value parent))))
1349 (define-widget 'custom-browse-face-tag 'push-button
1350 "Show parent in other window when activated."
1353 :action 'custom-browse-face-tag-action)
1355 (defun custom-browse-face-tag-action (widget &rest ignore)
1356 (let ((parent (widget-get widget :parent)))
1357 (customize-face-other-window (widget-value parent))))
1359 (defconst custom-browse-alist '((" " "space")
1365 (defun custom-browse-insert-prefix (prefix)
1366 "Insert PREFIX. On XEmacs convert it to line graphics."
1367 (if nil ; (string-match "XEmacs" emacs-version)
1370 (while (not (string-equal prefix ""))
1371 (let ((entry (substring prefix 0 3)))
1372 (setq prefix (substring prefix 3))
1373 (let ((overlay (make-overlay (1- (point)) (point) nil t nil))
1374 (name (nth 1 (assoc entry custom-browse-alist))))
1375 (overlay-put overlay 'end-glyph (widget-glyph-find name entry))
1376 (overlay-put overlay 'start-open t)
1377 (overlay-put overlay 'end-open t)))))
1380 ;;; Modification of Basic Widgets.
1382 ;; We add extra properties to the basic widgets needed here. This is
1383 ;; fine, as long as we are careful to stay within out own namespace.
1385 ;; We want simple widgets to be displayed by default, but complex
1386 ;; widgets to be hidden.
1388 (widget-put (get 'item 'widget-type) :custom-show t)
1389 (widget-put (get 'editable-field 'widget-type)
1390 :custom-show (lambda (widget value)
1391 (let ((pp (pp-to-string value)))
1392 (cond ((string-match "\n" pp)
1397 (widget-put (get 'menu-choice 'widget-type) :custom-show t)
1399 ;;; The `custom-manual' Widget.
1401 (define-widget 'custom-manual 'info-link
1402 "Link to the manual entry for this customization option."
1403 :help-echo "Read the manual entry for this option."
1406 ;;; The `custom-magic' Widget.
1408 (defgroup custom-magic-faces nil
1409 "Faces used by the magic button."
1410 :group 'custom-faces
1411 :group 'custom-buffer)
1413 (defface custom-invalid-face '((((class color))
1414 (:foreground "yellow" :background "red"))
1416 (:bold t :italic t :underline t)))
1417 "Face used when the customize item is invalid."
1418 :group 'custom-magic-faces)
1420 (defface custom-rogue-face '((((class color))
1421 (:foreground "pink" :background "black"))
1424 "Face used when the customize item is not defined for customization."
1425 :group 'custom-magic-faces)
1427 (defface custom-modified-face '((((class color))
1428 (:foreground "white" :background "blue"))
1431 "Face used when the customize item has been modified."
1432 :group 'custom-magic-faces)
1434 (defface custom-set-face '((((class color))
1435 (:foreground "blue" :background "white"))
1438 "Face used when the customize item has been set."
1439 :group 'custom-magic-faces)
1441 (defface custom-changed-face '((((class color))
1442 (:foreground "white" :background "blue"))
1445 "Face used when the customize item has been changed."
1446 :group 'custom-magic-faces)
1448 (defface custom-saved-face '((t (:underline t)))
1449 "Face used when the customize item has been saved."
1450 :group 'custom-magic-faces)
1452 (defconst custom-magic-alist '((nil "#" underline "\
1453 uninitialized, you should not see this.")
1454 (unknown "?" italic "\
1455 unknown, you should not see this.")
1456 (hidden "-" default "\
1457 hidden, invoke \"Show\" in the previous line to show." "\
1458 group now hidden, invoke \"Show\", above, to show contents.")
1459 (invalid "x" custom-invalid-face "\
1460 the value displayed for this %c is invalid and cannot be set.")
1461 (modified "*" custom-modified-face "\
1462 you have edited the value as text, but you have not set the %c." "\
1463 you have edited something in this group, but not set it.")
1464 (set "+" custom-set-face "\
1465 you have set this %c, but not saved it for future sessions." "\
1466 something in this group has been set, but not saved.")
1467 (changed ":" custom-changed-face "\
1468 this %c has been changed outside the customize buffer." "\
1469 something in this group has been changed outside customize.")
1470 (saved "!" custom-saved-face "\
1471 this %c has been set and saved." "\
1472 something in this group has been set and saved.")
1473 (rogue "@" custom-rogue-face "\
1474 this %c has not been changed with customize." "\
1475 something in this group is not prepared for customization.")
1476 (standard " " nil "\
1477 this %c is unchanged from its standard setting." "\
1478 visible group members are all at standard settings."))
1479 "Alist of customize option states.
1480 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1482 STATE is one of the following symbols:
1485 For internal use, should never occur.
1487 For internal use, should never occur.
1489 This item is not being displayed.
1491 This item is modified, but has an invalid form.
1493 This item is modified, and has a valid form.
1495 This item has been set but not saved.
1497 The current value of this item has been changed temporarily.
1499 This item is marked for saving.
1501 This item has no customization information.
1503 This item is unchanged from the standard setting.
1505 MAGIC is a string used to present that state.
1507 FACE is a face used to present the state.
1509 ITEM-DESC is a string describing the state for options.
1511 GROUP-DESC is a string describing the state for groups. If this is
1512 left out, ITEM-DESC will be used.
1514 The string %c in either description will be replaced with the
1515 category of the item. These are `group'. `option', and `face'.
1517 The list should be sorted most significant first.")
1519 (defcustom custom-magic-show 'long
1520 "If non-nil, show textual description of the state.
1521 If `long', show a full-line description, not just one word."
1522 :type '(choice (const :tag "no" nil)
1524 (other :tag "short" short))
1525 :group 'custom-buffer)
1527 (defcustom custom-magic-show-hidden '(option face)
1528 "Control whether the State button is shown for hidden items.
1529 The value should be a list with the custom categories where the State
1530 button should be visible. Possible categories are `group', `option',
1532 :type '(set (const group) (const option) (const face))
1533 :group 'custom-buffer)
1535 (defcustom custom-magic-show-button nil
1536 "Show a \"magic\" button indicating the state of each customization option."
1538 :group 'custom-buffer)
1540 (define-widget 'custom-magic 'default
1541 "Show and manipulate state for a customization option."
1543 :action 'widget-parent-action
1546 :value-create 'custom-magic-value-create
1547 :value-delete 'widget-children-value-delete)
1549 (defun widget-magic-mouse-down-action (widget &optional event)
1550 ;; Non-nil unless hidden.
1551 (not (eq (widget-get (widget-get (widget-get widget :parent) :parent)
1555 (defun custom-magic-value-create (widget)
1556 ;; Create compact status report for WIDGET.
1557 (let* ((parent (widget-get widget :parent))
1558 (state (widget-get parent :custom-state))
1559 (hidden (eq state 'hidden))
1560 (entry (assq state custom-magic-alist))
1561 (magic (nth 1 entry))
1562 (face (nth 2 entry))
1563 (category (widget-get parent :custom-category))
1564 (text (or (and (eq category 'group)
1567 (form (widget-get parent :custom-form))
1569 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text)
1570 (setq text (concat (match-string 1 text)
1571 (symbol-name category)
1572 (match-string 2 text))))
1573 (when (and custom-magic-show
1575 (memq category custom-magic-show-hidden)))
1577 (when (and (eq category 'group)
1578 (not (and (eq custom-buffer-style 'links)
1579 (> (widget-get parent :custom-level) 1))))
1580 (insert-char ?\ (* custom-buffer-indent
1581 (widget-get parent :custom-level))))
1582 (push (widget-create-child-and-convert
1584 :help-echo "Change the state of this item."
1585 :format (if hidden "%t" "%[%t%]")
1586 :button-prefix 'widget-push-button-prefix
1587 :button-suffix 'widget-push-button-suffix
1588 :mouse-down-action 'widget-magic-mouse-down-action
1592 (let ((start (point)))
1593 (if (eq custom-magic-show 'long)
1595 (insert (symbol-name state)))
1596 (cond ((eq form 'lisp)
1598 ((eq form 'mismatch)
1599 (insert " (mismatch)")))
1600 (put-text-property start (point) 'face 'custom-state-face))
1602 (when (and (eq category 'group)
1603 (not (and (eq custom-buffer-style 'links)
1604 (> (widget-get parent :custom-level) 1))))
1605 (insert-char ?\ (* custom-buffer-indent
1606 (widget-get parent :custom-level))))
1607 (when custom-magic-show-button
1608 (when custom-magic-show
1609 (let ((indent (widget-get parent :indent)))
1611 (insert-char ? indent))))
1612 (push (widget-create-child-and-convert
1614 :mouse-down-action 'widget-magic-mouse-down-action
1618 :help-echo "Change the state."
1619 :format (if hidden "%t" "%[%t%]")
1620 :tag (if (memq form '(lisp mismatch))
1621 (concat "(" magic ")")
1622 (concat "[" magic "]")))
1625 (widget-put widget :children children)))
1627 (defun custom-magic-reset (widget)
1628 "Redraw the :custom-magic property of WIDGET."
1629 (let ((magic (widget-get widget :custom-magic)))
1630 (widget-value-set magic (widget-value magic))))
1632 ;;; The `custom' Widget.
1634 (defface custom-button-face nil
1635 "Face used for buttons in customization buffers."
1636 :group 'custom-faces)
1638 (defface custom-documentation-face nil
1639 "Face used for documentation strings in customization buffers."
1640 :group 'custom-faces)
1642 (defface custom-state-face '((((class color)
1644 (:foreground "lime green"))
1647 (:foreground "dark green"))
1649 "Face used for State descriptions in the customize buffer."
1650 :group 'custom-faces)
1652 (define-widget 'custom 'default
1653 "Customize a user option."
1655 :convert-widget 'custom-convert-widget
1656 :notify 'custom-notify
1659 :custom-state 'hidden
1660 :documentation-property 'widget-subclass-responsibility
1661 :value-create 'widget-subclass-responsibility
1662 :value-delete 'widget-children-value-delete
1663 :value-get 'widget-value-value-get
1664 :validate 'widget-children-validate
1665 :match (lambda (widget value) (symbolp value)))
1667 (defun custom-convert-widget (widget)
1668 ;; Initialize :value and :tag from :args in WIDGET.
1669 (let ((args (widget-get widget :args)))
1671 (widget-put widget :value (widget-apply widget
1672 :value-to-internal (car args)))
1673 (widget-put widget :tag (custom-unlispify-tag-name (car args)))
1674 (widget-put widget :args nil)))
1677 (defun custom-notify (widget &rest args)
1678 "Keep track of changes."
1679 (let ((state (widget-get widget :custom-state)))
1680 (unless (eq state 'modified)
1681 (unless (memq state '(nil unknown hidden))
1682 (widget-put widget :custom-state 'modified))
1683 (custom-magic-reset widget)
1684 (apply 'widget-default-notify widget args))))
1686 (defun custom-redraw (widget)
1687 "Redraw WIDGET with current settings."
1688 (let ((line (count-lines (point-min) (point)))
1689 (column (current-column))
1691 (from (marker-position (widget-get widget :from)))
1692 (to (marker-position (widget-get widget :to))))
1694 (widget-value-set widget (widget-value widget))
1695 (custom-redraw-magic widget))
1696 (when (and (>= pos from) (<= pos to))
1701 (goto-line (1+ line)))
1702 (move-to-column column))
1705 (defun custom-redraw-magic (widget)
1706 "Redraw WIDGET state with current settings."
1708 (let ((magic (widget-get widget :custom-magic)))
1710 (widget-value-set magic (widget-value magic))
1711 (when (setq widget (widget-get widget :group))
1712 (custom-group-state-update widget)))
1714 (setq widget nil)))))
1717 (defun custom-show (widget value)
1718 "Non-nil if WIDGET should be shown with VALUE by default."
1719 (let ((show (widget-get widget :custom-show)))
1725 (funcall show widget value)))))
1727 (defvar custom-load-recursion nil
1728 "Hack to avoid recursive dependencies.")
1730 (defun custom-load-symbol (symbol)
1731 "Load all dependencies for SYMBOL."
1732 (unless custom-load-recursion
1733 (let ((custom-load-recursion t)
1734 (loads (get symbol 'custom-loads))
1737 (setq load (car loads)
1739 (cond ((symbolp load)
1743 ;; Don't reload a file already loaded.
1744 ((and (boundp 'preloaded-file-list)
1745 (member load preloaded-file-list)))
1746 ((assoc load load-history))
1747 ((assoc (locate-library load) load-history))
1750 ;; Without this, we would load cus-edit recursively.
1751 ;; We are still loading it when we call this,
1752 ;; and it is not in load-history yet.
1753 (or (equal load "cus-edit")
1754 (load-library load))
1757 (defun custom-load-widget (widget)
1758 "Load all dependencies for WIDGET."
1759 (custom-load-symbol (widget-value widget)))
1761 (defun custom-unloaded-symbol-p (symbol)
1762 "Return non-nil if the dependencies of SYMBOL has not yet been loaded."
1764 (loads (get symbol 'custom-loads))
1767 (setq load (car loads)
1769 (cond ((symbolp load)
1770 (unless (featurep load)
1772 ((assoc load load-history))
1773 ((assoc (locate-library load) load-history)
1779 (defun custom-unloaded-widget-p (widget)
1780 "Return non-nil if the dependencies of WIDGET has not yet been loaded."
1781 (custom-unloaded-symbol-p (widget-value widget)))
1783 (defun custom-toggle-hide (widget)
1784 "Toggle visibility of WIDGET."
1785 (custom-load-widget widget)
1786 (let ((state (widget-get widget :custom-state)))
1787 (cond ((memq state '(invalid modified))
1788 (error "There are unset changes"))
1790 (widget-put widget :custom-state 'unknown))
1792 (widget-put widget :documentation-shown nil)
1793 (widget-put widget :custom-state 'hidden)))
1794 (custom-redraw widget)
1797 (defun custom-toggle-parent (widget &rest ignore)
1798 "Toggle visibility of parent of WIDGET."
1799 (custom-toggle-hide (widget-get widget :parent)))
1801 (defun custom-add-see-also (widget &optional prefix)
1802 "Add `See also ...' to WIDGET if there are any links.
1803 Insert PREFIX first if non-nil."
1804 (let* ((symbol (widget-get widget :value))
1805 (links (get symbol 'custom-links))
1806 (many (> (length links) 2))
1807 (buttons (widget-get widget :buttons))
1808 (indent (widget-get widget :indent)))
1811 (insert-char ?\ indent))
1814 (insert "See also ")
1816 (push (widget-create-child-and-convert widget (car links))
1818 (setq links (cdr links))
1827 (widget-put widget :buttons buttons))))
1829 (defun custom-add-parent-links (widget &optional initial-string)
1830 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
1831 The value if non-nil if any parents were found.
1832 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
1833 (let ((name (widget-value widget))
1834 (type (widget-type widget))
1835 (buttons (widget-get widget :buttons))
1838 (insert (or initial-string "Parent groups:"))
1839 (mapatoms (lambda (symbol)
1840 (let ((entry (assq name (get symbol 'custom-group))))
1841 (when (eq (nth 1 entry) type)
1843 (push (widget-create-child-and-convert
1844 widget 'custom-group-link
1845 :tag (custom-unlispify-tag-name symbol)
1849 (widget-put widget :buttons buttons)
1852 (delete-region start (point)))
1855 ;;; The `custom-variable' Widget.
1857 (defface custom-variable-tag-face '((((class color)
1859 (:foreground "light blue" :underline t))
1862 (:foreground "blue" :underline t))
1864 "Face used for unpushable variable tags."
1865 :group 'custom-faces)
1867 (defface custom-variable-button-face '((t (:underline t :bold t)))
1868 "Face used for pushable variable tags."
1869 :group 'custom-faces)
1871 (defcustom custom-variable-default-form 'edit
1872 "Default form of displaying variable values."
1873 :type '(choice (const edit)
1875 :group 'custom-buffer
1878 (define-widget 'custom-variable 'custom
1879 "Customize variable."
1881 :help-echo "Set or reset this variable."
1882 :documentation-property 'variable-documentation
1883 :custom-category 'option
1885 :custom-menu 'custom-variable-menu-create
1886 :custom-form nil ; defaults to value of `custom-variable-default-form'
1887 :value-create 'custom-variable-value-create
1888 :action 'custom-variable-action
1889 :custom-set 'custom-variable-set
1890 :custom-save 'custom-variable-save
1891 :custom-reset-current 'custom-redraw
1892 :custom-reset-saved 'custom-variable-reset-saved
1893 :custom-reset-standard 'custom-variable-reset-standard)
1895 (defun custom-variable-type (symbol)
1896 "Return a widget suitable for editing the value of SYMBOL.
1897 If SYMBOL has a `custom-type' property, use that.
1898 Otherwise, look up symbol in `custom-guess-type-alist'."
1899 (let* ((type (or (get symbol 'custom-type)
1900 (and (not (get symbol 'standard-value))
1901 (custom-guess-type symbol))
1903 (options (get symbol 'custom-options))
1904 (tmp (if (listp type)
1905 (copy-sequence type)
1908 (widget-put tmp :options options))
1911 (defun custom-variable-value-create (widget)
1912 "Here is where you edit the variables value."
1913 (custom-load-widget widget)
1914 (unless (widget-get widget :custom-form)
1915 (widget-put widget :custom-form custom-variable-default-form))
1916 (let* ((buttons (widget-get widget :buttons))
1917 (children (widget-get widget :children))
1918 (form (widget-get widget :custom-form))
1919 (state (widget-get widget :custom-state))
1920 (symbol (widget-get widget :value))
1921 (tag (widget-get widget :tag))
1922 (type (custom-variable-type symbol))
1923 (conv (widget-convert type))
1924 (get (or (get symbol 'custom-get) 'default-value))
1925 (prefix (widget-get widget :custom-prefix))
1926 (last (widget-get widget :custom-last))
1927 (value (if (default-boundp symbol)
1928 (funcall get symbol)
1929 (widget-get conv :value))))
1930 ;; If the widget is new, the child determine whether it is hidden.
1932 ((custom-show type value)
1933 (setq state 'unknown))
1935 (setq state 'hidden)))
1936 ;; If we don't know the state, see if we need to edit it in lisp form.
1937 (when (eq state 'unknown)
1938 (unless (widget-apply conv :match value)
1939 ;; (widget-apply (widget-convert type) :match value)
1940 (setq form 'mismatch)))
1941 ;; Now we can create the child widget.
1942 (cond ((eq custom-buffer-style 'tree)
1943 (insert prefix (if last " `--- " " |--- "))
1944 (push (widget-create-child-and-convert
1945 widget 'custom-browse-variable-tag)
1947 (insert " " tag "\n")
1948 (widget-put widget :buttons buttons))
1950 ;; Indicate hidden value.
1951 (push (widget-create-child-and-convert
1954 :sample-face 'custom-variable-tag-face
1958 (push (widget-create-child-and-convert
1960 :help-echo "Show the value of this option."
1961 :action 'custom-toggle-parent
1964 ((memq form '(lisp mismatch))
1965 ;; In lisp mode edit the saved value when possible.
1966 (let* ((value (cond ((get symbol 'saved-value)
1967 (car (get symbol 'saved-value)))
1968 ((get symbol 'standard-value)
1969 (car (get symbol 'standard-value)))
1970 ((default-boundp symbol)
1971 (custom-quote (funcall get symbol)))
1973 (custom-quote (widget-get conv :value))))))
1974 (insert (symbol-name symbol) ": ")
1975 (push (widget-create-child-and-convert
1977 :help-echo "Hide the value of this option."
1978 :action 'custom-toggle-parent
1982 (push (widget-create-child-and-convert
1984 :button-face 'custom-variable-button-face
1986 :tag (symbol-name symbol)
1992 (let* ((format (widget-get type :format))
1993 tag-format value-format)
1994 (unless (string-match ":" format)
1995 (error "Bad format"))
1996 (setq tag-format (substring format 0 (match-end 0)))
1997 (setq value-format (substring format (match-end 0)))
1998 (push (widget-create-child-and-convert
2001 :action 'custom-tag-action
2002 :help-echo "Change value of this option."
2003 :mouse-down-action 'custom-tag-mouse-down-action
2004 :button-face 'custom-variable-button-face
2005 :sample-face 'custom-variable-tag-face
2009 (push (widget-create-child-and-convert
2011 :help-echo "Hide the value of this option."
2012 :action 'custom-toggle-parent
2015 (push (widget-create-child-and-convert
2017 :format value-format
2020 (unless (eq custom-buffer-style 'tree)
2021 ;; Now update the state.
2022 (unless (eq (preceding-char) ?\n)
2023 (widget-insert "\n"))
2024 (if (eq state 'hidden)
2025 (widget-put widget :custom-state state)
2026 (custom-variable-state-set widget))
2027 ;; Create the magic button.
2028 (let ((magic (widget-create-child-and-convert
2029 widget 'custom-magic nil)))
2030 (widget-put widget :custom-magic magic)
2031 (push magic buttons))
2032 ;; Update properties.
2033 (widget-put widget :custom-form form)
2034 (widget-put widget :buttons buttons)
2035 (widget-put widget :children children)
2036 ;; Insert documentation.
2037 (widget-default-format-handler widget ?h)
2039 (unless (eq state 'hidden)
2040 (when (eq (widget-get widget :custom-level) 1)
2041 (custom-add-parent-links widget))
2042 (custom-add-see-also widget)))))
2044 (defun custom-tag-action (widget &rest args)
2045 "Pass :action to first child of WIDGET's parent."
2046 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
2049 (defun custom-tag-mouse-down-action (widget &rest args)
2050 "Pass :mouse-down-action to first child of WIDGET's parent."
2051 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
2052 :mouse-down-action args))
2054 (defun custom-variable-state-set (widget)
2055 "Set the state of WIDGET."
2056 (let* ((symbol (widget-value widget))
2057 (get (or (get symbol 'custom-get) 'default-value))
2058 (value (if (default-boundp symbol)
2059 (funcall get symbol)
2060 (widget-get widget :value)))
2062 (state (cond ((setq tmp (get symbol 'customized-value))
2063 (if (condition-case nil
2064 (equal value (eval (car tmp)))
2068 ((setq tmp (get symbol 'saved-value))
2069 (if (condition-case nil
2070 (equal value (eval (car tmp)))
2074 ((setq tmp (get symbol 'standard-value))
2075 (if (condition-case nil
2076 (equal value (eval (car tmp)))
2081 (widget-put widget :custom-state state)))
2083 (defvar custom-variable-menu
2084 '(("Set for Current Session" custom-variable-set
2086 (eq (widget-get widget :custom-state) 'modified)))
2087 ("Save for Future Sessions" custom-variable-save
2089 (memq (widget-get widget :custom-state) '(modified set changed rogue))))
2090 ("Reset to Current" custom-redraw
2092 (and (default-boundp (widget-value widget))
2093 (memq (widget-get widget :custom-state) '(modified changed)))))
2094 ("Reset to Saved" custom-variable-reset-saved
2096 (and (get (widget-value widget) 'saved-value)
2097 (memq (widget-get widget :custom-state)
2098 '(modified set changed rogue)))))
2099 ("Reset to Standard Settings" custom-variable-reset-standard
2101 (and (get (widget-value widget) 'standard-value)
2102 (memq (widget-get widget :custom-state)
2103 '(modified set changed saved rogue)))))
2104 ("---" ignore ignore)
2105 ("Don't show as Lisp expression" custom-variable-edit
2107 (eq (widget-get widget :custom-form) 'lisp)))
2108 ("Show initial Lisp expression" custom-variable-edit-lisp
2110 (eq (widget-get widget :custom-form) 'edit))))
2111 "Alist of actions for the `custom-variable' widget.
2112 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2113 the menu entry, ACTION is the function to call on the widget when the
2114 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2115 widget as an argument, and returns non-nil if ACTION is valid on that
2116 widget. If FILTER is nil, ACTION is always valid.")
2118 (defun custom-variable-action (widget &optional event)
2119 "Show the menu for `custom-variable' WIDGET.
2120 Optional EVENT is the location for the menu."
2121 (if (eq (widget-get widget :custom-state) 'hidden)
2122 (custom-toggle-hide widget)
2123 (unless (eq (widget-get widget :custom-state) 'modified)
2124 (custom-variable-state-set widget))
2125 (custom-redraw-magic widget)
2126 (let* ((completion-ignore-case t)
2127 (answer (widget-choose (concat "Operation on "
2128 (custom-unlispify-tag-name
2129 (widget-get widget :value)))
2130 (custom-menu-filter custom-variable-menu
2134 (funcall answer widget)))))
2136 (defun custom-variable-edit (widget)
2137 "Edit value of WIDGET."
2138 (widget-put widget :custom-state 'unknown)
2139 (widget-put widget :custom-form 'edit)
2140 (custom-redraw widget))
2142 (defun custom-variable-edit-lisp (widget)
2143 "Edit the lisp representation of the value of WIDGET."
2144 (widget-put widget :custom-state 'unknown)
2145 (widget-put widget :custom-form 'lisp)
2146 (custom-redraw widget))
2148 (defun custom-variable-set (widget)
2149 "Set the current value for the variable being edited by WIDGET."
2150 (let* ((form (widget-get widget :custom-form))
2151 (state (widget-get widget :custom-state))
2152 (child (car (widget-get widget :children)))
2153 (symbol (widget-value widget))
2154 (set (or (get symbol 'custom-set) 'set-default))
2156 (cond ((eq state 'hidden)
2157 (error "Cannot set hidden variable"))
2158 ((setq val (widget-apply child :validate))
2159 (goto-char (widget-get val :from))
2160 (error "%s" (widget-get val :error)))
2161 ((memq form '(lisp mismatch))
2162 (funcall set symbol (eval (setq val (widget-value child))))
2163 (put symbol 'customized-value (list val)))
2165 (funcall set symbol (setq val (widget-value child)))
2166 (put symbol 'customized-value (list (custom-quote val)))))
2167 (custom-variable-state-set widget)
2168 (custom-redraw-magic widget)))
2170 (defun custom-variable-save (widget)
2171 "Set and save the value for the variable being edited by WIDGET."
2172 (let* ((form (widget-get widget :custom-form))
2173 (state (widget-get widget :custom-state))
2174 (child (car (widget-get widget :children)))
2175 (symbol (widget-value widget))
2176 (set (or (get symbol 'custom-set) 'set-default))
2178 (cond ((eq state 'hidden)
2179 (error "Cannot set hidden variable"))
2180 ((setq val (widget-apply child :validate))
2181 (goto-char (widget-get val :from))
2182 (error "%s" (widget-get val :error)))
2183 ((memq form '(lisp mismatch))
2184 (put symbol 'saved-value (list (widget-value child)))
2185 (funcall set symbol (eval (widget-value child))))
2188 'saved-value (list (custom-quote (widget-value
2190 (funcall set symbol (widget-value child))))
2191 (put symbol 'customized-value nil)
2193 (custom-variable-state-set widget)
2194 (custom-redraw-magic widget)))
2196 (defun custom-variable-reset-saved (widget)
2197 "Restore the saved value for the variable being edited by WIDGET."
2198 (let* ((symbol (widget-value widget))
2199 (set (or (get symbol 'custom-set) 'set-default)))
2200 (if (get symbol 'saved-value)
2202 (funcall set symbol (eval (car (get symbol 'saved-value))))
2204 (error "No saved value for %s" symbol))
2205 (put symbol 'customized-value nil)
2206 (widget-put widget :custom-state 'unknown)
2207 (custom-redraw widget)))
2209 (defun custom-variable-reset-standard (widget)
2210 "Restore the standard setting for the variable being edited by WIDGET."
2211 (let* ((symbol (widget-value widget))
2212 (set (or (get symbol 'custom-set) 'set-default)))
2213 (if (get symbol 'standard-value)
2214 (funcall set symbol (eval (car (get symbol 'standard-value))))
2215 (error "No standard setting known for %S" symbol))
2216 (put symbol 'customized-value nil)
2217 (when (get symbol 'saved-value)
2218 (put symbol 'saved-value nil)
2220 (widget-put widget :custom-state 'unknown)
2221 (custom-redraw widget)))
2223 ;;; The `custom-face-edit' Widget.
2225 (define-widget 'custom-face-edit 'checklist
2226 "Edit face attributes."
2230 :button-args '(:help-echo "Control whether this attribute have any effect.")
2231 :args (mapcar (lambda (att)
2234 :sibling-args (widget-get (nth 1 att) :sibling-args)
2235 (list 'const :format "" :value (nth 0 att))
2237 custom-face-attributes))
2239 ;;; The `custom-display' Widget.
2241 (define-widget 'custom-display 'menu-choice
2242 "Select a display type."
2245 :help-echo "Specify frames where the face attributes should be used."
2246 :args '((const :tag "all" t)
2250 :args ((group :sibling-args (:help-echo "\
2251 Only match the specified window systems.")
2252 (const :format "Type: "
2254 (checklist :inline t
2257 :sibling-args (:help-echo "\
2258 The X11 Window System.")
2260 (const :format "PM "
2261 :sibling-args (:help-echo "\
2262 OS/2 Presentation Manager.")
2264 (const :format "W32 "
2265 :sibling-args (:help-echo "\
2268 (const :format "DOS "
2269 :sibling-args (:help-echo "\
2272 (const :format "TTY%n"
2273 :sibling-args (:help-echo "\
2274 Plain text terminals.")
2276 (group :sibling-args (:help-echo "\
2277 Only match the frames with the specified color support.")
2278 (const :format "Class: "
2280 (checklist :inline t
2282 (const :format "Color "
2283 :sibling-args (:help-echo "\
2284 Match color frames.")
2286 (const :format "Grayscale "
2287 :sibling-args (:help-echo "\
2288 Match grayscale frames.")
2290 (const :format "Monochrome%n"
2291 :sibling-args (:help-echo "\
2292 Match frames with no color support.")
2294 (group :sibling-args (:help-echo "\
2295 Only match frames with the specified intensity.")
2297 Background brightness: "
2299 (checklist :inline t
2301 (const :format "Light "
2302 :sibling-args (:help-echo "\
2303 Match frames with light backgrounds.")
2305 (const :format "Dark\n"
2306 :sibling-args (:help-echo "\
2307 Match frames with dark backgrounds.")
2310 ;;; The `custom-face' Widget.
2312 (defface custom-face-tag-face '((t (:underline t)))
2313 "Face used for face tags."
2314 :group 'custom-faces)
2316 (defcustom custom-face-default-form 'selected
2317 "Default form of displaying face definition."
2318 :type '(choice (const all)
2321 :group 'custom-buffer
2324 (define-widget 'custom-face 'custom
2326 :sample-face 'custom-face-tag-face
2327 :help-echo "Set or reset this face."
2328 :documentation-property '(lambda (face)
2329 (face-doc-string face))
2330 :value-create 'custom-face-value-create
2331 :action 'custom-face-action
2332 :custom-category 'face
2333 :custom-form nil ; defaults to value of `custom-face-default-form'
2334 :custom-set 'custom-face-set
2335 :custom-save 'custom-face-save
2336 :custom-reset-current 'custom-redraw
2337 :custom-reset-saved 'custom-face-reset-saved
2338 :custom-reset-standard 'custom-face-reset-standard
2339 :custom-menu 'custom-face-menu-create)
2341 (define-widget 'custom-face-all 'editable-list
2342 "An editable list of display specifications and attributes."
2343 :entry-format "%i %d %v"
2344 :insert-button-args '(:help-echo "Insert new display specification here.")
2345 :append-button-args '(:help-echo "Append new display specification here.")
2346 :delete-button-args '(:help-echo "Delete this display specification.")
2347 :args '((group :format "%v" custom-display custom-face-edit)))
2349 (defconst custom-face-all (widget-convert 'custom-face-all)
2350 "Converted version of the `custom-face-all' widget.")
2352 (define-widget 'custom-display-unselected 'item
2353 "A display specification that doesn't match the selected display."
2354 :match 'custom-display-unselected-match)
2356 (defun custom-display-unselected-match (widget value)
2357 "Non-nil if VALUE is an unselected display specification."
2358 (not (face-spec-set-match-display value (selected-frame))))
2360 (define-widget 'custom-face-selected 'group
2361 "Edit the attributes of the selected display in a face specification."
2362 :args '((repeat :format ""
2364 (group custom-display-unselected sexp))
2365 (group (sexp :format "") custom-face-edit)
2370 (defconst custom-face-selected (widget-convert 'custom-face-selected)
2371 "Converted version of the `custom-face-selected' widget.")
2373 (defun custom-face-value-create (widget)
2374 "Create a list of the display specifications for WIDGET."
2375 (let ((buttons (widget-get widget :buttons))
2376 (symbol (widget-get widget :value))
2377 (tag (widget-get widget :tag))
2378 (state (widget-get widget :custom-state))
2380 (is-last (widget-get widget :custom-last))
2381 (prefix (widget-get widget :custom-prefix)))
2383 (setq tag (prin1-to-string symbol)))
2384 (cond ((eq custom-buffer-style 'tree)
2385 (insert prefix (if is-last " `--- " " |--- "))
2386 (push (widget-create-child-and-convert
2387 widget 'custom-browse-face-tag)
2389 (insert " " tag "\n")
2390 (widget-put widget :buttons buttons))
2394 (if (eq custom-buffer-style 'face)
2396 (widget-specify-sample widget begin (point))
2399 (and (string-match "XEmacs" emacs-version)
2400 ;; XEmacs cannot display uninitialized faces.
2401 (not (custom-facep symbol))
2402 (copy-face 'custom-face-empty symbol))
2403 (push (widget-create-child-and-convert widget 'item
2410 (push (widget-create-child-and-convert
2412 :help-echo "Hide or show this face."
2413 :action 'custom-toggle-parent
2414 (not (eq state 'hidden)))
2418 (let ((magic (widget-create-child-and-convert
2419 widget 'custom-magic nil)))
2420 (widget-put widget :custom-magic magic)
2421 (push magic buttons))
2423 (widget-put widget :buttons buttons)
2424 ;; Insert documentation.
2425 (widget-default-format-handler widget ?h)
2427 (unless (eq state 'hidden)
2428 (when (eq (widget-get widget :custom-level) 1)
2429 (custom-add-parent-links widget))
2430 (custom-add-see-also widget))
2432 (unless (eq (preceding-char) ?\n)
2434 (unless (eq state 'hidden)
2435 (message "Creating face editor...")
2436 (custom-load-widget widget)
2437 (unless (widget-get widget :custom-form)
2438 (widget-put widget :custom-form custom-face-default-form))
2439 (let* ((symbol (widget-value widget))
2440 (spec (or (get symbol 'saved-face)
2441 (get symbol 'face-defface-spec)
2442 ;; Attempt to construct it.
2443 (list (list t (custom-face-attributes-get
2444 symbol (selected-frame))))))
2445 (form (widget-get widget :custom-form))
2446 (indent (widget-get widget :indent))
2448 ;; If the user has changed this face in some other way,
2449 ;; edit it as the user has specified it.
2450 (if (not (face-spec-match-p symbol spec (selected-frame)))
2451 (setq spec (list (list t (face-attr-construct symbol (selected-frame))))))
2452 (setq edit (widget-create-child-and-convert
2454 (cond ((and (eq form 'selected)
2455 (widget-apply custom-face-selected
2457 (when indent (insert-char ?\ indent))
2458 'custom-face-selected)
2459 ((and (not (eq form 'lisp))
2460 (widget-apply custom-face-all
2464 (when indent (insert-char ?\ indent))
2467 (custom-face-state-set widget)
2468 (widget-put widget :children (list edit)))
2469 (message "Creating face editor...done"))))))
2471 (defvar custom-face-menu
2472 '(("Set for Current Session" custom-face-set)
2473 ("Save for Future Sessions" custom-face-save-command)
2474 ("Reset to Saved" custom-face-reset-saved
2476 (get (widget-value widget) 'saved-face)))
2477 ("Reset to Standard Setting" custom-face-reset-standard
2479 (get (widget-value widget) 'face-defface-spec)))
2480 ("---" ignore ignore)
2481 ("Show all display specs" custom-face-edit-all
2483 (not (eq (widget-get widget :custom-form) 'all))))
2484 ("Just current attributes" custom-face-edit-selected
2486 (not (eq (widget-get widget :custom-form) 'selected))))
2487 ("Show as Lisp expression" custom-face-edit-lisp
2489 (not (eq (widget-get widget :custom-form) 'lisp)))))
2490 "Alist of actions for the `custom-face' widget.
2491 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2492 the menu entry, ACTION is the function to call on the widget when the
2493 menu is selected, and FILTER is a predicate which takes a `custom-face'
2494 widget as an argument, and returns non-nil if ACTION is valid on that
2495 widget. If FILTER is nil, ACTION is always valid.")
2497 (defun custom-face-edit-selected (widget)
2498 "Edit selected attributes of the value of WIDGET."
2499 (widget-put widget :custom-state 'unknown)
2500 (widget-put widget :custom-form 'selected)
2501 (custom-redraw widget))
2503 (defun custom-face-edit-all (widget)
2504 "Edit all attributes of the value of WIDGET."
2505 (widget-put widget :custom-state 'unknown)
2506 (widget-put widget :custom-form 'all)
2507 (custom-redraw widget))
2509 (defun custom-face-edit-lisp (widget)
2510 "Edit the lisp representation of the value of WIDGET."
2511 (widget-put widget :custom-state 'unknown)
2512 (widget-put widget :custom-form 'lisp)
2513 (custom-redraw widget))
2515 (defun custom-face-state-set (widget)
2516 "Set the state of WIDGET."
2517 (let ((symbol (widget-value widget)))
2518 (widget-put widget :custom-state (cond ((get symbol 'customized-face)
2520 ((get symbol 'saved-face)
2522 ((get symbol 'face-defface-spec)
2527 (defun custom-face-action (widget &optional event)
2528 "Show the menu for `custom-face' WIDGET.
2529 Optional EVENT is the location for the menu."
2530 (if (eq (widget-get widget :custom-state) 'hidden)
2531 (custom-toggle-hide widget)
2532 (let* ((completion-ignore-case t)
2533 (symbol (widget-get widget :value))
2534 (answer (widget-choose (concat "Operation on "
2535 (custom-unlispify-tag-name symbol))
2536 (custom-menu-filter custom-face-menu
2540 (funcall answer widget)))))
2542 (defun custom-face-set (widget)
2543 "Make the face attributes in WIDGET take effect."
2544 (let* ((symbol (widget-value widget))
2545 (child (car (widget-get widget :children)))
2546 (value (widget-value child)))
2547 (put symbol 'customized-face value)
2548 (face-spec-set symbol value)
2549 (custom-face-state-set widget)
2550 (custom-redraw-magic widget)))
2552 (defun custom-face-save-command (widget)
2553 "Save in `.emacs' the face attributes in WIDGET."
2554 (custom-face-save widget)
2557 (defun custom-face-save (widget)
2558 "Prepare for saving WIDGET's face attributes, but don't write `.emacs'."
2559 (let* ((symbol (widget-value widget))
2560 (child (car (widget-get widget :children)))
2561 (value (widget-value child)))
2562 (face-spec-set symbol value)
2563 (put symbol 'saved-face value)
2564 (put symbol 'customized-face nil)
2566 (custom-face-state-set widget)
2567 (custom-redraw-magic widget)))
2569 (defun custom-face-reset-saved (widget)
2570 "Restore WIDGET to the face's default attributes."
2571 (let* ((symbol (widget-value widget))
2572 (child (car (widget-get widget :children)))
2573 (value (get symbol 'saved-face)))
2575 (error "No saved value for this face"))
2576 (put symbol 'customized-face nil)
2577 (face-spec-set symbol value)
2578 (widget-value-set child value)
2579 (custom-face-state-set widget)
2580 (custom-redraw-magic widget)))
2582 (defun custom-face-reset-standard (widget)
2583 "Restore WIDGET to the face's standard settings."
2584 (let* ((symbol (widget-value widget))
2585 (child (car (widget-get widget :children)))
2586 (value (get symbol 'face-defface-spec)))
2588 (error "No standard setting for this face"))
2589 (put symbol 'customized-face nil)
2590 (when (get symbol 'saved-face)
2591 (put symbol 'saved-face nil)
2593 (face-spec-set symbol value)
2594 (widget-value-set child value)
2595 (custom-face-state-set widget)
2596 (custom-redraw-magic widget)))
2598 ;;; The `face' Widget.
2600 (define-widget 'face 'default
2601 "Select and customize a face."
2602 :convert-widget 'widget-value-convert-widget
2603 :button-prefix 'widget-push-button-prefix
2604 :button-suffix 'widget-push-button-suffix
2605 :format "%t: %[select face%] %v"
2608 :value-create 'widget-face-value-create
2609 :value-delete 'widget-face-value-delete
2610 :value-get 'widget-value-value-get
2611 :validate 'widget-children-validate
2612 :action 'widget-face-action
2613 :match '(lambda (widget value) (symbolp value)))
2615 (defun widget-face-value-create (widget)
2616 ;; Create a `custom-face' child.
2617 (let* ((symbol (widget-value widget))
2618 (custom-buffer-style 'face)
2619 (child (widget-create-child-and-convert
2623 (custom-magic-reset child)
2624 (setq custom-options (cons child custom-options))
2625 (widget-put widget :children (list child))))
2627 (defun widget-face-value-delete (widget)
2628 ;; Remove the child from the options.
2629 (let ((child (car (widget-get widget :children))))
2630 (setq custom-options (delq child custom-options))
2631 (widget-children-value-delete widget)))
2633 (defvar face-history nil
2634 "History of entered face names.")
2636 (defun widget-face-action (widget &optional event)
2637 "Prompt for a face."
2638 (let ((answer (completing-read "Face: "
2639 (mapcar (lambda (face)
2640 (list (symbol-name face)))
2644 (unless (zerop (length answer))
2645 (widget-value-set widget (intern answer))
2646 (widget-apply widget :notify widget event)
2649 ;;; The `hook' Widget.
2651 (define-widget 'hook 'list
2653 :value-to-internal (lambda (widget value)
2654 (if (and value (symbolp value))
2657 :match (lambda (widget value)
2659 (widget-group-match widget value)))
2660 :convert-widget 'custom-hook-convert-widget
2663 (defun custom-hook-convert-widget (widget)
2664 ;; Handle `:custom-options'.
2665 (let* ((options (widget-get widget :options))
2666 (other `(editable-list :inline t
2667 :entry-format "%i %d%v"
2668 (function :format " %v")))
2670 (list `(checklist :inline t
2671 ,@(mapcar (lambda (entry)
2672 `(function-item ,entry))
2676 (widget-put widget :args args)
2679 ;;; The `custom-group-link' Widget.
2681 (define-widget 'custom-group-link 'link
2682 "Show parent in other window when activated."
2683 :help-echo "Create customization buffer for this group."
2684 :action 'custom-group-link-action)
2686 (defun custom-group-link-action (widget &rest ignore)
2687 (customize-group (widget-value widget)))
2689 ;;; The `custom-group' Widget.
2691 (defcustom custom-group-tag-faces nil
2692 ;; In XEmacs, this ought to play games with font size.
2693 "Face used for group tags.
2694 The first member is used for level 1 groups, the second for level 2,
2695 and so forth. The remaining group tags are shown with
2696 `custom-group-tag-face'."
2697 :type '(repeat face)
2698 :group 'custom-faces)
2700 (defface custom-group-tag-face-1 '((((class color)
2702 (:foreground "pink" :underline t))
2705 (:foreground "red" :underline t))
2707 "Face used for group tags.")
2709 (defface custom-group-tag-face '((((class color)
2711 (:foreground "light blue" :underline t))
2714 (:foreground "blue" :underline t))
2716 "Face used for low level group tags."
2717 :group 'custom-faces)
2719 (define-widget 'custom-group 'custom
2722 :sample-face-get 'custom-group-sample-face-get
2723 :documentation-property 'group-documentation
2724 :help-echo "Set or reset all members of this group."
2725 :value-create 'custom-group-value-create
2726 :action 'custom-group-action
2727 :custom-category 'group
2728 :custom-set 'custom-group-set
2729 :custom-save 'custom-group-save
2730 :custom-reset-current 'custom-group-reset-current
2731 :custom-reset-saved 'custom-group-reset-saved
2732 :custom-reset-standard 'custom-group-reset-standard
2733 :custom-menu 'custom-group-menu-create)
2735 (defun custom-group-sample-face-get (widget)
2736 ;; Use :sample-face.
2737 (or (nth (1- (widget-get widget :custom-level)) custom-group-tag-faces)
2738 'custom-group-tag-face))
2740 (define-widget 'custom-group-visibility 'visibility
2741 "An indicator and manipulator for hidden group contents."
2742 :create 'custom-group-visibility-create)
2744 (defun custom-group-visibility-create (widget)
2745 (let ((visible (widget-value widget)))
2747 (insert "--------")))
2748 (widget-default-create widget))
2750 (defun custom-group-members (symbol groups-only)
2751 "Return SYMBOL's custom group members.
2752 If GROUPS-ONLY non-nil, return only those members that are groups."
2753 (if (not groups-only)
2754 (get symbol 'custom-group)
2756 (dolist (entry (get symbol 'custom-group))
2757 (when (eq (nth 1 entry) 'custom-group)
2758 (push entry members)))
2759 (nreverse members))))
2761 (defun custom-group-value-create (widget)
2762 "Insert a customize group for WIDGET in the current buffer."
2763 (let* ((state (widget-get widget :custom-state))
2764 (level (widget-get widget :custom-level))
2765 ;; (indent (widget-get widget :indent))
2766 (prefix (widget-get widget :custom-prefix))
2767 (buttons (widget-get widget :buttons))
2768 (tag (widget-get widget :tag))
2769 (symbol (widget-value widget))
2770 (members (custom-group-members symbol
2771 (and (eq custom-buffer-style 'tree)
2772 custom-browse-only-groups))))
2773 (cond ((and (eq custom-buffer-style 'tree)
2775 (or members (custom-unloaded-widget-p widget)))
2776 (custom-browse-insert-prefix prefix)
2777 (push (widget-create-child-and-convert
2778 widget 'custom-browse-visibility
2779 ;; :tag-glyph "plus"
2783 ;; (widget-glyph-insert nil "-- " "horizontal")
2784 (push (widget-create-child-and-convert
2785 widget 'custom-browse-group-tag)
2787 (insert " " tag "\n")
2788 (widget-put widget :buttons buttons))
2789 ((and (eq custom-buffer-style 'tree)
2790 (zerop (length members)))
2791 (custom-browse-insert-prefix prefix)
2793 ;; (widget-glyph-insert nil "[ ]" "empty")
2794 ;; (widget-glyph-insert nil "-- " "horizontal")
2795 (push (widget-create-child-and-convert
2796 widget 'custom-browse-group-tag)
2798 (insert " " tag "\n")
2799 (widget-put widget :buttons buttons))
2800 ((eq custom-buffer-style 'tree)
2801 (custom-browse-insert-prefix prefix)
2802 (custom-load-widget widget)
2803 (if (zerop (length members))
2805 (custom-browse-insert-prefix prefix)
2807 ;; (widget-glyph-insert nil "[ ]" "empty")
2808 ;; (widget-glyph-insert nil "-- " "horizontal")
2809 (push (widget-create-child-and-convert
2810 widget 'custom-browse-group-tag)
2812 (insert " " tag "\n")
2813 (widget-put widget :buttons buttons))
2814 (push (widget-create-child-and-convert
2815 widget 'custom-browse-visibility
2816 ;; :tag-glyph "minus"
2820 ;; (widget-glyph-insert nil "-\\ " "top")
2821 (push (widget-create-child-and-convert
2822 widget 'custom-browse-group-tag)
2824 (insert " " tag "\n")
2825 (widget-put widget :buttons buttons)
2826 (message "Creating group...")
2827 (let* ((members (custom-sort-items members
2828 custom-browse-sort-alphabetically
2829 custom-browse-order-groups))
2830 (prefixes (widget-get widget :custom-prefixes))
2831 (custom-prefix-list (custom-prefix-add symbol prefixes))
2832 (extra-prefix (if (widget-get widget :custom-last)
2835 (prefix (concat prefix extra-prefix))
2838 (setq entry (car members)
2839 members (cdr members))
2840 (push (widget-create-child-and-convert
2841 widget (nth 1 entry)
2843 :tag (custom-unlispify-tag-name (nth 0 entry))
2844 :custom-prefixes custom-prefix-list
2845 :custom-level (1+ level)
2846 :custom-last (null members)
2847 :value (nth 0 entry)
2848 :custom-prefix prefix)
2850 (widget-put widget :children (reverse children)))
2851 (message "Creating group...done")))
2854 ;; Create level indicator.
2855 (unless (eq custom-buffer-style 'links)
2856 (insert-char ?\ (* custom-buffer-indent (1- level)))
2859 (let ((begin (point)))
2861 (widget-specify-sample widget begin (point)))
2863 ;; Create link/visibility indicator.
2864 (if (eq custom-buffer-style 'links)
2865 (push (widget-create-child-and-convert
2866 widget 'custom-group-link
2870 (push (widget-create-child-and-convert
2871 widget 'custom-group-visibility
2872 :help-echo "Show members of this group."
2873 :action 'custom-toggle-parent
2874 (not (eq state 'hidden)))
2877 ;; Create magic button.
2878 (let ((magic (widget-create-child-and-convert
2879 widget 'custom-magic nil)))
2880 (widget-put widget :custom-magic magic)
2881 (push magic buttons))
2883 (widget-put widget :buttons buttons)
2884 ;; Insert documentation.
2885 (if (and (eq custom-buffer-style 'links) (> level 1))
2886 (widget-put widget :documentation-indent 0))
2887 (widget-default-format-handler widget ?h))
2890 ;; Add parent groups references above the group.
2891 (if t ;;; This should test that the buffer
2892 ;;; was made to display a group.
2894 (if (custom-add-parent-links widget
2895 "Go to parent group:")
2897 ;; Create level indicator.
2898 (insert-char ?\ (* custom-buffer-indent (1- level)))
2901 (let ((start (point)))
2903 (widget-specify-sample widget start (point)))
2905 ;; Create visibility indicator.
2906 (unless (eq custom-buffer-style 'links)
2908 (push (widget-create-child-and-convert
2910 :help-echo "Hide members of this group."
2911 :action 'custom-toggle-parent
2912 (not (eq state 'hidden)))
2915 ;; Create more dashes.
2916 ;; Use 76 instead of 75 to compensate for the temporary "<"
2917 ;; added by `widget-insert'.
2918 (insert-char ?- (- 76 (current-column)
2919 (* custom-buffer-indent level)))
2921 ;; Create magic button.
2922 (let ((magic (widget-create-child-and-convert
2923 widget 'custom-magic
2926 (widget-put widget :custom-magic magic)
2927 (push magic buttons))
2929 (widget-put widget :buttons buttons)
2930 ;; Insert documentation.
2931 (widget-default-format-handler widget ?h)
2933 (if nil ;;; This should test that the buffer
2934 ;;; was not made to display a group.
2936 (insert-char ?\ custom-buffer-indent)
2937 (custom-add-parent-links widget)))
2938 (custom-add-see-also widget
2939 (make-string (* custom-buffer-indent level)
2942 (message "Creating group...")
2943 (custom-load-widget widget)
2944 (let* ((members (custom-sort-items members
2945 custom-buffer-sort-alphabetically
2946 custom-buffer-order-groups))
2947 (prefixes (widget-get widget :custom-prefixes))
2948 (custom-prefix-list (custom-prefix-add symbol prefixes))
2949 (length (length members))
2951 (children (mapcar (lambda (entry)
2952 (widget-insert "\n")
2954 Creating group members... %2d%%"
2955 (/ (* 100.0 count) length))
2956 (setq count (1+ count))
2958 (widget-create-child-and-convert
2959 widget (nth 1 entry)
2961 :tag (custom-unlispify-tag-name
2963 :custom-prefixes custom-prefix-list
2964 :custom-level (1+ level)
2965 :value (nth 0 entry))
2966 (unless (eq (preceding-char) ?\n)
2967 (widget-insert "\n"))))
2969 (message "Creating group magic...")
2970 (mapcar 'custom-magic-reset children)
2971 (message "Creating group state...")
2972 (widget-put widget :children children)
2973 (custom-group-state-update widget)
2974 (message "Creating group... done"))
2977 (insert-char ?\ (* custom-buffer-indent (1- level)))
2978 (insert "\\- " (widget-get widget :tag) " group end ")
2979 (insert-char ?- (- 75 (current-column) (* custom-buffer-indent level)))
2982 (defvar custom-group-menu
2983 '(("Set for Current Session" custom-group-set
2985 (eq (widget-get widget :custom-state) 'modified)))
2986 ("Save for Future Sessions" custom-group-save
2988 (memq (widget-get widget :custom-state) '(modified set))))
2989 ("Reset to Current" custom-group-reset-current
2991 (memq (widget-get widget :custom-state) '(modified))))
2992 ("Reset to Saved" custom-group-reset-saved
2994 (memq (widget-get widget :custom-state) '(modified set))))
2995 ("Reset to standard setting" custom-group-reset-standard
2997 (memq (widget-get widget :custom-state) '(modified set saved)))))
2998 "Alist of actions for the `custom-group' widget.
2999 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3000 the menu entry, ACTION is the function to call on the widget when the
3001 menu is selected, and FILTER is a predicate which takes a `custom-group'
3002 widget as an argument, and returns non-nil if ACTION is valid on that
3003 widget. If FILTER is nil, ACTION is always valid.")
3005 (defun custom-group-action (widget &optional event)
3006 "Show the menu for `custom-group' WIDGET.
3007 Optional EVENT is the location for the menu."
3008 (if (eq (widget-get widget :custom-state) 'hidden)
3009 (custom-toggle-hide widget)
3010 (let* ((completion-ignore-case t)
3011 (answer (widget-choose (concat "Operation on "
3012 (custom-unlispify-tag-name
3013 (widget-get widget :value)))
3014 (custom-menu-filter custom-group-menu
3018 (funcall answer widget)))))
3020 (defun custom-group-set (widget)
3021 "Set changes in all modified group members."
3022 (let ((children (widget-get widget :children)))
3023 (mapcar (lambda (child)
3024 (when (eq (widget-get child :custom-state) 'modified)
3025 (widget-apply child :custom-set)))
3028 (defun custom-group-save (widget)
3029 "Save all modified group members."
3030 (let ((children (widget-get widget :children)))
3031 (mapcar (lambda (child)
3032 (when (memq (widget-get child :custom-state) '(modified set))
3033 (widget-apply child :custom-save)))
3036 (defun custom-group-reset-current (widget)
3037 "Reset all modified group members."
3038 (let ((children (widget-get widget :children)))
3039 (mapcar (lambda (child)
3040 (when (eq (widget-get child :custom-state) 'modified)
3041 (widget-apply child :custom-reset-current)))
3044 (defun custom-group-reset-saved (widget)
3045 "Reset all modified or set group members."
3046 (let ((children (widget-get widget :children)))
3047 (mapcar (lambda (child)
3048 (when (memq (widget-get child :custom-state) '(modified set))
3049 (widget-apply child :custom-reset-saved)))
3052 (defun custom-group-reset-standard (widget)
3053 "Reset all modified, set, or saved group members."
3054 (let ((children (widget-get widget :children)))
3055 (mapcar (lambda (child)
3056 (when (memq (widget-get child :custom-state)
3057 '(modified set saved))
3058 (widget-apply child :custom-reset-standard)))
3061 (defun custom-group-state-update (widget)
3063 (unless (eq (widget-get widget :custom-state) 'hidden)
3064 (let* ((children (widget-get widget :children))
3065 (states (mapcar (lambda (child)
3066 (widget-get child :custom-state))
3068 (magics custom-magic-alist)
3071 (let ((magic (car (car magics))))
3072 (if (and (not (eq magic 'hidden))
3073 (memq magic states))
3076 (setq magics (cdr magics)))))
3077 (widget-put widget :custom-state found)))
3078 (custom-magic-reset widget))
3080 ;;; The `custom-save-all' Function.
3082 (defcustom custom-file nil
3083 "File used for storing customization information.
3084 The default is nil, which means to use your init file
3085 as specified by `user-init-file'. If you specify some other file,
3086 you need to explicitly load that file for the settings to take effect."
3087 :type '(choice (const :tag "Your Emacs init file" nil) file)
3090 (defun custom-file ()
3091 "Return the file name for saving customizations."
3095 (read-file-name "File for customizations: "
3096 "~/" nil nil ".emacs"))))
3098 (defun custom-save-delete (symbol)
3099 "Delete the call to SYMBOL from `custom-file'.
3100 Leave point at the location of the call, or after the last expression."
3101 (let ((default-major-mode))
3102 (set-buffer (find-file-noselect (custom-file))))
3103 (goto-char (point-min))
3104 (save-excursion (forward-sexp (buffer-size))) ; Test for scan errors.
3107 ;; Skip all whitespace and comments.
3108 (while (forward-comment 1))
3109 (let ((start (point))
3110 (sexp (condition-case nil
3111 (read (current-buffer))
3112 (end-of-file (throw 'found nil)))))
3113 (when (and (listp sexp)
3114 (eq (car sexp) symbol))
3115 (delete-region start (point))
3116 (throw 'found nil))))))
3118 (defun custom-save-variables ()
3119 "Save all customized variables in `custom-file'."
3121 (custom-save-delete 'custom-set-variables)
3122 (let ((standard-output (current-buffer)))
3125 (princ "(custom-set-variables")
3126 (mapatoms (lambda (symbol)
3127 (let ((value (get symbol 'saved-value))
3128 (requests (get symbol 'custom-requests))
3129 (now (not (or (get symbol 'standard-value)
3130 (and (not (boundp symbol))
3131 (not (get symbol 'force-value)))))))
3148 (unless (looking-at "\n")
3151 (defun custom-save-faces ()
3152 "Save all customized faces in `custom-file'."
3154 (custom-save-delete 'custom-set-faces)
3155 (let ((standard-output (current-buffer)))
3158 (princ "(custom-set-faces")
3159 (let ((value (get 'default 'saved-face)))
3160 ;; The default face must be first, since it affects the others.
3162 (princ "\n '(default ")
3164 (if (or (get 'default 'face-defface-spec)
3165 (and (not (custom-facep 'default))
3166 (not (get 'default 'force-face))))
3169 (mapatoms (lambda (symbol)
3170 (let ((value (get symbol 'saved-face)))
3171 (when (and (not (eq symbol 'default))
3172 ;; Don't print default face here.
3178 (if (or (get symbol 'face-defface-spec)
3179 (and (not (custom-facep symbol))
3180 (not (get symbol 'force-face))))
3184 (unless (looking-at "\n")
3188 (defun customize-save-customized ()
3189 "Save all user options which have been set in this session."
3191 (mapatoms (lambda (symbol)
3192 (let ((face (get symbol 'customized-face))
3193 (value (get symbol 'customized-value)))
3195 (put symbol 'saved-face face)
3196 (put symbol 'customized-face nil))
3198 (put symbol 'saved-value value)
3199 (put symbol 'customized-value nil)))))
3200 ;; We really should update all custom buffers here.
3204 (defun custom-save-all ()
3205 "Save all customizations in `custom-file'."
3206 (let ((inhibit-read-only t))
3207 (custom-save-variables)
3210 (let ((default-major-mode nil))
3211 (set-buffer (find-file-noselect (custom-file))))
3214 ;;; The Customize Menu.
3218 (defcustom custom-menu-nesting 2
3219 "Maximum nesting in custom menus."
3221 :group 'custom-menu)
3223 (defun custom-face-menu-create (widget symbol)
3224 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
3225 (vector (custom-unlispify-menu-entry symbol)
3226 `(customize-face ',symbol)
3229 (defun custom-variable-menu-create (widget symbol)
3230 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
3231 (let ((type (get symbol 'custom-type)))
3232 (unless (listp type)
3233 (setq type (list type)))
3234 (if (and type (widget-get type :custom-menu))
3235 (widget-apply type :custom-menu symbol)
3236 (vector (custom-unlispify-menu-entry symbol)
3237 `(customize-variable ',symbol)
3240 ;; Add checkboxes to boolean variable entries.
3241 (widget-put (get 'boolean 'widget-type)
3242 :custom-menu (lambda (widget symbol)
3243 (vector (custom-unlispify-menu-entry symbol)
3244 `(customize-variable ',symbol)
3246 ':selected symbol)))
3248 (if (string-match "XEmacs" emacs-version)
3249 ;; XEmacs can create menus dynamically.
3250 (defun custom-group-menu-create (widget symbol)
3251 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
3252 `( ,(custom-unlispify-menu-entry symbol t)
3253 :filter (lambda (&rest junk)
3254 (cdr (custom-menu-create ',symbol)))))
3256 (defun custom-group-menu-create (widget symbol)
3257 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
3258 ;; Limit the nesting.
3259 (let ((custom-menu-nesting (1- custom-menu-nesting)))
3260 (custom-menu-create symbol))))
3263 (defun custom-menu-create (symbol)
3264 "Create menu for customization group SYMBOL.
3265 The menu is in a format applicable to `easy-menu-define'."
3266 (let* ((item (vector (custom-unlispify-menu-entry symbol)
3267 `(customize-group ',symbol)
3269 (if (and (or (not (boundp 'custom-menu-nesting))
3270 (>= custom-menu-nesting 0))
3271 (< (length (get symbol 'custom-group)) widget-menu-max-size))
3272 (let ((custom-prefix-list (custom-prefix-add symbol
3273 custom-prefix-list))
3274 (members (custom-sort-items (get symbol 'custom-group)
3275 custom-menu-sort-alphabetically
3276 custom-menu-order-groups)))
3277 (custom-load-symbol symbol)
3278 `(,(custom-unlispify-menu-entry symbol t)
3281 ,@(mapcar (lambda (entry)
3282 (widget-apply (if (listp (nth 1 entry))
3284 (list (nth 1 entry)))
3285 :custom-menu (nth 0 entry)))
3290 (defun customize-menu-create (symbol &optional name)
3291 "Return a customize menu for customization group SYMBOL.
3292 If optional NAME is given, use that as the name of the menu.
3293 Otherwise the menu will be named `Customize'.
3294 The format is suitable for use with `easy-menu-define'."
3296 (setq name "Customize"))
3297 (if (string-match "XEmacs" emacs-version)
3298 ;; We can delay it under XEmacs.
3300 :filter (lambda (&rest junk)
3301 (cdr (custom-menu-create ',symbol))))
3302 ;; But we must create it now under Emacs.
3303 (cons name (cdr (custom-menu-create symbol)))))
3305 ;;; The Custom Mode.
3307 (defvar custom-mode-map nil
3308 "Keymap for `custom-mode'.")
3310 (unless custom-mode-map
3311 (setq custom-mode-map (make-sparse-keymap))
3312 (set-keymap-parent custom-mode-map widget-keymap)
3313 (suppress-keymap custom-mode-map)
3314 (define-key custom-mode-map " " 'scroll-up)
3315 (define-key custom-mode-map "\177" 'scroll-down)
3316 (define-key custom-mode-map "q" 'bury-buffer)
3317 (define-key custom-mode-map "u" 'Custom-goto-parent)
3318 (define-key custom-mode-map "n" 'widget-forward)
3319 (define-key custom-mode-map "p" 'widget-backward)
3320 (define-key custom-mode-map [mouse-1] 'Custom-move-and-invoke))
3322 (defun Custom-move-and-invoke (event)
3323 "Move to where you click, and if it is an active field, invoke it."
3325 (mouse-set-point event)
3326 (if (widget-event-point event)
3327 (let* ((pos (widget-event-point event))
3328 (button (get-char-property pos 'button)))
3330 (widget-button-click event)))))
3332 (easy-menu-define Custom-mode-menu
3334 "Menu used in customization buffers."
3336 ,(customize-menu-create 'customize)
3337 ["Set" Custom-set t]
3338 ["Save" Custom-save t]
3339 ["Reset to Current" Custom-reset-current t]
3340 ["Reset to Saved" Custom-reset-saved t]
3341 ["Reset to Standard Settings" Custom-reset-standard t]
3342 ["Info" (Info-goto-node "(emacs)Easy Customization") t]))
3344 (defun Custom-goto-parent ()
3345 "Go to the parent group listed at the top of this buffer.
3346 If several parents are listed, go to the first of them."
3349 (goto-char (point-min))
3350 (if (search-forward "\nGo to parent group: " nil t)
3351 (let* ((button (get-char-property (point) 'button))
3352 (parent (downcase (widget-get button :tag))))
3353 (customize-group parent)))))
3355 (defcustom custom-mode-hook nil
3356 "Hook called when entering custom-mode."
3358 :group 'custom-buffer )
3360 (defun custom-state-buffer-message (widget)
3361 (if (eq (widget-get (widget-get widget :parent) :custom-state) 'modified)
3362 (message "To install your edits, invoke [State] and choose the Set operation")))
3364 (defun custom-mode ()
3365 "Major mode for editing customization buffers.
3367 The following commands are available:
3369 Move to next button or editable field. \\[widget-forward]
3370 Move to previous button or editable field. \\[widget-backward]
3371 \\<widget-field-keymap>\
3372 Complete content of editable text field. \\[widget-complete]
3373 \\<custom-mode-map>\
3374 Invoke button under the mouse pointer. \\[Custom-move-and-invoke]
3375 Invoke button under point. \\[widget-button-press]
3376 Set all modifications. \\[Custom-set]
3377 Make all modifications default. \\[Custom-save]
3378 Reset all modified options. \\[Custom-reset-current]
3379 Reset all modified or set options. \\[Custom-reset-saved]
3380 Reset all options. \\[Custom-reset-standard]
3382 Entry to this mode calls the value of `custom-mode-hook'
3383 if that value is non-nil."
3384 (kill-all-local-variables)
3385 (setq major-mode 'custom-mode
3387 (use-local-map custom-mode-map)
3388 (easy-menu-add Custom-mode-menu)
3389 (make-local-variable 'custom-options)
3390 (make-local-variable 'widget-documentation-face)
3391 (setq widget-documentation-face 'custom-documentation-face)
3392 (make-local-variable 'widget-button-face)
3393 (setq widget-button-face 'custom-button-face)
3394 (make-local-hook 'widget-edit-functions)
3395 (add-hook 'widget-edit-functions 'custom-state-buffer-message nil t)
3396 (run-hooks 'custom-mode-hook))
3402 ;; cus-edit.el ends here