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 programming nil
110 "Support for programming in other languages."
113 (defgroup languages nil
114 "Specialized modes for editing programming languages."
118 "Lisp support, including Emacs Lisp."
123 "Support for the C language and related languages."
131 "Support for object-oriented programming."
134 (defgroup applications nil
135 "Applications written in Emacs."
138 (defgroup calendar nil
139 "Calendar and time management support."
140 :group
'applications
)
143 "Modes for electronic-mail handling."
144 :group
'applications
)
147 "Support for netnews reading and posting."
148 :group
'applications
)
151 "Games, jokes and amusements."
152 :group
'applications
)
154 (defgroup development nil
155 "Support for further development of Emacs."
159 "Support for Emacs documentation."
162 (defgroup extensions nil
163 "Emacs Lisp language extensions."
166 (defgroup internal nil
167 "Code for Emacs internals, build process, defaults."
171 "Maintenance aids for the Emacs development group."
175 (defgroup environment nil
176 "Fitting Emacs with its environment."
180 "Communications, networking, remote access to files."
184 (defgroup hardware nil
185 "Support for interfacing with exotic hardware."
188 (defgroup terminals nil
189 "Support for terminal types."
193 "Front-ends/assistants for, or emulators of, UNIX features."
197 "Support code for vms."
201 "Internationalization and alternate character-set support."
206 "The X Window system."
210 "Support for Emacs frames and window systems."
214 "Support editing files of data."
218 "Support editing files."
226 "Code related to the TeX formatter."
230 "Support for multiple fonts."
233 (defgroup hypermedia nil
234 "Support for links between text or other media types."
238 "Support for on-line help systems."
242 "Code local to your site."
245 (defgroup customize
'((widgets custom-group
))
246 "Customization of the Customization support."
247 :link
'(custom-manual "(custom)Top")
248 :link
'(url-link :tag
"Development Page"
249 "http://www.dina.kvl.dk/~abraham/custom/")
253 (defgroup custom-faces nil
254 "Faces used by customize."
258 (defgroup custom-browse nil
259 "Control customize browser."
263 (defgroup custom-buffer nil
264 "Control customize buffers."
268 (defgroup custom-menu nil
269 "Control customize menus."
273 (defgroup abbrev-mode nil
274 "Word abbreviations mode."
278 "Storage allocation and gc for GNU Emacs Lisp interpreter."
279 :tag
"Storage Allocation"
283 "Undoing changes in buffers."
286 (defgroup modeline nil
287 "Content of the modeline."
291 "Indenting and filling text."
294 (defgroup editing-basics nil
295 "Most basic editing facilities."
298 (defgroup display nil
299 "How characters are displayed in buffers."
302 (defgroup execute nil
303 "Executing external commands."
306 (defgroup installation nil
307 "The Emacs installation."
315 "Internal Emacs limits."
319 "Debugging Emacs itself."
322 (defgroup minibuffer nil
323 "Controling the behaviour of the minibuffer."
326 (defgroup keyboard nil
327 "Input from the keyboard."
331 "Input from the mouse."
335 "Input from the menus."
338 (defgroup auto-save nil
339 "Preventing accidential loss of data."
342 (defgroup processes-basics nil
343 "Basic stuff dealing with processes."
347 "MULE Emacs internationalization."
350 (defgroup windows nil
351 "Windows within a frame."
356 (defun custom-last (x &optional n
)
357 ;; Stolen from `cl.el'.
358 "Returns the last link in the list LIST.
359 With optional argument N, returns Nth-to-last link (default 1)."
362 (while (consp p
) (incf m
) (pop p
))
364 (if (< n m
) (nthcdr (- m n
) x
) x
)))
365 (while (consp (cdr x
)) (pop x
))
368 (defun custom-quote (sexp)
369 "Quote SEXP iff it is not self quoting."
370 (if (or (memq sexp
'(t nil
))
372 (eq (aref (symbol-name sexp
) 0) ?
:))
374 (memq (car sexp
) '(lambda)))
377 (and (fboundp 'characterp
)
382 (defun custom-split-regexp-maybe (regexp)
383 "If REGEXP is a string, split it to a list at `\\|'.
384 You can get the original back with from the result with:
385 (mapconcat 'identity result \"\\|\")
387 IF REGEXP is not a string, return it unchanged."
391 (while (string-match "\\\\|" regexp start
)
392 (setq all
(cons (substring regexp start
(match-beginning 0)) all
)
393 start
(match-end 0)))
394 (nreverse (cons (substring regexp start
) all
)))
397 (defun custom-variable-prompt ()
398 ;; Code stolen from `help.el'.
399 "Prompt for a variable, defaulting to the variable at point.
400 Return a list suitable for use in `interactive'."
401 (let ((v (variable-at-point))
402 (enable-recursive-minibuffers t
)
404 (setq val
(completing-read
406 (format "Customize option: (default %s) " v
)
407 "Customize variable: ")
408 obarray
(lambda (symbol)
410 (or (get symbol
'custom-type
)
411 (user-variable-p symbol
)))) t
))
412 (list (if (equal val
"")
413 (if (symbolp v
) v nil
)
416 (defun custom-menu-filter (menu widget
)
417 "Convert MENU to the form used by `widget-choose'.
418 MENU should be in the same format as `custom-variable-menu'.
419 WIDGET is the widget to apply the filter entries of MENU on."
421 current name action filter
)
423 (setq current
(car menu
)
425 action
(nth 1 current
)
426 filter
(nth 2 current
)
428 (if (or (null filter
) (funcall filter widget
))
429 (push (cons name action
) result
)
435 (defvar custom-prefix-list nil
436 "List of prefixes that should be ignored by `custom-unlispify'")
438 (defcustom custom-unlispify-menu-entries t
439 "Display menu entries as words instead of symbols if non nil."
443 (defcustom custom-unlispify-remove-prefixes nil
444 "Non-nil means remove group prefixes from option names in buffer."
448 (defun custom-unlispify-menu-entry (symbol &optional no-suffix
)
449 "Convert symbol into a menu entry."
450 (cond ((not custom-unlispify-menu-entries
)
451 (symbol-name symbol
))
452 ((get symbol
'custom-tag
)
454 (get symbol
'custom-tag
)
455 (concat (get symbol
'custom-tag
) "...")))
458 (set-buffer (get-buffer-create " *Custom-Work*"))
460 (princ symbol
(current-buffer))
461 (goto-char (point-min))
462 (when (and (eq (get symbol
'custom-type
) 'boolean
)
463 (re-search-forward "-p\\'" nil t
))
464 (replace-match "" t t
)
465 (goto-char (point-min)))
466 (if custom-unlispify-remove-prefixes
467 (let ((prefixes custom-prefix-list
)
470 (setq prefix
(car prefixes
))
471 (if (search-forward prefix
(+ (point) (length prefix
)) t
)
474 (delete-region (point-min) (point)))
475 (setq prefixes
(cdr prefixes
))))))
476 (subst-char-in-region (point-min) (point-max) ?- ?\ t
)
477 (capitalize-region (point-min) (point-max))
479 (goto-char (point-max))
483 (defcustom custom-unlispify-tag-names t
484 "Display tag names as words instead of symbols if non nil."
485 :group
'custom-buffer
488 (defun custom-unlispify-tag-name (symbol)
489 "Convert symbol into a menu entry."
490 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names
))
491 (custom-unlispify-menu-entry symbol t
)))
493 (defun custom-prefix-add (symbol prefixes
)
494 ;; Addd SYMBOL to list of ignored PREFIXES.
495 (cons (or (get symbol
'custom-prefix
)
496 (concat (symbol-name symbol
) "-"))
501 (defcustom custom-guess-name-alist
506 ("-function\\'" function
)
507 ("-functions\\'" (repeat function
))
508 ("-list\\'" (repeat sexp
))
509 ("-alist\\'" (repeat (cons sexp sexp
))))
510 "Alist of (MATCH TYPE).
512 MATCH should be a regexp matching the name of a symbol, and TYPE should
513 be a widget suitable for editing the value of that symbol. The TYPE
514 of the first entry where MATCH matches the name of the symbol will be
517 This is used for guessing the type of variables not declared with
519 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
522 (defcustom custom-guess-doc-alist
523 '(("\\`\\*?Non-nil " boolean
))
524 "Alist of (MATCH TYPE).
526 MATCH should be a regexp matching a documentation string, and TYPE
527 should be a widget suitable for editing the value of a variable with
528 that documentation string. The TYPE of the first entry where MATCH
529 matches the name of the symbol will be used.
531 This is used for guessing the type of variables not declared with
533 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
536 (defun custom-guess-type (symbol)
537 "Guess a widget suitable for editing the value of SYMBOL.
538 This is done by matching SYMBOL with `custom-guess-name-alist' and
539 if that fails, the doc string with `custom-guess-doc-alist'."
540 (let ((name (symbol-name symbol
))
541 (names custom-guess-name-alist
)
544 (setq current
(car names
)
546 (when (string-match (nth 0 current
) name
)
547 (setq found
(nth 1 current
)
550 (let ((doc (documentation-property symbol
'variable-documentation
))
551 (docs custom-guess-doc-alist
))
554 (setq current
(car docs
)
556 (when (string-match (nth 0 current
) doc
)
557 (setq found
(nth 1 current
)
563 (defcustom custom-browse-sort-alphabetically nil
564 "If non-nil, sort members of each customization group alphabetically."
566 :group
'custom-browse
)
568 (defcustom custom-browse-order-groups nil
569 "If non-nil, order group members within each customization group.
570 If `first', order groups before non-groups.
571 If `last', order groups after non-groups."
572 :type
'(choice (const first
)
574 (const :tag
"none" nil
))
575 :group
'custom-browse
)
577 (defcustom custom-browse-only-groups nil
578 "If non-nil, show group members only within each customization group."
580 :group
'custom-browse
)
582 (defcustom custom-buffer-sort-alphabetically nil
583 "If non-nil, sort members of each customization group alphabetically."
585 :group
'custom-buffer
)
587 (defcustom custom-buffer-order-groups
'last
588 "If non-nil, order group members within each customization group.
589 If `first', order groups before non-groups.
590 If `last', order groups after non-groups."
591 :type
'(choice (const first
)
593 (const :tag
"none" nil
))
594 :group
'custom-buffer
)
596 (defcustom custom-menu-sort-alphabetically nil
597 "If non-nil, sort members of each customization group alphabetically."
601 (defcustom custom-menu-order-groups
'first
602 "If non-nil, order group members within each customization group.
603 If `first', order groups before non-groups.
604 If `last', order groups after non-groups."
605 :type
'(choice (const first
)
607 (const :tag
"none" nil
))
610 (defun custom-sort-items (items sort-alphabetically order-groups
)
611 "Return a sorted copy of ITEMS.
612 ITEMS should be a `custom-group' property.
613 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
614 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
615 groups after non-groups, if nil do not order groups at all."
616 (sort (copy-sequence items
)
618 (let ((typea (nth 1 a
)) (typeb (nth 1 b
))
619 (namea (symbol-name (nth 0 a
))) (nameb (symbol-name (nth 0 b
))))
620 (cond ((not order-groups
)
621 ;; Since we don't care about A and B order, maybe sort.
622 (when sort-alphabetically
623 (string-lessp namea nameb
)))
624 ((eq typea
'custom-group
)
625 ;; If B is also a group, maybe sort. Otherwise, order A and B.
626 (if (eq typeb
'custom-group
)
627 (when sort-alphabetically
628 (string-lessp namea nameb
))
629 (eq order-groups
'first
)))
630 ((eq typeb
'custom-group
)
631 ;; Since A cannot be a group, order A and B.
632 (eq order-groups
'last
))
634 ;; Since A and B cannot be groups, sort.
635 (string-lessp namea nameb
)))))))
637 ;;; Custom Mode Commands.
639 (defvar custom-options nil
640 "Customization widgets in the current buffer.")
643 "Set changes in all modified options."
645 (let ((children custom-options
))
646 (mapcar (lambda (child)
647 (when (eq (widget-get child
:custom-state
) 'modified
)
648 (widget-apply child
:custom-set
)))
651 (defun Custom-save ()
652 "Set all modified group members and save them."
654 (let ((children custom-options
))
655 (mapcar (lambda (child)
656 (when (memq (widget-get child
:custom-state
) '(modified set
))
657 (widget-apply child
:custom-save
)))
661 (defvar custom-reset-menu
662 '(("Current" . Custom-reset-current
)
663 ("Saved" . Custom-reset-saved
)
664 ("Standard Settings" . Custom-reset-standard
))
665 "Alist of actions for the `Reset' button.
666 The key is a string containing the name of the action, the value is a
667 lisp function taking the widget as an element which will be called
668 when the action is chosen.")
670 (defun custom-reset (event)
671 "Select item from reset menu."
672 (let* ((completion-ignore-case t
)
673 (answer (widget-choose "Reset to"
679 (defun Custom-reset-current (&rest ignore
)
680 "Reset all modified group members to their current value."
682 (let ((children custom-options
))
683 (mapcar (lambda (child)
684 (when (eq (widget-get child
:custom-state
) 'modified
)
685 (widget-apply child
:custom-reset-current
)))
688 (defun Custom-reset-saved (&rest ignore
)
689 "Reset all modified or set group members to their saved value."
691 (let ((children custom-options
))
692 (mapcar (lambda (child)
693 (when (eq (widget-get child
:custom-state
) 'modified
)
694 (widget-apply child
:custom-reset-saved
)))
697 (defun Custom-reset-standard (&rest ignore
)
698 "Reset all modified, set, or saved group members to their standard settings."
700 (let ((children custom-options
))
701 (mapcar (lambda (child)
702 (when (eq (widget-get child
:custom-state
) 'modified
)
703 (widget-apply child
:custom-reset-standard
)))
706 ;;; The Customize Commands
708 (defun custom-prompt-variable (prompt-var prompt-val
)
709 "Prompt for a variable and a value and return them as a list.
710 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
711 prompt for the value. The %s escape in PROMPT-VAL is replaced with
712 the name of the variable.
714 If the variable has a `variable-interactive' property, that is used as if
715 it were the arg to `interactive' (which see) to interactively read the value.
717 If the variable has a `custom-type' property, it must be a widget and the
718 `:prompt-value' property of that widget will be used for reading the value."
719 (let* ((var (read-variable prompt-var
))
720 (minibuffer-help-form '(describe-variable var
)))
722 (let ((prop (get var
'variable-interactive
))
723 (type (get var
'custom-type
))
724 (prompt (format prompt-val var
)))
726 (setq type
(list type
)))
728 ;; Use VAR's `variable-interactive' property
729 ;; as an interactive spec for prompting.
730 (call-interactively (list 'lambda
'(arg)
731 (list 'interactive prop
)
734 (widget-prompt-value type
740 (eval-minibuffer prompt
)))))))
743 (defun customize-set-value (var val
)
744 "Set VARIABLE to VALUE. VALUE is a Lisp object.
746 If VARIABLE has a `variable-interactive' property, that is used as if
747 it were the arg to `interactive' (which see) to interactively read the value.
749 If VARIABLE has a `custom-type' property, it must be a widget and the
750 `:prompt-value' property of that widget will be used for reading the value."
751 (interactive (custom-prompt-variable "Set variable: "
752 "Set %s to value: "))
757 (defun customize-set-variable (var val
)
758 "Set the default for VARIABLE to VALUE. VALUE is a Lisp object.
760 If VARIABLE has a `custom-set' property, that is used for setting
761 VARIABLE, otherwise `set-default' is used.
763 The `customized-value' property of the VARIABLE will be set to a list
764 with a quoted VALUE as its sole list member.
766 If VARIABLE has a `variable-interactive' property, that is used as if
767 it were the arg to `interactive' (which see) to interactively read the value.
769 If VARIABLE has a `custom-type' property, it must be a widget and the
770 `:prompt-value' property of that widget will be used for reading the value. "
771 (interactive (custom-prompt-variable "Set variable: "
772 "Set customized value for %s to: "))
773 (funcall (or (get var
'custom-set
) 'set-default
) var val
)
774 (put var
'customized-value
(list (custom-quote val
))))
777 (defun customize-save-variable (var val
)
778 "Set the default for VARIABLE to VALUE, and save it for future sessions.
779 If VARIABLE has a `custom-set' property, that is used for setting
780 VARIABLE, otherwise `set-default' is used.
782 The `customized-value' property of the VARIABLE will be set to a list
783 with a quoted VALUE as its sole list member.
785 If VARIABLE has a `variable-interactive' property, that is used as if
786 it were the arg to `interactive' (which see) to interactively read the value.
788 If VARIABLE has a `custom-type' property, it must be a widget and the
789 `:prompt-value' property of that widget will be used for reading the value. "
790 (interactive (custom-prompt-variable "Set and ave variable: "
791 "Set and save value for %s as: "))
792 (funcall (or (get var
'custom-set
) 'set-default
) var val
)
793 (put var
'saved-value
(list (custom-quote val
)))
798 "Select a customization buffer which you can use to set user options.
799 User options are structured into \"groups\".
800 Initially the top-level group `Emacs' and its immediate subgroups
801 are shown; the contents of those subgroups are initially hidden."
803 (customize-group 'emacs
))
806 (defun customize-group (group)
807 "Customize GROUP, which must be a customization group."
808 (interactive (list (let ((completion-ignore-case t
))
809 (completing-read "Customize group: (default emacs) "
812 (or (get symbol
'custom-loads
)
813 (get symbol
'custom-group
)))
815 (when (stringp group
)
816 (if (string-equal "" group
)
818 (setq group
(intern group
))))
819 (or (get group
'custom-group
)
820 (custom-load-symbol group
))
821 (let ((name (format "*Customize Group: %s*"
822 (custom-unlispify-tag-name group
))))
823 (if (get-buffer name
)
824 (switch-to-buffer name
)
825 (custom-buffer-create (list (list group
'custom-group
))
827 (concat " for group "
828 (custom-unlispify-tag-name group
))))))
831 (defun customize-group-other-window (symbol)
832 "Customize SYMBOL, which must be a customization group."
833 (interactive (list (completing-read "Customize group: (default emacs) "
836 (get symbol
'custom-group
))
839 (when (stringp symbol
)
840 (if (string-equal "" symbol
)
842 (setq symbol
(intern symbol
))))
843 (custom-buffer-create-other-window
844 (list (list symbol
'custom-group
))
845 (format "*Customize Group: %s*" (custom-unlispify-tag-name symbol
))))
848 (defalias 'customize-variable
'customize-option
)
851 (defun customize-option (symbol)
852 "Customize SYMBOL, which must be a user option variable."
853 (interactive (custom-variable-prompt))
854 (custom-buffer-create (list (list symbol
'custom-variable
))
855 (format "*Customize Option: %s*"
856 (custom-unlispify-tag-name symbol
))))
859 (defun customize-changed-options (since-version)
860 "Customize all user option variables whose default values changed recently.
861 This means, in other words, variables defined with a `:version' option."
862 (interactive "sCustomize options changed, since version (default all versions): ")
863 (if (equal since-version
"")
864 (setq since-version nil
))
866 (mapatoms (lambda (symbol)
868 (let ((version (get symbol
'custom-version
)))
870 (or (null since-version
)
871 (customize-version-lessp since-version version
))))
873 (cons (list symbol
'custom-variable
) found
)))))
875 (error "No user options have changed defaults in recent Emacs versions")
876 (custom-buffer-create (custom-sort-items found t nil
)
877 "*Customize Changed Options*"))))
879 (defun customize-version-lessp (version1 version2
)
880 (let (major1 major2 minor1 minor2
)
881 (string-match "\\([0-9]+\\)[.]\\([0-9]+\\)" version1
)
882 (setq major1
(read (match-string 1 version1
)))
883 (setq minor1
(read (match-string 2 version1
)))
884 (string-match "\\([0-9]+\\)[.]\\([0-9]+\\)" version2
)
885 (setq major2
(read (match-string 1 version2
)))
886 (setq minor2
(read (match-string 2 version2
)))
887 (or (< major1 major2
)
888 (and (= major1 major2
)
889 (< minor1 minor2
)))))
892 (defalias 'customize-variable-other-window
'customize-option-other-window
)
895 (defun customize-option-other-window (symbol)
896 "Customize SYMBOL, which must be a user option variable.
897 Show the buffer in another window, but don't select it."
898 (interactive (custom-variable-prompt))
899 (custom-buffer-create-other-window
900 (list (list symbol
'custom-variable
))
901 (format "*Customize Option: %s*" (custom-unlispify-tag-name symbol
))))
904 (defun customize-face (&optional symbol
)
905 "Customize SYMBOL, which should be a face name or nil.
906 If SYMBOL is nil, customize all faces."
907 (interactive (list (completing-read "Customize face: (default all) "
908 obarray
'custom-facep
)))
909 (if (or (null symbol
) (and (stringp symbol
) (zerop (length symbol
))))
910 (custom-buffer-create (custom-sort-items
911 (mapcar (lambda (symbol)
912 (list symbol
'custom-face
))
916 (when (stringp symbol
)
917 (setq symbol
(intern symbol
)))
918 (unless (symbolp symbol
)
919 (error "Should be a symbol %S" symbol
))
920 (custom-buffer-create (list (list symbol
'custom-face
))
921 (format "*Customize Face: %s*"
922 (custom-unlispify-tag-name symbol
)))))
925 (defun customize-face-other-window (&optional symbol
)
926 "Show customization buffer for FACE in other window."
927 (interactive (list (completing-read "Customize face: "
928 obarray
'custom-facep
)))
929 (if (or (null symbol
) (and (stringp symbol
) (zerop (length symbol
))))
932 (setq symbol
(intern symbol
)))
933 (unless (symbolp symbol
)
934 (error "Should be a symbol %S" symbol
))
935 (custom-buffer-create-other-window
936 (list (list symbol
'custom-face
))
937 (format "*Customize Face: %s*" (custom-unlispify-tag-name symbol
)))))
940 (defun customize-customized ()
941 "Customize all user options set since the last save in this session."
944 (mapatoms (lambda (symbol)
945 (and (get symbol
'customized-face
)
946 (custom-facep symbol
)
947 (push (list symbol
'custom-face
) found
))
948 (and (get symbol
'customized-value
)
950 (push (list symbol
'custom-variable
) found
))))
952 (error "No customized user options")
953 (custom-buffer-create (custom-sort-items found t nil
)
954 "*Customize Customized*"))))
957 (defun customize-saved ()
958 "Customize all already saved user options."
961 (mapatoms (lambda (symbol)
962 (and (get symbol
'saved-face
)
963 (custom-facep symbol
)
964 (push (list symbol
'custom-face
) found
))
965 (and (get symbol
'saved-value
)
967 (push (list symbol
'custom-variable
) found
))))
969 (error "No saved user options")
970 (custom-buffer-create (custom-sort-items found t nil
)
971 "*Customize Saved*"))))
974 (defun customize-apropos (regexp &optional all
)
975 "Customize all user options matching REGEXP.
976 If ALL is `options', include only options.
977 If ALL is `faces', include only faces.
978 If ALL is `groups', include only groups.
979 If ALL is t (interactively, with prefix arg), include options which are not
980 user-settable, as well as faces and groups."
981 (interactive "sCustomize regexp: \nP")
983 (mapatoms (lambda (symbol)
984 (when (string-match regexp
(symbol-name symbol
))
985 (when (and (not (memq all
'(faces options
)))
986 (get symbol
'custom-group
))
987 (push (list symbol
'custom-group
) found
))
988 (when (and (not (memq all
'(options groups
)))
989 (custom-facep symbol
))
990 (push (list symbol
'custom-face
) found
))
991 (when (and (not (memq all
'(groups faces
)))
993 (or (get symbol
'saved-value
)
994 (get symbol
'standard-value
)
995 (if (memq all
'(nil options
))
996 (user-variable-p symbol
)
997 (get symbol
'variable-documentation
))))
998 (push (list symbol
'custom-variable
) found
)))))
1000 (error "No matches")
1001 (custom-buffer-create (custom-sort-items found t
1002 custom-buffer-order-groups
)
1003 "*Customize Apropos*"))))
1006 (defun customize-apropos-options (regexp &optional arg
)
1007 "Customize all user options matching REGEXP.
1008 With prefix arg, include options which are not user-settable."
1009 (interactive "sCustomize regexp: \nP")
1010 (customize-apropos regexp
(or arg
'options
)))
1013 (defun customize-apropos-faces (regexp)
1014 "Customize all user faces matching REGEXP."
1015 (interactive "sCustomize regexp: \n")
1016 (customize-apropos regexp
'faces
))
1019 (defun customize-apropos-groups (regexp)
1020 "Customize all user groups matching REGEXP."
1021 (interactive "sCustomize regexp: \n")
1022 (customize-apropos regexp
'groups
))
1026 (defcustom custom-buffer-style
'links
1027 "Control the presentation style for customization buffers.
1028 The value should be a symbol, one of:
1030 brackets: groups nest within each other with big horizontal brackets.
1031 links: groups have links to subgroups."
1032 :type
'(radio (const brackets
)
1034 :group
'custom-buffer
)
1036 (defcustom custom-buffer-indent
3
1037 "Number of spaces to indent nested groups."
1039 :group
'custom-buffer
)
1042 (defun custom-buffer-create (options &optional name description
)
1043 "Create a buffer containing OPTIONS.
1044 Optional NAME is the name of the buffer.
1045 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1046 SYMBOL is a customization option, and WIDGET is a widget for editing
1048 (unless name
(setq name
"*Customization*"))
1049 (kill-buffer (get-buffer-create name
))
1050 (switch-to-buffer (get-buffer-create name
))
1051 (custom-buffer-create-internal options description
))
1054 (defun custom-buffer-create-other-window (options &optional name description
)
1055 "Create a buffer containing OPTIONS.
1056 Optional NAME is the name of the buffer.
1057 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1058 SYMBOL is a customization option, and WIDGET is a widget for editing
1060 (unless name
(setq name
"*Customization*"))
1061 (kill-buffer (get-buffer-create name
))
1062 (let ((window (selected-window)))
1063 (switch-to-buffer-other-window (get-buffer-create name
))
1064 (custom-buffer-create-internal options description
)
1065 (select-window window
)))
1067 (defcustom custom-reset-button-menu nil
1068 "If non-nil, only show a single reset button in customize buffers.
1069 This button will have a menu with all three reset operations."
1071 :group
'custom-buffer
)
1073 (defun custom-buffer-create-internal (options &optional description
)
1074 (message "Creating customization buffer...")
1076 (widget-insert "This is a customization buffer")
1078 (widget-insert description
))
1080 Square brackets show active fields; type RET or click mouse-1
1081 on an active field to invoke its action. Editing an option value
1082 changes the text in the buffer; invoke the State button and
1083 choose the Set operation to set the option value.
1085 (widget-create 'info-link
1087 :help-echo
"Read the online help."
1088 "(emacs)Easy Customization")
1089 (widget-insert " for more information.\n\n")
1090 (message "Creating customization buttons...")
1091 (widget-insert "Operate on everything in this buffer:\n ")
1092 (widget-create 'push-button
1093 :tag
"Set for Current Session"
1095 Make your editing in this buffer take effect for this session."
1096 :action
(lambda (widget &optional event
)
1099 (widget-create 'push-button
1100 :tag
"Save for Future Sessions"
1102 Make your editing in this buffer take effect for future Emacs sessions."
1103 :action
(lambda (widget &optional event
)
1105 (if custom-reset-button-menu
1108 (widget-create 'push-button
1110 :help-echo
"Show a menu with reset operations."
1111 :mouse-down-action
(lambda (&rest junk
) t
)
1112 :action
(lambda (widget &optional event
)
1113 (custom-reset event
))))
1114 (widget-insert "\n ")
1115 (widget-create 'push-button
1118 Reset all edited text in this buffer to reflect current values."
1119 :action
'Custom-reset-current
)
1121 (widget-create 'push-button
1122 :tag
"Reset to Saved"
1124 Reset all values in this buffer to their saved settings."
1125 :action
'Custom-reset-saved
)
1127 (widget-create 'push-button
1128 :tag
"Reset to Standard"
1130 Reset all values in this buffer to their standard settings."
1131 :action
'Custom-reset-standard
))
1133 (widget-create 'push-button
1135 :help-echo
"Bury the buffer."
1136 :action
(lambda (widget &optional event
)
1138 (widget-insert "\n\n")
1139 (message "Creating customization items...")
1140 (setq custom-options
1141 (if (= (length options
) 1)
1142 (mapcar (lambda (entry)
1143 (widget-create (nth 1 entry
)
1144 :documentation-shown t
1145 :custom-state
'unknown
1146 :tag
(custom-unlispify-tag-name
1148 :value
(nth 0 entry
)))
1151 (length (length options
)))
1152 (mapcar (lambda (entry)
1154 (message "Creating customization items %2d%%..."
1155 (/ (* 100.0 count
) length
))
1156 (widget-create (nth 1 entry
)
1157 :tag
(custom-unlispify-tag-name
1159 :value
(nth 0 entry
))
1160 (setq count
(1+ count
))
1161 (unless (eq (preceding-char) ?
\n)
1162 (widget-insert "\n"))
1163 (widget-insert "\n")))
1165 (unless (eq (preceding-char) ?
\n)
1166 (widget-insert "\n"))
1167 (message "Creating customization items %2d%%...done" 100)
1168 (unless (eq custom-buffer-style
'tree
)
1169 (mapcar 'custom-magic-reset custom-options
))
1170 (message "Creating customization setup...")
1172 (goto-char (point-min))
1173 (message "Creating customization buffer...done"))
1175 ;;; The Tree Browser.
1178 (defun customize-browse (&optional group
)
1179 "Create a tree browser for the customize hierarchy."
1182 (setq group
'emacs
))
1183 (let ((name "*Customize Browser*"))
1184 (kill-buffer (get-buffer-create name
))
1185 (switch-to-buffer (get-buffer-create name
)))
1188 Square brackets show active fields; type RET or click mouse-1
1189 on an active field to invoke its action.
1190 Invoke [+] below to expand a group, and [-] to collapse an expanded group.\n")
1191 (if custom-browse-only-groups
1193 Invoke the [Group] button below to edit that item in another window.\n\n")
1194 (widget-insert "Invoke the ")
1195 (widget-create 'item
1198 :tag-glyph
"folder")
1199 (widget-insert ", ")
1200 (widget-create 'item
1204 (widget-insert ", and ")
1205 (widget-create 'item
1208 :tag-glyph
"option")
1209 (widget-insert " buttons below to edit that
1210 item in another window.\n\n"))
1211 (let ((custom-buffer-style 'tree
))
1212 (widget-create 'custom-group
1214 :custom-state
'unknown
1215 :tag
(custom-unlispify-tag-name group
)
1217 (goto-char (point-min)))
1219 (define-widget 'custom-browse-visibility
'item
1220 "Control visibility of items in the customize tree browser."
1222 :action
'custom-browse-visibility-action
)
1224 (defun custom-browse-visibility-action (widget &rest ignore
)
1225 (let ((custom-buffer-style 'tree
))
1226 (custom-toggle-parent widget
)))
1228 (define-widget 'custom-browse-group-tag
'push-button
1229 "Show parent in other window when activated."
1232 :action
'custom-browse-group-tag-action
)
1234 (defun custom-browse-group-tag-action (widget &rest ignore
)
1235 (let ((parent (widget-get widget
:parent
)))
1236 (customize-group-other-window (widget-value parent
))))
1238 (define-widget 'custom-browse-variable-tag
'push-button
1239 "Show parent in other window when activated."
1242 :action
'custom-browse-variable-tag-action
)
1244 (defun custom-browse-variable-tag-action (widget &rest ignore
)
1245 (let ((parent (widget-get widget
:parent
)))
1246 (customize-variable-other-window (widget-value parent
))))
1248 (define-widget 'custom-browse-face-tag
'push-button
1249 "Show parent in other window when activated."
1252 :action
'custom-browse-face-tag-action
)
1254 (defun custom-browse-face-tag-action (widget &rest ignore
)
1255 (let ((parent (widget-get widget
:parent
)))
1256 (customize-face-other-window (widget-value parent
))))
1258 (defconst custom-browse-alist
'((" " "space")
1264 (defun custom-browse-insert-prefix (prefix)
1265 "Insert PREFIX. On XEmacs convert it to line graphics."
1266 (if nil
; (string-match "XEmacs" emacs-version)
1269 (while (not (string-equal prefix
""))
1270 (let ((entry (substring prefix
0 3)))
1271 (setq prefix
(substring prefix
3))
1272 (let ((overlay (make-overlay (1- (point)) (point) nil t nil
))
1273 (name (nth 1 (assoc entry custom-browse-alist
))))
1274 (overlay-put overlay
'end-glyph
(widget-glyph-find name entry
))
1275 (overlay-put overlay
'start-open t
)
1276 (overlay-put overlay
'end-open t
)))))
1279 ;;; Modification of Basic Widgets.
1281 ;; We add extra properties to the basic widgets needed here. This is
1282 ;; fine, as long as we are careful to stay within out own namespace.
1284 ;; We want simple widgets to be displayed by default, but complex
1285 ;; widgets to be hidden.
1287 (widget-put (get 'item
'widget-type
) :custom-show t
)
1288 (widget-put (get 'editable-field
'widget-type
)
1289 :custom-show
(lambda (widget value
)
1290 (let ((pp (pp-to-string value
)))
1291 (cond ((string-match "\n" pp
)
1296 (widget-put (get 'menu-choice
'widget-type
) :custom-show t
)
1298 ;;; The `custom-manual' Widget.
1300 (define-widget 'custom-manual
'info-link
1301 "Link to the manual entry for this customization option."
1302 :help-echo
"Read the manual entry for this option."
1305 ;;; The `custom-magic' Widget.
1307 (defgroup custom-magic-faces nil
1308 "Faces used by the magic button."
1309 :group
'custom-faces
1310 :group
'custom-buffer
)
1312 (defface custom-invalid-face
'((((class color
))
1313 (:foreground
"yellow" :background
"red"))
1315 (:bold t
:italic t
:underline t
)))
1316 "Face used when the customize item is invalid."
1317 :group
'custom-magic-faces
)
1319 (defface custom-rogue-face
'((((class color
))
1320 (:foreground
"pink" :background
"black"))
1323 "Face used when the customize item is not defined for customization."
1324 :group
'custom-magic-faces
)
1326 (defface custom-modified-face
'((((class color
))
1327 (:foreground
"white" :background
"blue"))
1330 "Face used when the customize item has been modified."
1331 :group
'custom-magic-faces
)
1333 (defface custom-set-face
'((((class color
))
1334 (:foreground
"blue" :background
"white"))
1337 "Face used when the customize item has been set."
1338 :group
'custom-magic-faces
)
1340 (defface custom-changed-face
'((((class color
))
1341 (:foreground
"white" :background
"blue"))
1344 "Face used when the customize item has been changed."
1345 :group
'custom-magic-faces
)
1347 (defface custom-saved-face
'((t (:underline t
)))
1348 "Face used when the customize item has been saved."
1349 :group
'custom-magic-faces
)
1351 (defconst custom-magic-alist
'((nil "#" underline
"\
1352 uninitialized, you should not see this.")
1353 (unknown "?" italic
"\
1354 unknown, you should not see this.")
1355 (hidden "-" default
"\
1356 hidden, invoke \"Show\" in the previous line to show." "\
1357 group now hidden, invoke \"Show\", above, to show contents.")
1358 (invalid "x" custom-invalid-face
"\
1359 the value displayed for this %c is invalid and cannot be set.")
1360 (modified "*" custom-modified-face
"\
1361 you have edited the value as text, but you have not set the %c." "\
1362 you have edited something in this group, but not set it.")
1363 (set "+" custom-set-face
"\
1364 you have set this %c, but not saved it for future sessions." "\
1365 something in this group has been set, but not saved.")
1366 (changed ":" custom-changed-face
"\
1367 this %c has been changed outside the customize buffer." "\
1368 something in this group has been changed outside customize.")
1369 (saved "!" custom-saved-face
"\
1370 this %c has been set and saved." "\
1371 something in this group has been set and saved.")
1372 (rogue "@" custom-rogue-face
"\
1373 this %c has not been changed with customize." "\
1374 something in this group is not prepared for customization.")
1375 (standard " " nil
"\
1376 this %c is unchanged from its standard setting." "\
1377 visible group members are all at standard settings."))
1378 "Alist of customize option states.
1379 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1381 STATE is one of the following symbols:
1384 For internal use, should never occur.
1386 For internal use, should never occur.
1388 This item is not being displayed.
1390 This item is modified, but has an invalid form.
1392 This item is modified, and has a valid form.
1394 This item has been set but not saved.
1396 The current value of this item has been changed temporarily.
1398 This item is marked for saving.
1400 This item has no customization information.
1402 This item is unchanged from the standard setting.
1404 MAGIC is a string used to present that state.
1406 FACE is a face used to present the state.
1408 ITEM-DESC is a string describing the state for options.
1410 GROUP-DESC is a string describing the state for groups. If this is
1411 left out, ITEM-DESC will be used.
1413 The string %c in either description will be replaced with the
1414 category of the item. These are `group'. `option', and `face'.
1416 The list should be sorted most significant first.")
1418 (defcustom custom-magic-show
'long
1419 "If non-nil, show textual description of the state.
1420 If `long', show a full-line description, not just one word."
1421 :type
'(choice (const :tag
"no" nil
)
1424 :group
'custom-buffer
)
1426 (defcustom custom-magic-show-hidden
'(option face
)
1427 "Control whether the State button is shown for hidden items.
1428 The value should be a list with the custom categories where the State
1429 button should be visible. Possible categories are `group', `option',
1431 :type
'(set (const group
) (const option
) (const face
))
1432 :group
'custom-buffer
)
1434 (defcustom custom-magic-show-button nil
1435 "Show a \"magic\" button indicating the state of each customization option."
1437 :group
'custom-buffer
)
1439 (define-widget 'custom-magic
'default
1440 "Show and manipulate state for a customization option."
1442 :action
'widget-parent-action
1445 :value-create
'custom-magic-value-create
1446 :value-delete
'widget-children-value-delete
)
1448 (defun widget-magic-mouse-down-action (widget &optional event
)
1449 ;; Non-nil unless hidden.
1450 (not (eq (widget-get (widget-get (widget-get widget
:parent
) :parent
)
1454 (defun custom-magic-value-create (widget)
1455 ;; Create compact status report for WIDGET.
1456 (let* ((parent (widget-get widget
:parent
))
1457 (state (widget-get parent
:custom-state
))
1458 (hidden (eq state
'hidden
))
1459 (entry (assq state custom-magic-alist
))
1460 (magic (nth 1 entry
))
1461 (face (nth 2 entry
))
1462 (category (widget-get parent
:custom-category
))
1463 (text (or (and (eq category
'group
)
1466 (form (widget-get parent
:custom-form
))
1468 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text
)
1469 (setq text
(concat (match-string 1 text
)
1470 (symbol-name category
)
1471 (match-string 2 text
))))
1472 (when (and custom-magic-show
1474 (memq category custom-magic-show-hidden
)))
1476 (when (and (eq category
'group
)
1477 (not (and (eq custom-buffer-style
'links
)
1478 (> (widget-get parent
:custom-level
) 1))))
1479 (insert-char ?\
(* custom-buffer-indent
1480 (widget-get parent
:custom-level
))))
1481 (push (widget-create-child-and-convert
1483 :help-echo
"Change the state of this item."
1484 :format
(if hidden
"%t" "%[%t%]")
1485 :button-prefix
'widget-push-button-prefix
1486 :button-suffix
'widget-push-button-suffix
1487 :mouse-down-action
'widget-magic-mouse-down-action
1491 (let ((start (point)))
1492 (if (eq custom-magic-show
'long
)
1494 (insert (symbol-name state
)))
1495 (cond ((eq form
'lisp
)
1497 ((eq form
'mismatch
)
1498 (insert " (mismatch)")))
1499 (put-text-property start
(point) 'face
'custom-state-face
))
1501 (when (and (eq category
'group
)
1502 (not (and (eq custom-buffer-style
'links
)
1503 (> (widget-get parent
:custom-level
) 1))))
1504 (insert-char ?\
(* custom-buffer-indent
1505 (widget-get parent
:custom-level
))))
1506 (when custom-magic-show-button
1507 (when custom-magic-show
1508 (let ((indent (widget-get parent
:indent
)))
1510 (insert-char ? indent
))))
1511 (push (widget-create-child-and-convert
1513 :mouse-down-action
'widget-magic-mouse-down-action
1517 :help-echo
"Change the state."
1518 :format
(if hidden
"%t" "%[%t%]")
1519 :tag
(if (memq form
'(lisp mismatch
))
1520 (concat "(" magic
")")
1521 (concat "[" magic
"]")))
1524 (widget-put widget
:children children
)))
1526 (defun custom-magic-reset (widget)
1527 "Redraw the :custom-magic property of WIDGET."
1528 (let ((magic (widget-get widget
:custom-magic
)))
1529 (widget-value-set magic
(widget-value magic
))))
1531 ;;; The `custom' Widget.
1533 (defface custom-button-face nil
1534 "Face used for buttons in customization buffers."
1535 :group
'custom-faces
)
1537 (defface custom-documentation-face nil
1538 "Face used for documentation strings in customization buffers."
1539 :group
'custom-faces
)
1541 (defface custom-state-face
'((((class color
)
1543 (:foreground
"lime green"))
1546 (:foreground
"dark green"))
1548 "Face used for State descriptions in the customize buffer."
1549 :group
'custom-faces
)
1551 (define-widget 'custom
'default
1552 "Customize a user option."
1554 :convert-widget
'custom-convert-widget
1555 :notify
'custom-notify
1558 :custom-state
'hidden
1559 :documentation-property
'widget-subclass-responsibility
1560 :value-create
'widget-subclass-responsibility
1561 :value-delete
'widget-children-value-delete
1562 :value-get
'widget-value-value-get
1563 :validate
'widget-children-validate
1564 :match
(lambda (widget value
) (symbolp value
)))
1566 (defun custom-convert-widget (widget)
1567 ;; Initialize :value and :tag from :args in WIDGET.
1568 (let ((args (widget-get widget
:args
)))
1570 (widget-put widget
:value
(widget-apply widget
1571 :value-to-internal
(car args
)))
1572 (widget-put widget
:tag
(custom-unlispify-tag-name (car args
)))
1573 (widget-put widget
:args nil
)))
1576 (defun custom-notify (widget &rest args
)
1577 "Keep track of changes."
1578 (let ((state (widget-get widget
:custom-state
)))
1579 (unless (eq state
'modified
)
1580 (unless (memq state
'(nil unknown hidden
))
1581 (widget-put widget
:custom-state
'modified
))
1582 (custom-magic-reset widget
)
1583 (apply 'widget-default-notify widget args
))))
1585 (defun custom-redraw (widget)
1586 "Redraw WIDGET with current settings."
1587 (let ((line (count-lines (point-min) (point)))
1588 (column (current-column))
1590 (from (marker-position (widget-get widget
:from
)))
1591 (to (marker-position (widget-get widget
:to
))))
1593 (widget-value-set widget
(widget-value widget
))
1594 (custom-redraw-magic widget
))
1595 (when (and (>= pos from
) (<= pos to
))
1600 (goto-line (1+ line
)))
1601 (move-to-column column
))
1604 (defun custom-redraw-magic (widget)
1605 "Redraw WIDGET state with current settings."
1607 (let ((magic (widget-get widget
:custom-magic
)))
1609 (widget-value-set magic
(widget-value magic
))
1610 (when (setq widget
(widget-get widget
:group
))
1611 (custom-group-state-update widget
)))
1613 (setq widget nil
)))))
1616 (defun custom-show (widget value
)
1617 "Non-nil if WIDGET should be shown with VALUE by default."
1618 (let ((show (widget-get widget
:custom-show
)))
1624 (funcall show widget value
)))))
1626 (defvar custom-load-recursion nil
1627 "Hack to avoid recursive dependencies.")
1629 (defun custom-load-symbol (symbol)
1630 "Load all dependencies for SYMBOL."
1631 (unless custom-load-recursion
1632 (let ((custom-load-recursion t
)
1633 (loads (get symbol
'custom-loads
))
1636 (setq load
(car loads
)
1638 (cond ((symbolp load
)
1642 ;; Don't reload a file already loaded.
1643 ((and (boundp 'preloaded-file-list
)
1644 (member load preloaded-file-list
)))
1645 ((assoc load load-history
))
1646 ((assoc (locate-library load
) load-history
))
1649 ;; Without this, we would load cus-edit recursively.
1650 ;; We are still loading it when we call this,
1651 ;; and it is not in load-history yet.
1652 (or (equal load
"cus-edit")
1653 (load-library load
))
1656 (defun custom-load-widget (widget)
1657 "Load all dependencies for WIDGET."
1658 (custom-load-symbol (widget-value widget
)))
1660 (defun custom-unloaded-symbol-p (symbol)
1661 "Return non-nil if the dependencies of SYMBOL has not yet been loaded."
1663 (loads (get symbol
'custom-loads
))
1666 (setq load
(car loads
)
1668 (cond ((symbolp load
)
1669 (unless (featurep load
)
1671 ((assoc load load-history
))
1672 ((assoc (locate-library load
) load-history
)
1678 (defun custom-unloaded-widget-p (widget)
1679 "Return non-nil if the dependencies of WIDGET has not yet been loaded."
1680 (custom-unloaded-symbol-p (widget-value widget
)))
1682 (defun custom-toggle-hide (widget)
1683 "Toggle visibility of WIDGET."
1684 (custom-load-widget widget
)
1685 (let ((state (widget-get widget
:custom-state
)))
1686 (cond ((memq state
'(invalid modified
))
1687 (error "There are unset changes"))
1689 (widget-put widget
:custom-state
'unknown
))
1691 (widget-put widget
:documentation-shown nil
)
1692 (widget-put widget
:custom-state
'hidden
)))
1693 (custom-redraw widget
)
1696 (defun custom-toggle-parent (widget &rest ignore
)
1697 "Toggle visibility of parent of WIDGET."
1698 (custom-toggle-hide (widget-get widget
:parent
)))
1700 (defun custom-add-see-also (widget &optional prefix
)
1701 "Add `See also ...' to WIDGET if there are any links.
1702 Insert PREFIX first if non-nil."
1703 (let* ((symbol (widget-get widget
:value
))
1704 (links (get symbol
'custom-links
))
1705 (many (> (length links
) 2))
1706 (buttons (widget-get widget
:buttons
))
1707 (indent (widget-get widget
:indent
)))
1710 (insert-char ?\ indent
))
1713 (insert "See also ")
1715 (push (widget-create-child-and-convert widget
(car links
))
1717 (setq links
(cdr links
))
1726 (widget-put widget
:buttons buttons
))))
1728 (defun custom-add-parent-links (widget &optional initial-string
)
1729 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
1730 The value if non-nil if any parents were found.
1731 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
1732 (let ((name (widget-value widget
))
1733 (type (widget-type widget
))
1734 (buttons (widget-get widget
:buttons
))
1737 (insert (or initial-string
"Parent groups:"))
1738 (mapatoms (lambda (symbol)
1739 (let ((entry (assq name
(get symbol
'custom-group
))))
1740 (when (eq (nth 1 entry
) type
)
1742 (push (widget-create-child-and-convert
1743 widget
'custom-group-link
1744 :tag
(custom-unlispify-tag-name symbol
)
1748 (widget-put widget
:buttons buttons
)
1751 (delete-region start
(point)))
1754 ;;; The `custom-variable' Widget.
1756 (defface custom-variable-tag-face
'((((class color
)
1758 (:foreground
"light blue" :underline t
))
1761 (:foreground
"blue" :underline t
))
1763 "Face used for unpushable variable tags."
1764 :group
'custom-faces
)
1766 (defface custom-variable-button-face
'((t (:underline t
:bold t
)))
1767 "Face used for pushable variable tags."
1768 :group
'custom-faces
)
1770 (defcustom custom-variable-default-form
'edit
1771 "Default form of displaying variable values."
1772 :type
'(choice (const edit
)
1774 :group
'custom-buffer
)
1776 (define-widget 'custom-variable
'custom
1777 "Customize variable."
1779 :help-echo
"Set or reset this variable."
1780 :documentation-property
'variable-documentation
1781 :custom-category
'option
1783 :custom-menu
'custom-variable-menu-create
1784 :custom-form nil
; defaults to value of `custom-variable-default-form'
1785 :value-create
'custom-variable-value-create
1786 :action
'custom-variable-action
1787 :custom-set
'custom-variable-set
1788 :custom-save
'custom-variable-save
1789 :custom-reset-current
'custom-redraw
1790 :custom-reset-saved
'custom-variable-reset-saved
1791 :custom-reset-standard
'custom-variable-reset-standard
)
1793 (defun custom-variable-type (symbol)
1794 "Return a widget suitable for editing the value of SYMBOL.
1795 If SYMBOL has a `custom-type' property, use that.
1796 Otherwise, look up symbol in `custom-guess-type-alist'."
1797 (let* ((type (or (get symbol
'custom-type
)
1798 (and (not (get symbol
'standard-value
))
1799 (custom-guess-type symbol
))
1801 (options (get symbol
'custom-options
))
1802 (tmp (if (listp type
)
1803 (copy-sequence type
)
1806 (widget-put tmp
:options options
))
1809 (defun custom-variable-value-create (widget)
1810 "Here is where you edit the variables value."
1811 (custom-load-widget widget
)
1812 (unless (widget-get widget
:custom-form
)
1813 (widget-put widget
:custom-form custom-variable-default-form
))
1814 (let* ((buttons (widget-get widget
:buttons
))
1815 (children (widget-get widget
:children
))
1816 (form (widget-get widget
:custom-form
))
1817 (state (widget-get widget
:custom-state
))
1818 (symbol (widget-get widget
:value
))
1819 (tag (widget-get widget
:tag
))
1820 (type (custom-variable-type symbol
))
1821 (conv (widget-convert type
))
1822 (get (or (get symbol
'custom-get
) 'default-value
))
1823 (prefix (widget-get widget
:custom-prefix
))
1824 (last (widget-get widget
:custom-last
))
1825 (value (if (default-boundp symbol
)
1826 (funcall get symbol
)
1827 (widget-get conv
:value
))))
1828 ;; If the widget is new, the child determine whether it is hidden.
1830 ((custom-show type value
)
1831 (setq state
'unknown
))
1833 (setq state
'hidden
)))
1834 ;; If we don't know the state, see if we need to edit it in lisp form.
1835 (when (eq state
'unknown
)
1836 (unless (widget-apply conv
:match value
)
1837 ;; (widget-apply (widget-convert type) :match value)
1838 (setq form
'mismatch
)))
1839 ;; Now we can create the child widget.
1840 (cond ((eq custom-buffer-style
'tree
)
1841 (insert prefix
(if last
" `--- " " |--- "))
1842 (push (widget-create-child-and-convert
1843 widget
'custom-browse-variable-tag
)
1845 (insert " " tag
"\n")
1846 (widget-put widget
:buttons buttons
))
1848 ;; Indicate hidden value.
1849 (push (widget-create-child-and-convert
1852 :sample-face
'custom-variable-tag-face
1856 (push (widget-create-child-and-convert
1858 :help-echo
"Show the value of this option."
1859 :action
'custom-toggle-parent
1862 ((memq form
'(lisp mismatch
))
1863 ;; In lisp mode edit the saved value when possible.
1864 (let* ((value (cond ((get symbol
'saved-value
)
1865 (car (get symbol
'saved-value
)))
1866 ((get symbol
'standard-value
)
1867 (car (get symbol
'standard-value
)))
1868 ((default-boundp symbol
)
1869 (custom-quote (funcall get symbol
)))
1871 (custom-quote (widget-get conv
:value
))))))
1872 (insert (symbol-name symbol
) ": ")
1873 (push (widget-create-child-and-convert
1875 :help-echo
"Hide the value of this option."
1876 :action
'custom-toggle-parent
1880 (push (widget-create-child-and-convert
1882 :button-face
'custom-variable-button-face
1884 :tag
(symbol-name symbol
)
1890 (let* ((format (widget-get type
:format
))
1891 tag-format value-format
)
1892 (unless (string-match ":" format
)
1893 (error "Bad format"))
1894 (setq tag-format
(substring format
0 (match-end 0)))
1895 (setq value-format
(substring format
(match-end 0)))
1896 (push (widget-create-child-and-convert
1899 :action
'custom-tag-action
1900 :help-echo
"Change value of this option."
1901 :mouse-down-action
'custom-tag-mouse-down-action
1902 :button-face
'custom-variable-button-face
1903 :sample-face
'custom-variable-tag-face
1907 (push (widget-create-child-and-convert
1909 :help-echo
"Hide the value of this option."
1910 :action
'custom-toggle-parent
1913 (push (widget-create-child-and-convert
1915 :format value-format
1918 (unless (eq custom-buffer-style
'tree
)
1919 ;; Now update the state.
1920 (unless (eq (preceding-char) ?
\n)
1921 (widget-insert "\n"))
1922 (if (eq state
'hidden
)
1923 (widget-put widget
:custom-state state
)
1924 (custom-variable-state-set widget
))
1925 ;; Create the magic button.
1926 (let ((magic (widget-create-child-and-convert
1927 widget
'custom-magic nil
)))
1928 (widget-put widget
:custom-magic magic
)
1929 (push magic buttons
))
1930 ;; Update properties.
1931 (widget-put widget
:custom-form form
)
1932 (widget-put widget
:buttons buttons
)
1933 (widget-put widget
:children children
)
1934 ;; Insert documentation.
1935 (widget-default-format-handler widget ?h
)
1937 (unless (eq state
'hidden
)
1938 (when (eq (widget-get widget
:custom-level
) 1)
1939 (custom-add-parent-links widget
))
1940 (custom-add-see-also widget
)))))
1942 (defun custom-tag-action (widget &rest args
)
1943 "Pass :action to first child of WIDGET's parent."
1944 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
1947 (defun custom-tag-mouse-down-action (widget &rest args
)
1948 "Pass :mouse-down-action to first child of WIDGET's parent."
1949 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
1950 :mouse-down-action args
))
1952 (defun custom-variable-state-set (widget)
1953 "Set the state of WIDGET."
1954 (let* ((symbol (widget-value widget
))
1955 (get (or (get symbol
'custom-get
) 'default-value
))
1956 (value (if (default-boundp symbol
)
1957 (funcall get symbol
)
1958 (widget-get widget
:value
)))
1960 (state (cond ((setq tmp
(get symbol
'customized-value
))
1961 (if (condition-case nil
1962 (equal value
(eval (car tmp
)))
1966 ((setq tmp
(get symbol
'saved-value
))
1967 (if (condition-case nil
1968 (equal value
(eval (car tmp
)))
1972 ((setq tmp
(get symbol
'standard-value
))
1973 (if (condition-case nil
1974 (equal value
(eval (car tmp
)))
1979 (widget-put widget
:custom-state state
)))
1981 (defvar custom-variable-menu
1982 '(("Set for Current Session" custom-variable-set
1984 (eq (widget-get widget
:custom-state
) 'modified
)))
1985 ("Save for Future Sessions" custom-variable-save
1987 (memq (widget-get widget
:custom-state
) '(modified set changed rogue
))))
1988 ("Reset to Current" custom-redraw
1990 (and (default-boundp (widget-value widget
))
1991 (memq (widget-get widget
:custom-state
) '(modified changed
)))))
1992 ("Reset to Saved" custom-variable-reset-saved
1994 (and (get (widget-value widget
) 'saved-value
)
1995 (memq (widget-get widget
:custom-state
)
1996 '(modified set changed rogue
)))))
1997 ("Reset to Standard Settings" custom-variable-reset-standard
1999 (and (get (widget-value widget
) 'standard-value
)
2000 (memq (widget-get widget
:custom-state
)
2001 '(modified set changed saved rogue
)))))
2002 ("---" ignore ignore
)
2003 ("Don't show as Lisp expression" custom-variable-edit
2005 (eq (widget-get widget
:custom-form
) 'lisp
)))
2006 ("Show initial Lisp expression" custom-variable-edit-lisp
2008 (eq (widget-get widget
:custom-form
) 'edit
))))
2009 "Alist of actions for the `custom-variable' widget.
2010 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2011 the menu entry, ACTION is the function to call on the widget when the
2012 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2013 widget as an argument, and returns non-nil if ACTION is valid on that
2014 widget. If FILTER is nil, ACTION is always valid.")
2016 (defun custom-variable-action (widget &optional event
)
2017 "Show the menu for `custom-variable' WIDGET.
2018 Optional EVENT is the location for the menu."
2019 (if (eq (widget-get widget
:custom-state
) 'hidden
)
2020 (custom-toggle-hide widget
)
2021 (unless (eq (widget-get widget
:custom-state
) 'modified
)
2022 (custom-variable-state-set widget
))
2023 (custom-redraw-magic widget
)
2024 (let* ((completion-ignore-case t
)
2025 (answer (widget-choose (concat "Operation on "
2026 (custom-unlispify-tag-name
2027 (widget-get widget
:value
)))
2028 (custom-menu-filter custom-variable-menu
2032 (funcall answer widget
)))))
2034 (defun custom-variable-edit (widget)
2035 "Edit value of WIDGET."
2036 (widget-put widget
:custom-state
'unknown
)
2037 (widget-put widget
:custom-form
'edit
)
2038 (custom-redraw widget
))
2040 (defun custom-variable-edit-lisp (widget)
2041 "Edit the lisp representation of the value of WIDGET."
2042 (widget-put widget
:custom-state
'unknown
)
2043 (widget-put widget
:custom-form
'lisp
)
2044 (custom-redraw widget
))
2046 (defun custom-variable-set (widget)
2047 "Set the current value for the variable being edited by WIDGET."
2048 (let* ((form (widget-get widget
:custom-form
))
2049 (state (widget-get widget
:custom-state
))
2050 (child (car (widget-get widget
:children
)))
2051 (symbol (widget-value widget
))
2052 (set (or (get symbol
'custom-set
) 'set-default
))
2054 (cond ((eq state
'hidden
)
2055 (error "Cannot set hidden variable"))
2056 ((setq val
(widget-apply child
:validate
))
2057 (goto-char (widget-get val
:from
))
2058 (error "%s" (widget-get val
:error
)))
2059 ((memq form
'(lisp mismatch
))
2060 (funcall set symbol
(eval (setq val
(widget-value child
))))
2061 (put symbol
'customized-value
(list val
)))
2063 (funcall set symbol
(setq val
(widget-value child
)))
2064 (put symbol
'customized-value
(list (custom-quote val
)))))
2065 (custom-variable-state-set widget
)
2066 (custom-redraw-magic widget
)))
2068 (defun custom-variable-save (widget)
2069 "Set and save the value for the variable being edited by WIDGET."
2070 (let* ((form (widget-get widget
:custom-form
))
2071 (state (widget-get widget
:custom-state
))
2072 (child (car (widget-get widget
:children
)))
2073 (symbol (widget-value widget
))
2074 (set (or (get symbol
'custom-set
) 'set-default
))
2076 (cond ((eq state
'hidden
)
2077 (error "Cannot set hidden variable"))
2078 ((setq val
(widget-apply child
:validate
))
2079 (goto-char (widget-get val
:from
))
2080 (error "%s" (widget-get val
:error
)))
2081 ((memq form
'(lisp mismatch
))
2082 (put symbol
'saved-value
(list (widget-value child
)))
2083 (funcall set symbol
(eval (widget-value child
))))
2086 'saved-value
(list (custom-quote (widget-value
2088 (funcall set symbol
(widget-value child
))))
2089 (put symbol
'customized-value nil
)
2091 (custom-variable-state-set widget
)
2092 (custom-redraw-magic widget
)))
2094 (defun custom-variable-reset-saved (widget)
2095 "Restore the saved value for the variable being edited by WIDGET."
2096 (let* ((symbol (widget-value widget
))
2097 (set (or (get symbol
'custom-set
) 'set-default
)))
2098 (if (get symbol
'saved-value
)
2100 (funcall set symbol
(eval (car (get symbol
'saved-value
))))
2102 (error "No saved value for %s" symbol
))
2103 (put symbol
'customized-value nil
)
2104 (widget-put widget
:custom-state
'unknown
)
2105 (custom-redraw widget
)))
2107 (defun custom-variable-reset-standard (widget)
2108 "Restore the standard setting for the variable being edited by WIDGET."
2109 (let* ((symbol (widget-value widget
))
2110 (set (or (get symbol
'custom-set
) 'set-default
)))
2111 (if (get symbol
'standard-value
)
2112 (funcall set symbol
(eval (car (get symbol
'standard-value
))))
2113 (error "No standard setting known for %S" symbol
))
2114 (put symbol
'customized-value nil
)
2115 (when (get symbol
'saved-value
)
2116 (put symbol
'saved-value nil
)
2118 (widget-put widget
:custom-state
'unknown
)
2119 (custom-redraw widget
)))
2121 ;;; The `custom-face-edit' Widget.
2123 (define-widget 'custom-face-edit
'checklist
2124 "Edit face attributes."
2128 :button-args
'(:help-echo
"Control whether this attribute have any effect.")
2129 :args
(mapcar (lambda (att)
2132 :sibling-args
(widget-get (nth 1 att
) :sibling-args
)
2133 (list 'const
:format
"" :value
(nth 0 att
))
2135 custom-face-attributes
))
2137 ;;; The `custom-display' Widget.
2139 (define-widget 'custom-display
'menu-choice
2140 "Select a display type."
2143 :help-echo
"Specify frames where the face attributes should be used."
2144 :args
'((const :tag
"all" t
)
2148 :args
((group :sibling-args
(:help-echo
"\
2149 Only match the specified window systems.")
2150 (const :format
"Type: "
2152 (checklist :inline t
2155 :sibling-args
(:help-echo
"\
2156 The X11 Window System.")
2158 (const :format
"PM "
2159 :sibling-args
(:help-echo
"\
2160 OS/2 Presentation Manager.")
2162 (const :format
"W32 "
2163 :sibling-args
(:help-echo
"\
2166 (const :format
"DOS "
2167 :sibling-args
(:help-echo
"\
2170 (const :format
"TTY%n"
2171 :sibling-args
(:help-echo
"\
2172 Plain text terminals.")
2174 (group :sibling-args
(:help-echo
"\
2175 Only match the frames with the specified color support.")
2176 (const :format
"Class: "
2178 (checklist :inline t
2180 (const :format
"Color "
2181 :sibling-args
(:help-echo
"\
2182 Match color frames.")
2184 (const :format
"Grayscale "
2185 :sibling-args
(:help-echo
"\
2186 Match grayscale frames.")
2188 (const :format
"Monochrome%n"
2189 :sibling-args
(:help-echo
"\
2190 Match frames with no color support.")
2192 (group :sibling-args
(:help-echo
"\
2193 Only match frames with the specified intensity.")
2195 Background brightness: "
2197 (checklist :inline t
2199 (const :format
"Light "
2200 :sibling-args
(:help-echo
"\
2201 Match frames with light backgrounds.")
2203 (const :format
"Dark\n"
2204 :sibling-args
(:help-echo
"\
2205 Match frames with dark backgrounds.")
2208 ;;; The `custom-face' Widget.
2210 (defface custom-face-tag-face
'((t (:underline t
)))
2211 "Face used for face tags."
2212 :group
'custom-faces
)
2214 (defcustom custom-face-default-form
'selected
2215 "Default form of displaying face definition."
2216 :type
'(choice (const all
)
2219 :group
'custom-buffer
)
2221 (define-widget 'custom-face
'custom
2223 :sample-face
'custom-face-tag-face
2224 :help-echo
"Set or reset this face."
2225 :documentation-property
'(lambda (face)
2226 (face-doc-string face
))
2227 :value-create
'custom-face-value-create
2228 :action
'custom-face-action
2229 :custom-category
'face
2230 :custom-form nil
; defaults to value of `custom-face-default-form'
2231 :custom-set
'custom-face-set
2232 :custom-save
'custom-face-save
2233 :custom-reset-current
'custom-redraw
2234 :custom-reset-saved
'custom-face-reset-saved
2235 :custom-reset-standard
'custom-face-reset-standard
2236 :custom-menu
'custom-face-menu-create
)
2238 (define-widget 'custom-face-all
'editable-list
2239 "An editable list of display specifications and attributes."
2240 :entry-format
"%i %d %v"
2241 :insert-button-args
'(:help-echo
"Insert new display specification here.")
2242 :append-button-args
'(:help-echo
"Append new display specification here.")
2243 :delete-button-args
'(:help-echo
"Delete this display specification.")
2244 :args
'((group :format
"%v" custom-display custom-face-edit
)))
2246 (defconst custom-face-all
(widget-convert 'custom-face-all
)
2247 "Converted version of the `custom-face-all' widget.")
2249 (define-widget 'custom-display-unselected
'item
2250 "A display specification that doesn't match the selected display."
2251 :match
'custom-display-unselected-match
)
2253 (defun custom-display-unselected-match (widget value
)
2254 "Non-nil if VALUE is an unselected display specification."
2255 (not (face-spec-set-match-display value
(selected-frame))))
2257 (define-widget 'custom-face-selected
'group
2258 "Edit the attributes of the selected display in a face specification."
2259 :args
'((repeat :format
""
2261 (group custom-display-unselected sexp
))
2262 (group (sexp :format
"") custom-face-edit
)
2267 (defconst custom-face-selected
(widget-convert 'custom-face-selected
)
2268 "Converted version of the `custom-face-selected' widget.")
2270 (defun custom-face-value-create (widget)
2271 "Create a list of the display specifications for WIDGET."
2272 (let ((buttons (widget-get widget
:buttons
))
2273 (symbol (widget-get widget
:value
))
2274 (tag (widget-get widget
:tag
))
2275 (state (widget-get widget
:custom-state
))
2277 (is-last (widget-get widget
:custom-last
))
2278 (prefix (widget-get widget
:custom-prefix
)))
2280 (setq tag
(prin1-to-string symbol
)))
2281 (cond ((eq custom-buffer-style
'tree
)
2282 (insert prefix
(if is-last
" `--- " " |--- "))
2283 (push (widget-create-child-and-convert
2284 widget
'custom-browse-face-tag
)
2286 (insert " " tag
"\n")
2287 (widget-put widget
:buttons buttons
))
2291 (if (eq custom-buffer-style
'face
)
2293 (widget-specify-sample widget begin
(point))
2296 (and (string-match "XEmacs" emacs-version
)
2297 ;; XEmacs cannot display uninitialized faces.
2298 (not (custom-facep symbol
))
2299 (copy-face 'custom-face-empty symbol
))
2300 (push (widget-create-child-and-convert widget
'item
2307 (push (widget-create-child-and-convert
2309 :help-echo
"Hide or show this face."
2310 :action
'custom-toggle-parent
2311 (not (eq state
'hidden
)))
2315 (let ((magic (widget-create-child-and-convert
2316 widget
'custom-magic nil
)))
2317 (widget-put widget
:custom-magic magic
)
2318 (push magic buttons
))
2320 (widget-put widget
:buttons buttons
)
2321 ;; Insert documentation.
2322 (widget-default-format-handler widget ?h
)
2324 (unless (eq state
'hidden
)
2325 (when (eq (widget-get widget
:custom-level
) 1)
2326 (custom-add-parent-links widget
))
2327 (custom-add-see-also widget
))
2329 (unless (eq (preceding-char) ?
\n)
2331 (unless (eq state
'hidden
)
2332 (message "Creating face editor...")
2333 (custom-load-widget widget
)
2334 (unless (widget-get widget
:custom-form
)
2335 (widget-put widget
:custom-form custom-face-default-form
))
2336 (let* ((symbol (widget-value widget
))
2337 (spec (or (get symbol
'saved-face
)
2338 (get symbol
'face-defface-spec
)
2339 ;; Attempt to construct it.
2340 (list (list t
(custom-face-attributes-get
2341 symbol
(selected-frame))))))
2342 (form (widget-get widget
:custom-form
))
2343 (indent (widget-get widget
:indent
))
2345 ;; If the user has changed this face in some other way,
2346 ;; edit it as the user has specified it.
2347 (if (not (face-spec-match-p symbol spec
(selected-frame)))
2348 (setq spec
(list (list t
(face-attr-construct symbol
(selected-frame))))))
2349 (setq edit
(widget-create-child-and-convert
2351 (cond ((and (eq form
'selected
)
2352 (widget-apply custom-face-selected
2354 (when indent
(insert-char ?\ indent
))
2355 'custom-face-selected
)
2356 ((and (not (eq form
'lisp
))
2357 (widget-apply custom-face-all
2361 (when indent
(insert-char ?\ indent
))
2364 (custom-face-state-set widget
)
2365 (widget-put widget
:children
(list edit
)))
2366 (message "Creating face editor...done"))))))
2368 (defvar custom-face-menu
2369 '(("Set for Current Session" custom-face-set
)
2370 ("Save for Future Sessions" custom-face-save-command
)
2371 ("Reset to Saved" custom-face-reset-saved
2373 (get (widget-value widget
) 'saved-face
)))
2374 ("Reset to Standard Setting" custom-face-reset-standard
2376 (get (widget-value widget
) 'face-defface-spec
)))
2377 ("---" ignore ignore
)
2378 ("Show all display specs" custom-face-edit-all
2380 (not (eq (widget-get widget
:custom-form
) 'all
))))
2381 ("Just current attributes" custom-face-edit-selected
2383 (not (eq (widget-get widget
:custom-form
) 'selected
))))
2384 ("Show as Lisp expression" custom-face-edit-lisp
2386 (not (eq (widget-get widget
:custom-form
) 'lisp
)))))
2387 "Alist of actions for the `custom-face' widget.
2388 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2389 the menu entry, ACTION is the function to call on the widget when the
2390 menu is selected, and FILTER is a predicate which takes a `custom-face'
2391 widget as an argument, and returns non-nil if ACTION is valid on that
2392 widget. If FILTER is nil, ACTION is always valid.")
2394 (defun custom-face-edit-selected (widget)
2395 "Edit selected attributes of the value of WIDGET."
2396 (widget-put widget
:custom-state
'unknown
)
2397 (widget-put widget
:custom-form
'selected
)
2398 (custom-redraw widget
))
2400 (defun custom-face-edit-all (widget)
2401 "Edit all attributes of the value of WIDGET."
2402 (widget-put widget
:custom-state
'unknown
)
2403 (widget-put widget
:custom-form
'all
)
2404 (custom-redraw widget
))
2406 (defun custom-face-edit-lisp (widget)
2407 "Edit the lisp representation of the value of WIDGET."
2408 (widget-put widget
:custom-state
'unknown
)
2409 (widget-put widget
:custom-form
'lisp
)
2410 (custom-redraw widget
))
2412 (defun custom-face-state-set (widget)
2413 "Set the state of WIDGET."
2414 (let ((symbol (widget-value widget
)))
2415 (widget-put widget
:custom-state
(cond ((get symbol
'customized-face
)
2417 ((get symbol
'saved-face
)
2419 ((get symbol
'face-defface-spec
)
2424 (defun custom-face-action (widget &optional event
)
2425 "Show the menu for `custom-face' WIDGET.
2426 Optional EVENT is the location for the menu."
2427 (if (eq (widget-get widget
:custom-state
) 'hidden
)
2428 (custom-toggle-hide widget
)
2429 (let* ((completion-ignore-case t
)
2430 (symbol (widget-get widget
:value
))
2431 (answer (widget-choose (concat "Operation on "
2432 (custom-unlispify-tag-name symbol
))
2433 (custom-menu-filter custom-face-menu
2437 (funcall answer widget
)))))
2439 (defun custom-face-set (widget)
2440 "Make the face attributes in WIDGET take effect."
2441 (let* ((symbol (widget-value widget
))
2442 (child (car (widget-get widget
:children
)))
2443 (value (widget-value child
)))
2444 (put symbol
'customized-face value
)
2445 (face-spec-set symbol value
)
2446 (custom-face-state-set widget
)
2447 (custom-redraw-magic widget
)))
2449 (defun custom-face-save-command (widget)
2450 "Save in `.emacs' the face attributes in WIDGET."
2451 (custom-face-save widget
)
2454 (defun custom-face-save (widget)
2455 "Prepare for saving WIDGET's face attributes, but don't write `.emacs'."
2456 (let* ((symbol (widget-value widget
))
2457 (child (car (widget-get widget
:children
)))
2458 (value (widget-value child
)))
2459 (face-spec-set symbol value
)
2460 (put symbol
'saved-face value
)
2461 (put symbol
'customized-face nil
)
2463 (custom-face-state-set widget
)
2464 (custom-redraw-magic widget
)))
2466 (defun custom-face-reset-saved (widget)
2467 "Restore WIDGET to the face's default attributes."
2468 (let* ((symbol (widget-value widget
))
2469 (child (car (widget-get widget
:children
)))
2470 (value (get symbol
'saved-face
)))
2472 (error "No saved value for this face"))
2473 (put symbol
'customized-face nil
)
2474 (face-spec-set symbol value
)
2475 (widget-value-set child value
)
2476 (custom-face-state-set widget
)
2477 (custom-redraw-magic widget
)))
2479 (defun custom-face-reset-standard (widget)
2480 "Restore WIDGET to the face's standard settings."
2481 (let* ((symbol (widget-value widget
))
2482 (child (car (widget-get widget
:children
)))
2483 (value (get symbol
'face-defface-spec
)))
2485 (error "No standard setting for this face"))
2486 (put symbol
'customized-face nil
)
2487 (when (get symbol
'saved-face
)
2488 (put symbol
'saved-face nil
)
2490 (face-spec-set symbol value
)
2491 (widget-value-set child value
)
2492 (custom-face-state-set widget
)
2493 (custom-redraw-magic widget
)))
2495 ;;; The `face' Widget.
2497 (define-widget 'face
'default
2498 "Select and customize a face."
2499 :convert-widget
'widget-value-convert-widget
2500 :button-prefix
'widget-push-button-prefix
2501 :button-suffix
'widget-push-button-suffix
2502 :format
"%t: %[select face%] %v"
2505 :value-create
'widget-face-value-create
2506 :value-delete
'widget-face-value-delete
2507 :value-get
'widget-value-value-get
2508 :validate
'widget-children-validate
2509 :action
'widget-face-action
2510 :match
'(lambda (widget value
) (symbolp value
)))
2512 (defun widget-face-value-create (widget)
2513 ;; Create a `custom-face' child.
2514 (let* ((symbol (widget-value widget
))
2515 (custom-buffer-style 'face
)
2516 (child (widget-create-child-and-convert
2520 (custom-magic-reset child
)
2521 (setq custom-options
(cons child custom-options
))
2522 (widget-put widget
:children
(list child
))))
2524 (defun widget-face-value-delete (widget)
2525 ;; Remove the child from the options.
2526 (let ((child (car (widget-get widget
:children
))))
2527 (setq custom-options
(delq child custom-options
))
2528 (widget-children-value-delete widget
)))
2530 (defvar face-history nil
2531 "History of entered face names.")
2533 (defun widget-face-action (widget &optional event
)
2534 "Prompt for a face."
2535 (let ((answer (completing-read "Face: "
2536 (mapcar (lambda (face)
2537 (list (symbol-name face
)))
2541 (unless (zerop (length answer
))
2542 (widget-value-set widget
(intern answer
))
2543 (widget-apply widget
:notify widget event
)
2546 ;;; The `hook' Widget.
2548 (define-widget 'hook
'list
2550 :value-to-internal
(lambda (widget value
)
2551 (if (and value
(symbolp value
))
2554 :match
(lambda (widget value
)
2556 (widget-group-match widget value
)))
2557 :convert-widget
'custom-hook-convert-widget
2560 (defun custom-hook-convert-widget (widget)
2561 ;; Handle `:custom-options'.
2562 (let* ((options (widget-get widget
:options
))
2563 (other `(editable-list :inline t
2564 :entry-format
"%i %d%v"
2565 (function :format
" %v")))
2567 (list `(checklist :inline t
2568 ,@(mapcar (lambda (entry)
2569 `(function-item ,entry
))
2573 (widget-put widget
:args args
)
2576 ;;; The `custom-group-link' Widget.
2578 (define-widget 'custom-group-link
'link
2579 "Show parent in other window when activated."
2580 :help-echo
"Create customization buffer for this group."
2581 :action
'custom-group-link-action
)
2583 (defun custom-group-link-action (widget &rest ignore
)
2584 (customize-group (widget-value widget
)))
2586 ;;; The `custom-group' Widget.
2588 (defcustom custom-group-tag-faces nil
2589 ;; In XEmacs, this ought to play games with font size.
2590 "Face used for group tags.
2591 The first member is used for level 1 groups, the second for level 2,
2592 and so forth. The remaining group tags are shown with
2593 `custom-group-tag-face'."
2594 :type
'(repeat face
)
2595 :group
'custom-faces
)
2597 (defface custom-group-tag-face-1
'((((class color
)
2599 (:foreground
"pink" :underline t
))
2602 (:foreground
"red" :underline t
))
2604 "Face used for group tags.")
2606 (defface custom-group-tag-face
'((((class color
)
2608 (:foreground
"light blue" :underline t
))
2611 (:foreground
"blue" :underline t
))
2613 "Face used for low level group tags."
2614 :group
'custom-faces
)
2616 (define-widget 'custom-group
'custom
2619 :sample-face-get
'custom-group-sample-face-get
2620 :documentation-property
'group-documentation
2621 :help-echo
"Set or reset all members of this group."
2622 :value-create
'custom-group-value-create
2623 :action
'custom-group-action
2624 :custom-category
'group
2625 :custom-set
'custom-group-set
2626 :custom-save
'custom-group-save
2627 :custom-reset-current
'custom-group-reset-current
2628 :custom-reset-saved
'custom-group-reset-saved
2629 :custom-reset-standard
'custom-group-reset-standard
2630 :custom-menu
'custom-group-menu-create
)
2632 (defun custom-group-sample-face-get (widget)
2633 ;; Use :sample-face.
2634 (or (nth (1- (widget-get widget
:custom-level
)) custom-group-tag-faces
)
2635 'custom-group-tag-face
))
2637 (define-widget 'custom-group-visibility
'visibility
2638 "An indicator and manipulator for hidden group contents."
2639 :create
'custom-group-visibility-create
)
2641 (defun custom-group-visibility-create (widget)
2642 (let ((visible (widget-value widget
)))
2644 (insert "--------")))
2645 (widget-default-create widget
))
2647 (defun custom-group-members (symbol groups-only
)
2648 "Return SYMBOL's custom group members.
2649 If GROUPS-ONLY non-nil, return only those members that are groups."
2650 (if (not groups-only
)
2651 (get symbol
'custom-group
)
2653 (dolist (entry (get symbol
'custom-group
))
2654 (when (eq (nth 1 entry
) 'custom-group
)
2655 (push entry members
)))
2656 (nreverse members
))))
2658 (defun custom-group-value-create (widget)
2659 "Insert a customize group for WIDGET in the current buffer."
2660 (let* ((state (widget-get widget
:custom-state
))
2661 (level (widget-get widget
:custom-level
))
2662 ;; (indent (widget-get widget :indent))
2663 (prefix (widget-get widget
:custom-prefix
))
2664 (buttons (widget-get widget
:buttons
))
2665 (tag (widget-get widget
:tag
))
2666 (symbol (widget-value widget
))
2667 (members (custom-group-members symbol
2668 (and (eq custom-buffer-style
'tree
)
2669 custom-browse-only-groups
))))
2670 (cond ((and (eq custom-buffer-style
'tree
)
2672 (or members
(custom-unloaded-widget-p widget
)))
2673 (custom-browse-insert-prefix prefix
)
2674 (push (widget-create-child-and-convert
2675 widget
'custom-browse-visibility
2676 ;; :tag-glyph "plus"
2680 ;; (widget-glyph-insert nil "-- " "horizontal")
2681 (push (widget-create-child-and-convert
2682 widget
'custom-browse-group-tag
)
2684 (insert " " tag
"\n")
2685 (widget-put widget
:buttons buttons
))
2686 ((and (eq custom-buffer-style
'tree
)
2687 (zerop (length members
)))
2688 (custom-browse-insert-prefix prefix
)
2690 ;; (widget-glyph-insert nil "[ ]" "empty")
2691 ;; (widget-glyph-insert nil "-- " "horizontal")
2692 (push (widget-create-child-and-convert
2693 widget
'custom-browse-group-tag
)
2695 (insert " " tag
"\n")
2696 (widget-put widget
:buttons buttons
))
2697 ((eq custom-buffer-style
'tree
)
2698 (custom-browse-insert-prefix prefix
)
2699 (custom-load-widget widget
)
2700 (if (zerop (length members
))
2702 (custom-browse-insert-prefix prefix
)
2704 ;; (widget-glyph-insert nil "[ ]" "empty")
2705 ;; (widget-glyph-insert nil "-- " "horizontal")
2706 (push (widget-create-child-and-convert
2707 widget
'custom-browse-group-tag
)
2709 (insert " " tag
"\n")
2710 (widget-put widget
:buttons buttons
))
2711 (push (widget-create-child-and-convert
2712 widget
'custom-browse-visibility
2713 ;; :tag-glyph "minus"
2717 ;; (widget-glyph-insert nil "-\\ " "top")
2718 (push (widget-create-child-and-convert
2719 widget
'custom-browse-group-tag
)
2721 (insert " " tag
"\n")
2722 (widget-put widget
:buttons buttons
)
2723 (message "Creating group...")
2724 (let* ((members (custom-sort-items members
2725 custom-browse-sort-alphabetically
2726 custom-browse-order-groups
))
2727 (prefixes (widget-get widget
:custom-prefixes
))
2728 (custom-prefix-list (custom-prefix-add symbol prefixes
))
2729 (extra-prefix (if (widget-get widget
:custom-last
)
2732 (prefix (concat prefix extra-prefix
))
2735 (setq entry
(car members
)
2736 members
(cdr members
))
2737 (push (widget-create-child-and-convert
2738 widget
(nth 1 entry
)
2740 :tag
(custom-unlispify-tag-name (nth 0 entry
))
2741 :custom-prefixes custom-prefix-list
2742 :custom-level
(1+ level
)
2743 :custom-last
(null members
)
2744 :value
(nth 0 entry
)
2745 :custom-prefix prefix
)
2747 (widget-put widget
:children
(reverse children
)))
2748 (message "Creating group...done")))
2751 ;; Create level indicator.
2752 (unless (eq custom-buffer-style
'links
)
2753 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
2756 (let ((begin (point)))
2758 (widget-specify-sample widget begin
(point)))
2760 ;; Create link/visibility indicator.
2761 (if (eq custom-buffer-style
'links
)
2762 (push (widget-create-child-and-convert
2763 widget
'custom-group-link
2767 (push (widget-create-child-and-convert
2768 widget
'custom-group-visibility
2769 :help-echo
"Show members of this group."
2770 :action
'custom-toggle-parent
2771 (not (eq state
'hidden
)))
2774 ;; Create magic button.
2775 (let ((magic (widget-create-child-and-convert
2776 widget
'custom-magic nil
)))
2777 (widget-put widget
:custom-magic magic
)
2778 (push magic buttons
))
2780 (widget-put widget
:buttons buttons
)
2781 ;; Insert documentation.
2782 (if (and (eq custom-buffer-style
'links
) (> level
1))
2783 (widget-put widget
:documentation-indent
0))
2784 (widget-default-format-handler widget ?h
))
2787 ;; Add parent groups references above the group.
2788 (if t
;;; This should test that the buffer
2789 ;;; was made to display a group.
2791 (if (custom-add-parent-links widget
2792 "Go to parent group:")
2794 ;; Create level indicator.
2795 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
2798 (let ((start (point)))
2800 (widget-specify-sample widget start
(point)))
2802 ;; Create visibility indicator.
2803 (unless (eq custom-buffer-style
'links
)
2805 (push (widget-create-child-and-convert
2807 :help-echo
"Hide members of this group."
2808 :action
'custom-toggle-parent
2809 (not (eq state
'hidden
)))
2812 ;; Create more dashes.
2813 ;; Use 76 instead of 75 to compensate for the temporary "<"
2814 ;; added by `widget-insert'.
2815 (insert-char ?-
(- 76 (current-column)
2816 (* custom-buffer-indent level
)))
2818 ;; Create magic button.
2819 (let ((magic (widget-create-child-and-convert
2820 widget
'custom-magic
2823 (widget-put widget
:custom-magic magic
)
2824 (push magic buttons
))
2826 (widget-put widget
:buttons buttons
)
2827 ;; Insert documentation.
2828 (widget-default-format-handler widget ?h
)
2830 (if nil
;;; This should test that the buffer
2831 ;;; was not made to display a group.
2833 (insert-char ?\ custom-buffer-indent
)
2834 (custom-add-parent-links widget
)))
2835 (custom-add-see-also widget
2836 (make-string (* custom-buffer-indent level
)
2839 (message "Creating group...")
2840 (custom-load-widget widget
)
2841 (let* ((members (custom-sort-items members
2842 custom-buffer-sort-alphabetically
2843 custom-buffer-order-groups
))
2844 (prefixes (widget-get widget
:custom-prefixes
))
2845 (custom-prefix-list (custom-prefix-add symbol prefixes
))
2846 (length (length members
))
2848 (children (mapcar (lambda (entry)
2849 (widget-insert "\n")
2851 Creating group members... %2d%%"
2852 (/ (* 100.0 count
) length
))
2853 (setq count
(1+ count
))
2855 (widget-create-child-and-convert
2856 widget
(nth 1 entry
)
2858 :tag
(custom-unlispify-tag-name
2860 :custom-prefixes custom-prefix-list
2861 :custom-level
(1+ level
)
2862 :value
(nth 0 entry
))
2863 (unless (eq (preceding-char) ?
\n)
2864 (widget-insert "\n"))))
2866 (message "Creating group magic...")
2867 (mapcar 'custom-magic-reset children
)
2868 (message "Creating group state...")
2869 (widget-put widget
:children children
)
2870 (custom-group-state-update widget
)
2871 (message "Creating group... done"))
2874 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
2875 (insert "\\- " (widget-get widget
:tag
) " group end ")
2876 (insert-char ?-
(- 75 (current-column) (* custom-buffer-indent level
)))
2879 (defvar custom-group-menu
2880 '(("Set for Current Session" custom-group-set
2882 (eq (widget-get widget
:custom-state
) 'modified
)))
2883 ("Save for Future Sessions" custom-group-save
2885 (memq (widget-get widget
:custom-state
) '(modified set
))))
2886 ("Reset to Current" custom-group-reset-current
2888 (memq (widget-get widget
:custom-state
) '(modified))))
2889 ("Reset to Saved" custom-group-reset-saved
2891 (memq (widget-get widget
:custom-state
) '(modified set
))))
2892 ("Reset to standard setting" custom-group-reset-standard
2894 (memq (widget-get widget
:custom-state
) '(modified set saved
)))))
2895 "Alist of actions for the `custom-group' widget.
2896 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2897 the menu entry, ACTION is the function to call on the widget when the
2898 menu is selected, and FILTER is a predicate which takes a `custom-group'
2899 widget as an argument, and returns non-nil if ACTION is valid on that
2900 widget. If FILTER is nil, ACTION is always valid.")
2902 (defun custom-group-action (widget &optional event
)
2903 "Show the menu for `custom-group' WIDGET.
2904 Optional EVENT is the location for the menu."
2905 (if (eq (widget-get widget
:custom-state
) 'hidden
)
2906 (custom-toggle-hide widget
)
2907 (let* ((completion-ignore-case t
)
2908 (answer (widget-choose (concat "Operation on "
2909 (custom-unlispify-tag-name
2910 (widget-get widget
:value
)))
2911 (custom-menu-filter custom-group-menu
2915 (funcall answer widget
)))))
2917 (defun custom-group-set (widget)
2918 "Set changes in all modified group members."
2919 (let ((children (widget-get widget
:children
)))
2920 (mapcar (lambda (child)
2921 (when (eq (widget-get child
:custom-state
) 'modified
)
2922 (widget-apply child
:custom-set
)))
2925 (defun custom-group-save (widget)
2926 "Save all modified group members."
2927 (let ((children (widget-get widget
:children
)))
2928 (mapcar (lambda (child)
2929 (when (memq (widget-get child
:custom-state
) '(modified set
))
2930 (widget-apply child
:custom-save
)))
2933 (defun custom-group-reset-current (widget)
2934 "Reset all modified group members."
2935 (let ((children (widget-get widget
:children
)))
2936 (mapcar (lambda (child)
2937 (when (eq (widget-get child
:custom-state
) 'modified
)
2938 (widget-apply child
:custom-reset-current
)))
2941 (defun custom-group-reset-saved (widget)
2942 "Reset all modified or set group members."
2943 (let ((children (widget-get widget
:children
)))
2944 (mapcar (lambda (child)
2945 (when (memq (widget-get child
:custom-state
) '(modified set
))
2946 (widget-apply child
:custom-reset-saved
)))
2949 (defun custom-group-reset-standard (widget)
2950 "Reset all modified, set, or saved group members."
2951 (let ((children (widget-get widget
:children
)))
2952 (mapcar (lambda (child)
2953 (when (memq (widget-get child
:custom-state
)
2954 '(modified set saved
))
2955 (widget-apply child
:custom-reset-standard
)))
2958 (defun custom-group-state-update (widget)
2960 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
2961 (let* ((children (widget-get widget
:children
))
2962 (states (mapcar (lambda (child)
2963 (widget-get child
:custom-state
))
2965 (magics custom-magic-alist
)
2968 (let ((magic (car (car magics
))))
2969 (if (and (not (eq magic
'hidden
))
2970 (memq magic states
))
2973 (setq magics
(cdr magics
)))))
2974 (widget-put widget
:custom-state found
)))
2975 (custom-magic-reset widget
))
2977 ;;; The `custom-save-all' Function.
2979 (defcustom custom-file nil
2980 "File used for storing customization information.
2981 The default is nil, which means to use your init file
2982 as specified by `user-init-file'. If you specify some other file,
2983 you need to explicitly load that file for the settings to take effect."
2984 :type
'(choice (const :tag
"Your Emacs init file" nil
) file
)
2987 (defun custom-save-delete (symbol)
2988 "Delete the call to SYMBOL from `custom-file'.
2989 Leave point at the location of the call, or after the last expression."
2990 (let ((default-major-mode))
2991 (set-buffer (find-file-noselect (or custom-file user-init-file
))))
2992 (goto-char (point-min))
2995 (let ((sexp (condition-case nil
2996 (read (current-buffer))
2997 (end-of-file (throw 'found nil
)))))
2998 (when (and (listp sexp
)
2999 (eq (car sexp
) symbol
))
3000 (delete-region (save-excursion
3004 (throw 'found nil
))))))
3006 (defun custom-save-variables ()
3007 "Save all customized variables in `custom-file'."
3009 (custom-save-delete 'custom-set-variables
)
3010 (let ((standard-output (current-buffer)))
3013 (princ "(custom-set-variables")
3014 (mapatoms (lambda (symbol)
3015 (let ((value (get symbol
'saved-value
))
3016 (requests (get symbol
'custom-requests
))
3017 (now (not (or (get symbol
'standard-value
)
3018 (and (not (boundp symbol
))
3019 (not (get symbol
'force-value
)))))))
3036 (unless (looking-at "\n")
3039 (defun custom-save-faces ()
3040 "Save all customized faces in `custom-file'."
3042 (custom-save-delete 'custom-set-faces
)
3043 (let ((standard-output (current-buffer)))
3046 (princ "(custom-set-faces")
3047 (let ((value (get 'default
'saved-face
)))
3048 ;; The default face must be first, since it affects the others.
3050 (princ "\n '(default ")
3052 (if (or (get 'default
'face-defface-spec
)
3053 (and (not (custom-facep 'default
))
3054 (not (get 'default
'force-face
))))
3057 (mapatoms (lambda (symbol)
3058 (let ((value (get symbol
'saved-face
)))
3059 (when (and (not (eq symbol
'default
))
3060 ;; Don't print default face here.
3066 (if (or (get symbol
'face-defface-spec
)
3067 (and (not (custom-facep symbol
))
3068 (not (get symbol
'force-face
))))
3072 (unless (looking-at "\n")
3076 (defun customize-save-customized ()
3077 "Save all user options which have been set in this session."
3079 (mapatoms (lambda (symbol)
3080 (let ((face (get symbol
'customized-face
))
3081 (value (get symbol
'customized-value
)))
3083 (put symbol
'saved-face face
)
3084 (put symbol
'customized-face nil
))
3086 (put symbol
'saved-value value
)
3087 (put symbol
'customized-value nil
)))))
3088 ;; We really should update all custom buffers here.
3092 (defun custom-save-all ()
3093 "Save all customizations in `custom-file'."
3094 (let ((inhibit-read-only t
))
3095 (custom-save-variables)
3098 (let ((default-major-mode nil
))
3099 (set-buffer (find-file-noselect (or custom-file user-init-file
))))
3102 ;;; The Customize Menu.
3106 (defcustom custom-menu-nesting
2
3107 "Maximum nesting in custom menus."
3109 :group
'custom-menu
)
3111 (defun custom-face-menu-create (widget symbol
)
3112 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
3113 (vector (custom-unlispify-menu-entry symbol
)
3114 `(customize-face ',symbol
)
3117 (defun custom-variable-menu-create (widget symbol
)
3118 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
3119 (let ((type (get symbol
'custom-type
)))
3120 (unless (listp type
)
3121 (setq type
(list type
)))
3122 (if (and type
(widget-get type
:custom-menu
))
3123 (widget-apply type
:custom-menu symbol
)
3124 (vector (custom-unlispify-menu-entry symbol
)
3125 `(customize-variable ',symbol
)
3128 ;; Add checkboxes to boolean variable entries.
3129 (widget-put (get 'boolean
'widget-type
)
3130 :custom-menu
(lambda (widget symbol
)
3131 (vector (custom-unlispify-menu-entry symbol
)
3132 `(customize-variable ',symbol
)
3134 ':selected symbol
)))
3136 (if (string-match "XEmacs" emacs-version
)
3137 ;; XEmacs can create menus dynamically.
3138 (defun custom-group-menu-create (widget symbol
)
3139 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
3140 `( ,(custom-unlispify-menu-entry symbol t
)
3141 :filter
(lambda (&rest junk
)
3142 (cdr (custom-menu-create ',symbol
)))))
3144 (defun custom-group-menu-create (widget symbol
)
3145 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
3146 ;; Limit the nesting.
3147 (let ((custom-menu-nesting (1- custom-menu-nesting
)))
3148 (custom-menu-create symbol
))))
3151 (defun custom-menu-create (symbol)
3152 "Create menu for customization group SYMBOL.
3153 The menu is in a format applicable to `easy-menu-define'."
3154 (let* ((item (vector (custom-unlispify-menu-entry symbol
)
3155 `(customize-group ',symbol
)
3157 (if (and (or (not (boundp 'custom-menu-nesting
))
3158 (>= custom-menu-nesting
0))
3159 (< (length (get symbol
'custom-group
)) widget-menu-max-size
))
3160 (let ((custom-prefix-list (custom-prefix-add symbol
3161 custom-prefix-list
))
3162 (members (custom-sort-items (get symbol
'custom-group
)
3163 custom-menu-sort-alphabetically
3164 custom-menu-order-groups
)))
3165 (custom-load-symbol symbol
)
3166 `(,(custom-unlispify-menu-entry symbol t
)
3169 ,@(mapcar (lambda (entry)
3170 (widget-apply (if (listp (nth 1 entry
))
3172 (list (nth 1 entry
)))
3173 :custom-menu
(nth 0 entry
)))
3178 (defun customize-menu-create (symbol &optional name
)
3179 "Return a customize menu for customization group SYMBOL.
3180 If optional NAME is given, use that as the name of the menu.
3181 Otherwise the menu will be named `Customize'.
3182 The format is suitable for use with `easy-menu-define'."
3184 (setq name
"Customize"))
3185 (if (string-match "XEmacs" emacs-version
)
3186 ;; We can delay it under XEmacs.
3188 :filter
(lambda (&rest junk
)
3189 (cdr (custom-menu-create ',symbol
))))
3190 ;; But we must create it now under Emacs.
3191 (cons name
(cdr (custom-menu-create symbol
)))))
3193 ;;; The Custom Mode.
3195 (defvar custom-mode-map nil
3196 "Keymap for `custom-mode'.")
3198 (unless custom-mode-map
3199 (setq custom-mode-map
(make-sparse-keymap))
3200 (set-keymap-parent custom-mode-map widget-keymap
)
3201 (suppress-keymap custom-mode-map
)
3202 (define-key custom-mode-map
" " 'scroll-up
)
3203 (define-key custom-mode-map
"\177" 'scroll-down
)
3204 (define-key custom-mode-map
"q" 'bury-buffer
)
3205 (define-key custom-mode-map
"u" 'Custom-goto-parent
)
3206 (define-key custom-mode-map
"n" 'widget-forward
)
3207 (define-key custom-mode-map
"p" 'widget-backward
)
3208 (define-key custom-mode-map
[mouse-1
] 'Custom-move-and-invoke
))
3210 (defun Custom-move-and-invoke (event)
3211 "Move to where you click, and if it is an active field, invoke it."
3213 (mouse-set-point event
)
3214 (if (widget-event-point event
)
3215 (let* ((pos (widget-event-point event
))
3216 (button (get-char-property pos
'button
)))
3218 (widget-button-click event
)))))
3220 (easy-menu-define Custom-mode-menu
3222 "Menu used in customization buffers."
3224 ,(customize-menu-create 'customize
)
3225 ["Set" Custom-set t
]
3226 ["Save" Custom-save t
]
3227 ["Reset to Current" Custom-reset-current t
]
3228 ["Reset to Saved" Custom-reset-saved t
]
3229 ["Reset to Standard Settings" Custom-reset-standard t
]
3230 ["Info" (Info-goto-node "(custom)The Customization Buffer") t
]))
3232 (defun Custom-goto-parent ()
3233 "Go to the parent group listed at the top of this buffer.
3234 If several parents are listed, go to the first of them."
3237 (goto-char (point-min))
3238 (if (search-forward "\nGo to parent group: " nil t
)
3239 (let* ((button (get-char-property (point) 'button
))
3240 (parent (downcase (widget-get button
:tag
))))
3241 (customize-group parent
)))))
3243 (defcustom custom-mode-hook nil
3244 "Hook called when entering custom-mode."
3246 :group
'custom-buffer
)
3248 (defun custom-state-buffer-message (widget)
3249 (if (eq (widget-get (widget-get widget
:parent
) :custom-state
) 'modified
)
3250 (message "To install your edits, invoke [State] and choose the Set operation")))
3252 (defun custom-mode ()
3253 "Major mode for editing customization buffers.
3255 The following commands are available:
3257 Move to next button or editable field. \\[widget-forward]
3258 Move to previous button or editable field. \\[widget-backward]
3259 \\<widget-field-keymap>\
3260 Complete content of editable text field. \\[widget-complete]
3261 \\<custom-mode-map>\
3262 Invoke button under the mouse pointer. \\[Custom-move-and-invoke]
3263 Invoke button under point. \\[widget-button-press]
3264 Set all modifications. \\[Custom-set]
3265 Make all modifications default. \\[Custom-save]
3266 Reset all modified options. \\[Custom-reset-current]
3267 Reset all modified or set options. \\[Custom-reset-saved]
3268 Reset all options. \\[Custom-reset-standard]
3270 Entry to this mode calls the value of `custom-mode-hook'
3271 if that value is non-nil."
3272 (kill-all-local-variables)
3273 (setq major-mode
'custom-mode
3275 (use-local-map custom-mode-map
)
3276 (easy-menu-add Custom-mode-menu
)
3277 (make-local-variable 'custom-options
)
3278 (make-local-variable 'widget-documentation-face
)
3279 (setq widget-documentation-face
'custom-documentation-face
)
3280 (make-local-variable 'widget-button-face
)
3281 (setq widget-button-face
'custom-button-face
)
3282 (make-local-hook 'widget-edit-functions
)
3283 (add-hook 'widget-edit-functions
'custom-state-buffer-message nil t
)
3284 (run-hooks 'custom-mode-hook
))
3290 ;; cus-edit.el ends here