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
))))))
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 (get symbol
'custom-group
))
815 (when (stringp group
)
816 (if (string-equal "" group
)
818 (setq group
(intern group
))))
819 (let ((name (format "*Customize Group: %s*"
820 (custom-unlispify-tag-name group
))))
821 (if (get-buffer name
)
822 (switch-to-buffer name
)
823 (custom-buffer-create (list (list group
'custom-group
))
825 (concat " for group "
826 (custom-unlispify-tag-name group
))))))
829 (defun customize-group-other-window (symbol)
830 "Customize SYMBOL, which must be a customization group."
831 (interactive (list (completing-read "Customize group: (default emacs) "
834 (get symbol
'custom-group
))
837 (when (stringp symbol
)
838 (if (string-equal "" symbol
)
840 (setq symbol
(intern symbol
))))
841 (custom-buffer-create-other-window
842 (list (list symbol
'custom-group
))
843 (format "*Customize Group: %s*" (custom-unlispify-tag-name symbol
))))
846 (defalias 'customize-variable
'customize-option
)
849 (defun customize-option (symbol)
850 "Customize SYMBOL, which must be a user option variable."
851 (interactive (custom-variable-prompt))
852 (custom-buffer-create (list (list symbol
'custom-variable
))
853 (format "*Customize Option: %s*"
854 (custom-unlispify-tag-name symbol
))))
857 (defalias 'customize-variable-other-window
'customize-option-other-window
)
860 (defun customize-option-other-window (symbol)
861 "Customize SYMBOL, which must be a user option variable.
862 Show the buffer in another window, but don't select it."
863 (interactive (custom-variable-prompt))
864 (custom-buffer-create-other-window
865 (list (list symbol
'custom-variable
))
866 (format "*Customize Option: %s*" (custom-unlispify-tag-name symbol
))))
869 (defun customize-face (&optional symbol
)
870 "Customize SYMBOL, which should be a face name or nil.
871 If SYMBOL is nil, customize all faces."
872 (interactive (list (completing-read "Customize face: (default all) "
873 obarray
'custom-facep
)))
874 (if (or (null symbol
) (and (stringp symbol
) (zerop (length symbol
))))
875 (custom-buffer-create (custom-sort-items
876 (mapcar (lambda (symbol)
877 (list symbol
'custom-face
))
881 (when (stringp symbol
)
882 (setq symbol
(intern symbol
)))
883 (unless (symbolp symbol
)
884 (error "Should be a symbol %S" symbol
))
885 (custom-buffer-create (list (list symbol
'custom-face
))
886 (format "*Customize Face: %s*"
887 (custom-unlispify-tag-name symbol
)))))
890 (defun customize-face-other-window (&optional symbol
)
891 "Show customization buffer for FACE in other window."
892 (interactive (list (completing-read "Customize face: "
893 obarray
'custom-facep
)))
894 (if (or (null symbol
) (and (stringp symbol
) (zerop (length symbol
))))
897 (setq symbol
(intern symbol
)))
898 (unless (symbolp symbol
)
899 (error "Should be a symbol %S" symbol
))
900 (custom-buffer-create-other-window
901 (list (list symbol
'custom-face
))
902 (format "*Customize Face: %s*" (custom-unlispify-tag-name symbol
)))))
905 (defun customize-customized ()
906 "Customize all user options set since the last save in this session."
909 (mapatoms (lambda (symbol)
910 (and (get symbol
'customized-face
)
911 (custom-facep symbol
)
912 (push (list symbol
'custom-face
) found
))
913 (and (get symbol
'customized-value
)
915 (push (list symbol
'custom-variable
) found
))))
917 (error "No customized user options")
918 (custom-buffer-create (custom-sort-items found t nil
)
919 "*Customize Customized*"))))
922 (defun customize-saved ()
923 "Customize all already saved user options."
926 (mapatoms (lambda (symbol)
927 (and (get symbol
'saved-face
)
928 (custom-facep symbol
)
929 (push (list symbol
'custom-face
) found
))
930 (and (get symbol
'saved-value
)
932 (push (list symbol
'custom-variable
) found
))))
934 (error "No saved user options")
935 (custom-buffer-create (custom-sort-items found t nil
)
936 "*Customize Saved*"))))
939 (defun customize-apropos (regexp &optional all
)
940 "Customize all user options matching REGEXP.
941 If ALL is `options', include only options.
942 If ALL is `faces', include only faces.
943 If ALL is `groups', include only groups.
944 If ALL is t (interactively, with prefix arg), include options which are not
945 user-settable, as well as faces and groups."
946 (interactive "sCustomize regexp: \nP")
948 (mapatoms (lambda (symbol)
949 (when (string-match regexp
(symbol-name symbol
))
950 (when (and (not (memq all
'(faces options
)))
951 (get symbol
'custom-group
))
952 (push (list symbol
'custom-group
) found
))
953 (when (and (not (memq all
'(options groups
)))
954 (custom-facep symbol
))
955 (push (list symbol
'custom-face
) found
))
956 (when (and (not (memq all
'(groups faces
)))
958 (or (get symbol
'saved-value
)
959 (get symbol
'standard-value
)
960 (if (memq all
'(nil options
))
961 (user-variable-p symbol
)
962 (get symbol
'variable-documentation
))))
963 (push (list symbol
'custom-variable
) found
)))))
966 (custom-buffer-create (custom-sort-items found t
967 custom-buffer-order-groups
)
968 "*Customize Apropos*"))))
971 (defun customize-apropos-options (regexp &optional arg
)
972 "Customize all user options matching REGEXP.
973 With prefix arg, include options which are not user-settable."
974 (interactive "sCustomize regexp: \nP")
975 (customize-apropos regexp
(or arg
'options
)))
978 (defun customize-apropos-faces (regexp)
979 "Customize all user faces matching REGEXP."
980 (interactive "sCustomize regexp: \n")
981 (customize-apropos regexp
'faces
))
984 (defun customize-apropos-groups (regexp)
985 "Customize all user groups matching REGEXP."
986 (interactive "sCustomize regexp: \n")
987 (customize-apropos regexp
'groups
))
991 (defcustom custom-buffer-style
'links
992 "Control the presentation style for customization buffers.
993 The value should be a symbol, one of:
995 brackets: groups nest within each other with big horizontal brackets.
996 links: groups have links to subgroups."
997 :type
'(radio (const brackets
)
999 :group
'custom-buffer
)
1001 (defcustom custom-buffer-indent
3
1002 "Number of spaces to indent nested groups."
1004 :group
'custom-buffer
)
1007 (defun custom-buffer-create (options &optional name description
)
1008 "Create a buffer containing OPTIONS.
1009 Optional NAME is the name of the buffer.
1010 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1011 SYMBOL is a customization option, and WIDGET is a widget for editing
1013 (unless name
(setq name
"*Customization*"))
1014 (kill-buffer (get-buffer-create name
))
1015 (switch-to-buffer (get-buffer-create name
))
1016 (custom-buffer-create-internal options description
))
1019 (defun custom-buffer-create-other-window (options &optional name description
)
1020 "Create a buffer containing OPTIONS.
1021 Optional NAME is the name of the buffer.
1022 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1023 SYMBOL is a customization option, and WIDGET is a widget for editing
1025 (unless name
(setq name
"*Customization*"))
1026 (kill-buffer (get-buffer-create name
))
1027 (let ((window (selected-window)))
1028 (switch-to-buffer-other-window (get-buffer-create name
))
1029 (custom-buffer-create-internal options description
)
1030 (select-window window
)))
1032 (defcustom custom-reset-button-menu nil
1033 "If non-nil, only show a single reset button in customize buffers.
1034 This button will have a menu with all three reset operations."
1036 :group
'custom-buffer
)
1038 (defun custom-buffer-create-internal (options &optional description
)
1039 (message "Creating customization buffer...")
1041 (widget-insert "This is a customization buffer")
1043 (widget-insert description
))
1045 Square brackets show active fields; type RET or click mouse-1
1046 on an active field to invoke its action. Editing an option value
1047 changes the text in the buffer; invoke the State button and
1048 choose the Set operation to set the option value.
1050 (widget-create 'info-link
1052 :help-echo
"Read the online help."
1053 "(emacs)Easy Customization")
1054 (widget-insert " for more information.\n\n")
1055 (message "Creating customization buttons...")
1056 (widget-insert "Operate on everything in this buffer:\n ")
1057 (widget-create 'push-button
1058 :tag
"Set for Current Session"
1060 Make your editing in this buffer take effect for this session."
1061 :action
(lambda (widget &optional event
)
1064 (widget-create 'push-button
1065 :tag
"Save for Future Sessions"
1067 Make your editing in this buffer take effect for future Emacs sessions."
1068 :action
(lambda (widget &optional event
)
1070 (if custom-reset-button-menu
1073 (widget-create 'push-button
1075 :help-echo
"Show a menu with reset operations."
1076 :mouse-down-action
(lambda (&rest junk
) t
)
1077 :action
(lambda (widget &optional event
)
1078 (custom-reset event
))))
1079 (widget-insert "\n ")
1080 (widget-create 'push-button
1083 Reset all edited text in this buffer to reflect current values."
1084 :action
'Custom-reset-current
)
1086 (widget-create 'push-button
1087 :tag
"Reset to Saved"
1089 Reset all values in this buffer to their saved settings."
1090 :action
'Custom-reset-saved
)
1092 (widget-create 'push-button
1093 :tag
"Reset to Standard"
1095 Reset all values in this buffer to their standard settings."
1096 :action
'Custom-reset-standard
))
1098 (widget-create 'push-button
1100 :help-echo
"Bury the buffer."
1101 :action
(lambda (widget &optional event
)
1103 (widget-insert "\n\n")
1104 (message "Creating customization items...")
1105 (setq custom-options
1106 (if (= (length options
) 1)
1107 (mapcar (lambda (entry)
1108 (widget-create (nth 1 entry
)
1109 :documentation-shown t
1110 :custom-state
'unknown
1111 :tag
(custom-unlispify-tag-name
1113 :value
(nth 0 entry
)))
1116 (length (length options
)))
1117 (mapcar (lambda (entry)
1119 (message "Creating customization items %2d%%..."
1120 (/ (* 100.0 count
) length
))
1121 (widget-create (nth 1 entry
)
1122 :tag
(custom-unlispify-tag-name
1124 :value
(nth 0 entry
))
1125 (setq count
(1+ count
))
1126 (unless (eq (preceding-char) ?
\n)
1127 (widget-insert "\n"))
1128 (widget-insert "\n")))
1130 (unless (eq (preceding-char) ?
\n)
1131 (widget-insert "\n"))
1132 (message "Creating customization items %2d%%...done" 100)
1133 (unless (eq custom-buffer-style
'tree
)
1134 (mapcar 'custom-magic-reset custom-options
))
1135 (message "Creating customization setup...")
1137 (goto-char (point-min))
1138 (message "Creating customization buffer...done"))
1140 ;;; The Tree Browser.
1143 (defun customize-browse (&optional group
)
1144 "Create a tree browser for the customize hierarchy."
1147 (setq group
'emacs
))
1148 (let ((name "*Customize Browser*"))
1149 (kill-buffer (get-buffer-create name
))
1150 (switch-to-buffer (get-buffer-create name
)))
1153 Square brackets show active fields; type RET or click mouse-1
1154 on an active field to invoke its action.
1155 Invoke [+] below to expand a group, and [-] to collapse an expanded group.\n")
1156 (if custom-browse-only-groups
1158 Invoke the [Group] button below to edit that item in another window.\n\n")
1159 (widget-insert "Invoke the ")
1160 (widget-create 'item
1163 :tag-glyph
"folder")
1164 (widget-insert ", ")
1165 (widget-create 'item
1169 (widget-insert ", and ")
1170 (widget-create 'item
1173 :tag-glyph
"option")
1174 (widget-insert " buttons below to edit that
1175 item in another window.\n\n"))
1176 (let ((custom-buffer-style 'tree
))
1177 (widget-create 'custom-group
1179 :custom-state
'unknown
1180 :tag
(custom-unlispify-tag-name group
)
1182 (goto-char (point-min)))
1184 (define-widget 'custom-browse-visibility
'item
1185 "Control visibility of of items in the customize tree browser."
1187 :action
'custom-browse-visibility-action
)
1189 (defun custom-browse-visibility-action (widget &rest ignore
)
1190 (let ((custom-buffer-style 'tree
))
1191 (custom-toggle-parent widget
)))
1193 (define-widget 'custom-browse-group-tag
'push-button
1194 "Show parent in other window when activated."
1197 :action
'custom-browse-group-tag-action
)
1199 (defun custom-browse-group-tag-action (widget &rest ignore
)
1200 (let ((parent (widget-get widget
:parent
)))
1201 (customize-group-other-window (widget-value parent
))))
1203 (define-widget 'custom-browse-variable-tag
'push-button
1204 "Show parent in other window when activated."
1207 :action
'custom-browse-variable-tag-action
)
1209 (defun custom-browse-variable-tag-action (widget &rest ignore
)
1210 (let ((parent (widget-get widget
:parent
)))
1211 (customize-variable-other-window (widget-value parent
))))
1213 (define-widget 'custom-browse-face-tag
'push-button
1214 "Show parent in other window when activated."
1217 :action
'custom-browse-face-tag-action
)
1219 (defun custom-browse-face-tag-action (widget &rest ignore
)
1220 (let ((parent (widget-get widget
:parent
)))
1221 (customize-face-other-window (widget-value parent
))))
1223 (defconst custom-browse-alist
'((" " "space")
1229 (defun custom-browse-insert-prefix (prefix)
1230 "Insert PREFIX. On XEmacs convert it to line graphics."
1231 (if nil
; (string-match "XEmacs" emacs-version)
1234 (while (not (string-equal prefix
""))
1235 (let ((entry (substring prefix
0 3)))
1236 (setq prefix
(substring prefix
3))
1237 (let ((overlay (make-overlay (1- (point)) (point) nil t nil
))
1238 (name (nth 1 (assoc entry custom-browse-alist
))))
1239 (overlay-put overlay
'end-glyph
(widget-glyph-find name entry
))
1240 (overlay-put overlay
'start-open t
)
1241 (overlay-put overlay
'end-open t
)))))
1244 ;;; Modification of Basic Widgets.
1246 ;; We add extra properties to the basic widgets needed here. This is
1247 ;; fine, as long as we are careful to stay within out own namespace.
1249 ;; We want simple widgets to be displayed by default, but complex
1250 ;; widgets to be hidden.
1252 (widget-put (get 'item
'widget-type
) :custom-show t
)
1253 (widget-put (get 'editable-field
'widget-type
)
1254 :custom-show
(lambda (widget value
)
1255 (let ((pp (pp-to-string value
)))
1256 (cond ((string-match "\n" pp
)
1261 (widget-put (get 'menu-choice
'widget-type
) :custom-show t
)
1263 ;;; The `custom-manual' Widget.
1265 (define-widget 'custom-manual
'info-link
1266 "Link to the manual entry for this customization option."
1267 :help-echo
"Read the manual entry for this option."
1270 ;;; The `custom-magic' Widget.
1272 (defgroup custom-magic-faces nil
1273 "Faces used by the magic button."
1274 :group
'custom-faces
1275 :group
'custom-buffer
)
1277 (defface custom-invalid-face
'((((class color
))
1278 (:foreground
"yellow" :background
"red"))
1280 (:bold t
:italic t
:underline t
)))
1281 "Face used when the customize item is invalid."
1282 :group
'custom-magic-faces
)
1284 (defface custom-rogue-face
'((((class color
))
1285 (:foreground
"pink" :background
"black"))
1288 "Face used when the customize item is not defined for customization."
1289 :group
'custom-magic-faces
)
1291 (defface custom-modified-face
'((((class color
))
1292 (:foreground
"white" :background
"blue"))
1295 "Face used when the customize item has been modified."
1296 :group
'custom-magic-faces
)
1298 (defface custom-set-face
'((((class color
))
1299 (:foreground
"blue" :background
"white"))
1302 "Face used when the customize item has been set."
1303 :group
'custom-magic-faces
)
1305 (defface custom-changed-face
'((((class color
))
1306 (:foreground
"white" :background
"blue"))
1309 "Face used when the customize item has been changed."
1310 :group
'custom-magic-faces
)
1312 (defface custom-saved-face
'((t (:underline t
)))
1313 "Face used when the customize item has been saved."
1314 :group
'custom-magic-faces
)
1316 (defconst custom-magic-alist
'((nil "#" underline
"\
1317 uninitialized, you should not see this.")
1318 (unknown "?" italic
"\
1319 unknown, you should not see this.")
1320 (hidden "-" default
"\
1321 hidden, invoke \"Show\" in the previous line to show." "\
1322 group now hidden, invoke \"Show\", above, to show contents.")
1323 (invalid "x" custom-invalid-face
"\
1324 the value displayed for this %c is invalid and cannot be set.")
1325 (modified "*" custom-modified-face
"\
1326 you have edited the value as text, but you have not set the %c." "\
1327 you have edited something in this group, but not set it.")
1328 (set "+" custom-set-face
"\
1329 you have set this %c, but not saved it for future sessions." "\
1330 something in this group has been set, but not saved.")
1331 (changed ":" custom-changed-face
"\
1332 this %c has been changed outside the customize buffer." "\
1333 something in this group has been changed outside customize.")
1334 (saved "!" custom-saved-face
"\
1335 this %c has been set and saved." "\
1336 something in this group has been set and saved.")
1337 (rogue "@" custom-rogue-face
"\
1338 this %c has not been changed with customize." "\
1339 something in this group is not prepared for customization.")
1340 (standard " " nil
"\
1341 this %c is unchanged from its standard setting." "\
1342 visible group members are all at standard settings."))
1343 "Alist of customize option states.
1344 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1346 STATE is one of the following symbols:
1349 For internal use, should never occur.
1351 For internal use, should never occur.
1353 This item is not being displayed.
1355 This item is modified, but has an invalid form.
1357 This item is modified, and has a valid form.
1359 This item has been set but not saved.
1361 The current value of this item has been changed temporarily.
1363 This item is marked for saving.
1365 This item has no customization information.
1367 This item is unchanged from the standard setting.
1369 MAGIC is a string used to present that state.
1371 FACE is a face used to present the state.
1373 ITEM-DESC is a string describing the state for options.
1375 GROUP-DESC is a string describing the state for groups. If this is
1376 left out, ITEM-DESC will be used.
1378 The string %c in either description will be replaced with the
1379 category of the item. These are `group'. `option', and `face'.
1381 The list should be sorted most significant first.")
1383 (defcustom custom-magic-show
'long
1384 "If non-nil, show textual description of the state.
1385 If `long', show a full-line description, not just one word."
1386 :type
'(choice (const :tag
"no" nil
)
1389 :group
'custom-buffer
)
1391 (defcustom custom-magic-show-hidden
'(option face
)
1392 "Control whether the State button is shown for hidden items.
1393 The value should be a list with the custom categories where the State
1394 button should be visible. Possible categories are `group', `option',
1396 :type
'(set (const group
) (const option
) (const face
))
1397 :group
'custom-buffer
)
1399 (defcustom custom-magic-show-button nil
1400 "Show a \"magic\" button indicating the state of each customization option."
1402 :group
'custom-buffer
)
1404 (define-widget 'custom-magic
'default
1405 "Show and manipulate state for a customization option."
1407 :action
'widget-parent-action
1410 :value-create
'custom-magic-value-create
1411 :value-delete
'widget-children-value-delete
)
1413 (defun widget-magic-mouse-down-action (widget &optional event
)
1414 ;; Non-nil unless hidden.
1415 (not (eq (widget-get (widget-get (widget-get widget
:parent
) :parent
)
1419 (defun custom-magic-value-create (widget)
1420 ;; Create compact status report for WIDGET.
1421 (let* ((parent (widget-get widget
:parent
))
1422 (state (widget-get parent
:custom-state
))
1423 (hidden (eq state
'hidden
))
1424 (entry (assq state custom-magic-alist
))
1425 (magic (nth 1 entry
))
1426 (face (nth 2 entry
))
1427 (category (widget-get parent
:custom-category
))
1428 (text (or (and (eq category
'group
)
1431 (form (widget-get parent
:custom-form
))
1433 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text
)
1434 (setq text
(concat (match-string 1 text
)
1435 (symbol-name category
)
1436 (match-string 2 text
))))
1437 (when (and custom-magic-show
1439 (memq category custom-magic-show-hidden
)))
1441 (when (and (eq category
'group
)
1442 (not (and (eq custom-buffer-style
'links
)
1443 (> (widget-get parent
:custom-level
) 1))))
1444 (insert-char ?\
(* custom-buffer-indent
1445 (widget-get parent
:custom-level
))))
1446 (push (widget-create-child-and-convert
1448 :help-echo
"Change the state of this item."
1449 :format
(if hidden
"%t" "%[%t%]")
1450 :button-prefix
'widget-push-button-prefix
1451 :button-suffix
'widget-push-button-suffix
1452 :mouse-down-action
'widget-magic-mouse-down-action
1456 (let ((start (point)))
1457 (if (eq custom-magic-show
'long
)
1459 (insert (symbol-name state
)))
1460 (cond ((eq form
'lisp
)
1462 ((eq form
'mismatch
)
1463 (insert " (mismatch)")))
1464 (put-text-property start
(point) 'face
'custom-state-face
))
1466 (when (and (eq category
'group
)
1467 (not (and (eq custom-buffer-style
'links
)
1468 (> (widget-get parent
:custom-level
) 1))))
1469 (insert-char ?\
(* custom-buffer-indent
1470 (widget-get parent
:custom-level
))))
1471 (when custom-magic-show-button
1472 (when custom-magic-show
1473 (let ((indent (widget-get parent
:indent
)))
1475 (insert-char ? indent
))))
1476 (push (widget-create-child-and-convert
1478 :mouse-down-action
'widget-magic-mouse-down-action
1482 :help-echo
"Change the state."
1483 :format
(if hidden
"%t" "%[%t%]")
1484 :tag
(if (memq form
'(lisp mismatch
))
1485 (concat "(" magic
")")
1486 (concat "[" magic
"]")))
1489 (widget-put widget
:children children
)))
1491 (defun custom-magic-reset (widget)
1492 "Redraw the :custom-magic property of WIDGET."
1493 (let ((magic (widget-get widget
:custom-magic
)))
1494 (widget-value-set magic
(widget-value magic
))))
1496 ;;; The `custom' Widget.
1498 (defface custom-button-face nil
1499 "Face used for buttons in customization buffers."
1500 :group
'custom-faces
)
1502 (defface custom-documentation-face nil
1503 "Face used for documentation strings in customization buffers."
1504 :group
'custom-faces
)
1506 (defface custom-state-face
'((((class color
)
1508 (:foreground
"lime green"))
1511 (:foreground
"dark green"))
1513 "Face used for State descriptions in the customize buffer."
1514 :group
'custom-faces
)
1516 (define-widget 'custom
'default
1517 "Customize a user option."
1519 :convert-widget
'custom-convert-widget
1520 :notify
'custom-notify
1523 :custom-state
'hidden
1524 :documentation-property
'widget-subclass-responsibility
1525 :value-create
'widget-subclass-responsibility
1526 :value-delete
'widget-children-value-delete
1527 :value-get
'widget-value-value-get
1528 :validate
'widget-children-validate
1529 :match
(lambda (widget value
) (symbolp value
)))
1531 (defun custom-convert-widget (widget)
1532 ;; Initialize :value and :tag from :args in WIDGET.
1533 (let ((args (widget-get widget
:args
)))
1535 (widget-put widget
:value
(widget-apply widget
1536 :value-to-internal
(car args
)))
1537 (widget-put widget
:tag
(custom-unlispify-tag-name (car args
)))
1538 (widget-put widget
:args nil
)))
1541 (defun custom-notify (widget &rest args
)
1542 "Keep track of changes."
1543 (let ((state (widget-get widget
:custom-state
)))
1544 (unless (eq state
'modified
)
1545 (unless (memq state
'(nil unknown hidden
))
1546 (widget-put widget
:custom-state
'modified
))
1547 (custom-magic-reset widget
)
1548 (apply 'widget-default-notify widget args
))))
1550 (defun custom-redraw (widget)
1551 "Redraw WIDGET with current settings."
1552 (let ((line (count-lines (point-min) (point)))
1553 (column (current-column))
1555 (from (marker-position (widget-get widget
:from
)))
1556 (to (marker-position (widget-get widget
:to
))))
1558 (widget-value-set widget
(widget-value widget
))
1559 (custom-redraw-magic widget
))
1560 (when (and (>= pos from
) (<= pos to
))
1565 (goto-line (1+ line
)))
1566 (move-to-column column
))
1569 (defun custom-redraw-magic (widget)
1570 "Redraw WIDGET state with current settings."
1572 (let ((magic (widget-get widget
:custom-magic
)))
1574 (widget-value-set magic
(widget-value magic
))
1575 (when (setq widget
(widget-get widget
:group
))
1576 (custom-group-state-update widget
)))
1578 (setq widget nil
)))))
1581 (defun custom-show (widget value
)
1582 "Non-nil if WIDGET should be shown with VALUE by default."
1583 (let ((show (widget-get widget
:custom-show
)))
1589 (funcall show widget value
)))))
1591 (defvar custom-load-recursion nil
1592 "Hack to avoid recursive dependencies.")
1594 (defun custom-load-symbol (symbol)
1595 "Load all dependencies for SYMBOL."
1596 (unless custom-load-recursion
1597 (let ((custom-load-recursion t
)
1598 (loads (get symbol
'custom-loads
))
1601 (setq load
(car loads
)
1603 (cond ((symbolp load
)
1607 ;; Don't reload a file already loaded.
1608 ((and (boundp 'preloaded-file-list
)
1609 (member load preloaded-file-list
)))
1610 ((assoc load load-history
))
1611 ((assoc (locate-library load
) load-history
))
1614 ;; Without this, we would load cus-edit recursively.
1615 ;; We are still loading it when we call this,
1616 ;; and it is not in load-history yet.
1617 (or (equal load
"cus-edit")
1618 (load-library load
))
1621 (defun custom-load-widget (widget)
1622 "Load all dependencies for WIDGET."
1623 (custom-load-symbol (widget-value widget
)))
1625 (defun custom-unloaded-symbol-p (symbol)
1626 "Return non-nil if the dependencies of SYMBOL has not yet been loaded."
1628 (loads (get symbol
'custom-loads
))
1631 (setq load
(car loads
)
1633 (cond ((symbolp load
)
1634 (unless (featurep load
)
1636 ((assoc load load-history
))
1637 ((assoc (locate-library load
) load-history
)
1643 (defun custom-unloaded-widget-p (widget)
1644 "Return non-nil if the dependencies of WIDGET has not yet been loaded."
1645 (custom-unloaded-symbol-p (widget-value widget
)))
1647 (defun custom-toggle-hide (widget)
1648 "Toggle visibility of WIDGET."
1649 (custom-load-widget widget
)
1650 (let ((state (widget-get widget
:custom-state
)))
1651 (cond ((memq state
'(invalid modified
))
1652 (error "There are unset changes"))
1654 (widget-put widget
:custom-state
'unknown
))
1656 (widget-put widget
:documentation-shown nil
)
1657 (widget-put widget
:custom-state
'hidden
)))
1658 (custom-redraw widget
)
1661 (defun custom-toggle-parent (widget &rest ignore
)
1662 "Toggle visibility of parent of WIDGET."
1663 (custom-toggle-hide (widget-get widget
:parent
)))
1665 (defun custom-add-see-also (widget &optional prefix
)
1666 "Add `See also ...' to WIDGET if there are any links.
1667 Insert PREFIX first if non-nil."
1668 (let* ((symbol (widget-get widget
:value
))
1669 (links (get symbol
'custom-links
))
1670 (many (> (length links
) 2))
1671 (buttons (widget-get widget
:buttons
))
1672 (indent (widget-get widget
:indent
)))
1675 (insert-char ?\ indent
))
1678 (insert "See also ")
1680 (push (widget-create-child-and-convert widget
(car links
))
1682 (setq links
(cdr links
))
1691 (widget-put widget
:buttons buttons
))))
1693 (defun custom-add-parent-links (widget &optional initial-string
)
1694 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
1695 The value if non-nil if any parents were found.
1696 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
1697 (let ((name (widget-value widget
))
1698 (type (widget-type widget
))
1699 (buttons (widget-get widget
:buttons
))
1702 (insert (or initial-string
"Parent groups:"))
1703 (mapatoms (lambda (symbol)
1704 (let ((entry (assq name
(get symbol
'custom-group
))))
1705 (when (eq (nth 1 entry
) type
)
1707 (push (widget-create-child-and-convert
1708 widget
'custom-group-link
1709 :tag
(custom-unlispify-tag-name symbol
)
1713 (widget-put widget
:buttons buttons
)
1716 (delete-region start
(point)))
1719 ;;; The `custom-variable' Widget.
1721 (defface custom-variable-tag-face
'((((class color
)
1723 (:foreground
"light blue" :underline t
))
1726 (:foreground
"blue" :underline t
))
1728 "Face used for unpushable variable tags."
1729 :group
'custom-faces
)
1731 (defface custom-variable-button-face
'((t (:underline t
:bold t
)))
1732 "Face used for pushable variable tags."
1733 :group
'custom-faces
)
1735 (define-widget 'custom-variable
'custom
1736 "Customize variable."
1738 :help-echo
"Set or reset this variable."
1739 :documentation-property
'variable-documentation
1740 :custom-category
'option
1742 :custom-menu
'custom-variable-menu-create
1744 :value-create
'custom-variable-value-create
1745 :action
'custom-variable-action
1746 :custom-set
'custom-variable-set
1747 :custom-save
'custom-variable-save
1748 :custom-reset-current
'custom-redraw
1749 :custom-reset-saved
'custom-variable-reset-saved
1750 :custom-reset-standard
'custom-variable-reset-standard
)
1752 (defun custom-variable-type (symbol)
1753 "Return a widget suitable for editing the value of SYMBOL.
1754 If SYMBOL has a `custom-type' property, use that.
1755 Otherwise, look up symbol in `custom-guess-type-alist'."
1756 (let* ((type (or (get symbol
'custom-type
)
1757 (and (not (get symbol
'standard-value
))
1758 (custom-guess-type symbol
))
1760 (options (get symbol
'custom-options
))
1761 (tmp (if (listp type
)
1762 (copy-sequence type
)
1765 (widget-put tmp
:options options
))
1768 (defun custom-variable-value-create (widget)
1769 "Here is where you edit the variables value."
1770 (custom-load-widget widget
)
1771 (let* ((buttons (widget-get widget
:buttons
))
1772 (children (widget-get widget
:children
))
1773 (form (widget-get widget
:custom-form
))
1774 (state (widget-get widget
:custom-state
))
1775 (symbol (widget-get widget
:value
))
1776 (tag (widget-get widget
:tag
))
1777 (type (custom-variable-type symbol
))
1778 (conv (widget-convert type
))
1779 (get (or (get symbol
'custom-get
) 'default-value
))
1780 (prefix (widget-get widget
:custom-prefix
))
1781 (last (widget-get widget
:custom-last
))
1782 (value (if (default-boundp symbol
)
1783 (funcall get symbol
)
1784 (widget-get conv
:value
))))
1785 ;; If the widget is new, the child determine whether it is hidden.
1787 ((custom-show type value
)
1788 (setq state
'unknown
))
1790 (setq state
'hidden
)))
1791 ;; If we don't know the state, see if we need to edit it in lisp form.
1792 (when (eq state
'unknown
)
1793 (unless (widget-apply conv
:match value
)
1794 ;; (widget-apply (widget-convert type) :match value)
1795 (setq form
'mismatch
)))
1796 ;; Now we can create the child widget.
1797 (cond ((eq custom-buffer-style
'tree
)
1798 (insert prefix
(if last
" `--- " " |--- "))
1799 (push (widget-create-child-and-convert
1800 widget
'custom-browse-variable-tag
)
1802 (insert " " tag
"\n")
1803 (widget-put widget
:buttons buttons
))
1805 ;; Indicate hidden value.
1806 (push (widget-create-child-and-convert
1809 :sample-face
'custom-variable-tag-face
1813 (push (widget-create-child-and-convert
1815 :help-echo
"Show the value of this option."
1816 :action
'custom-toggle-parent
1819 ((memq form
'(lisp mismatch
))
1820 ;; In lisp mode edit the saved value when possible.
1821 (let* ((value (cond ((get symbol
'saved-value
)
1822 (car (get symbol
'saved-value
)))
1823 ((get symbol
'standard-value
)
1824 (car (get symbol
'standard-value
)))
1825 ((default-boundp symbol
)
1826 (custom-quote (funcall get symbol
)))
1828 (custom-quote (widget-get conv
:value
))))))
1829 (insert (symbol-name symbol
) ": ")
1830 (push (widget-create-child-and-convert
1832 :help-echo
"Hide the value of this option."
1833 :action
'custom-toggle-parent
1837 (push (widget-create-child-and-convert
1839 :button-face
'custom-variable-button-face
1841 :tag
(symbol-name symbol
)
1847 (let* ((format (widget-get type
:format
))
1848 tag-format value-format
)
1849 (unless (string-match ":" format
)
1850 (error "Bad format."))
1851 (setq tag-format
(substring format
0 (match-end 0)))
1852 (setq value-format
(substring format
(match-end 0)))
1853 (push (widget-create-child-and-convert
1856 :action
'custom-tag-action
1857 :help-echo
"Change value of this option."
1858 :mouse-down-action
'custom-tag-mouse-down-action
1859 :button-face
'custom-variable-button-face
1860 :sample-face
'custom-variable-tag-face
1864 (push (widget-create-child-and-convert
1866 :help-echo
"Hide the value of this option."
1867 :action
'custom-toggle-parent
1870 (push (widget-create-child-and-convert
1872 :format value-format
1875 (unless (eq custom-buffer-style
'tree
)
1876 ;; Now update the state.
1877 (unless (eq (preceding-char) ?
\n)
1878 (widget-insert "\n"))
1879 (if (eq state
'hidden
)
1880 (widget-put widget
:custom-state state
)
1881 (custom-variable-state-set widget
))
1882 ;; Create the magic button.
1883 (let ((magic (widget-create-child-and-convert
1884 widget
'custom-magic nil
)))
1885 (widget-put widget
:custom-magic magic
)
1886 (push magic buttons
))
1887 ;; Update properties.
1888 (widget-put widget
:custom-form form
)
1889 (widget-put widget
:buttons buttons
)
1890 (widget-put widget
:children children
)
1891 ;; Insert documentation.
1892 (widget-default-format-handler widget ?h
)
1894 (unless (eq state
'hidden
)
1895 (when (eq (widget-get widget
:custom-level
) 1)
1896 (custom-add-parent-links widget
))
1897 (custom-add-see-also widget
)))))
1899 (defun custom-tag-action (widget &rest args
)
1900 "Pass :action to first child of WIDGET's parent."
1901 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
1904 (defun custom-tag-mouse-down-action (widget &rest args
)
1905 "Pass :mouse-down-action to first child of WIDGET's parent."
1906 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
1907 :mouse-down-action args
))
1909 (defun custom-variable-state-set (widget)
1910 "Set the state of WIDGET."
1911 (let* ((symbol (widget-value widget
))
1912 (get (or (get symbol
'custom-get
) 'default-value
))
1913 (value (if (default-boundp symbol
)
1914 (funcall get symbol
)
1915 (widget-get widget
:value
)))
1917 (state (cond ((setq tmp
(get symbol
'customized-value
))
1918 (if (condition-case nil
1919 (equal value
(eval (car tmp
)))
1923 ((setq tmp
(get symbol
'saved-value
))
1924 (if (condition-case nil
1925 (equal value
(eval (car tmp
)))
1929 ((setq tmp
(get symbol
'standard-value
))
1930 (if (condition-case nil
1931 (equal value
(eval (car tmp
)))
1936 (widget-put widget
:custom-state state
)))
1938 (defvar custom-variable-menu
1939 '(("Set for Current Session" custom-variable-set
1941 (eq (widget-get widget
:custom-state
) 'modified
)))
1942 ("Save for Future Sessions" custom-variable-save
1944 (memq (widget-get widget
:custom-state
) '(modified set changed rogue
))))
1945 ("Reset to Current" custom-redraw
1947 (and (default-boundp (widget-value widget
))
1948 (memq (widget-get widget
:custom-state
) '(modified changed
)))))
1949 ("Reset to Saved" custom-variable-reset-saved
1951 (and (get (widget-value widget
) 'saved-value
)
1952 (memq (widget-get widget
:custom-state
)
1953 '(modified set changed rogue
)))))
1954 ("Reset to Standard Settings" custom-variable-reset-standard
1956 (and (get (widget-value widget
) 'standard-value
)
1957 (memq (widget-get widget
:custom-state
)
1958 '(modified set changed saved rogue
)))))
1959 ("---" ignore ignore
)
1960 ("Don't show as Lisp expression" custom-variable-edit
1962 (eq (widget-get widget
:custom-form
) 'lisp
)))
1963 ("Show initial Lisp expression" custom-variable-edit-lisp
1965 (eq (widget-get widget
:custom-form
) 'edit
))))
1966 "Alist of actions for the `custom-variable' widget.
1967 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
1968 the menu entry, ACTION is the function to call on the widget when the
1969 menu is selected, and FILTER is a predicate which takes a `custom-variable'
1970 widget as an argument, and returns non-nil if ACTION is valid on that
1971 widget. If FILTER is nil, ACTION is always valid.")
1973 (defun custom-variable-action (widget &optional event
)
1974 "Show the menu for `custom-variable' WIDGET.
1975 Optional EVENT is the location for the menu."
1976 (if (eq (widget-get widget
:custom-state
) 'hidden
)
1977 (custom-toggle-hide widget
)
1978 (unless (eq (widget-get widget
:custom-state
) 'modified
)
1979 (custom-variable-state-set widget
))
1980 (custom-redraw-magic widget
)
1981 (let* ((completion-ignore-case t
)
1982 (answer (widget-choose (concat "Operation on "
1983 (custom-unlispify-tag-name
1984 (widget-get widget
:value
)))
1985 (custom-menu-filter custom-variable-menu
1989 (funcall answer widget
)))))
1991 (defun custom-variable-edit (widget)
1992 "Edit value of WIDGET."
1993 (widget-put widget
:custom-state
'unknown
)
1994 (widget-put widget
:custom-form
'edit
)
1995 (custom-redraw widget
))
1997 (defun custom-variable-edit-lisp (widget)
1998 "Edit the lisp representation of the value of WIDGET."
1999 (widget-put widget
:custom-state
'unknown
)
2000 (widget-put widget
:custom-form
'lisp
)
2001 (custom-redraw widget
))
2003 (defun custom-variable-set (widget)
2004 "Set the current value for the variable being edited by WIDGET."
2005 (let* ((form (widget-get widget
:custom-form
))
2006 (state (widget-get widget
:custom-state
))
2007 (child (car (widget-get widget
:children
)))
2008 (symbol (widget-value widget
))
2009 (set (or (get symbol
'custom-set
) 'set-default
))
2011 (cond ((eq state
'hidden
)
2012 (error "Cannot set hidden variable."))
2013 ((setq val
(widget-apply child
:validate
))
2014 (goto-char (widget-get val
:from
))
2015 (error "%s" (widget-get val
:error
)))
2016 ((memq form
'(lisp mismatch
))
2017 (funcall set symbol
(eval (setq val
(widget-value child
))))
2018 (put symbol
'customized-value
(list val
)))
2020 (funcall set symbol
(setq val
(widget-value child
)))
2021 (put symbol
'customized-value
(list (custom-quote val
)))))
2022 (custom-variable-state-set widget
)
2023 (custom-redraw-magic widget
)))
2025 (defun custom-variable-save (widget)
2026 "Set and save the value for the variable being edited by WIDGET."
2027 (let* ((form (widget-get widget
:custom-form
))
2028 (state (widget-get widget
:custom-state
))
2029 (child (car (widget-get widget
:children
)))
2030 (symbol (widget-value widget
))
2031 (set (or (get symbol
'custom-set
) 'set-default
))
2033 (cond ((eq state
'hidden
)
2034 (error "Cannot set hidden variable."))
2035 ((setq val
(widget-apply child
:validate
))
2036 (goto-char (widget-get val
:from
))
2037 (error "%s" (widget-get val
:error
)))
2038 ((memq form
'(lisp mismatch
))
2039 (put symbol
'saved-value
(list (widget-value child
)))
2040 (funcall set symbol
(eval (widget-value child
))))
2043 'saved-value
(list (custom-quote (widget-value
2045 (funcall set symbol
(widget-value child
))))
2046 (put symbol
'customized-value nil
)
2048 (custom-variable-state-set widget
)
2049 (custom-redraw-magic widget
)))
2051 (defun custom-variable-reset-saved (widget)
2052 "Restore the saved value for the variable being edited by WIDGET."
2053 (let* ((symbol (widget-value widget
))
2054 (set (or (get symbol
'custom-set
) 'set-default
)))
2055 (if (get symbol
'saved-value
)
2057 (funcall set symbol
(eval (car (get symbol
'saved-value
))))
2059 (error "No saved value for %s" symbol
))
2060 (put symbol
'customized-value nil
)
2061 (widget-put widget
:custom-state
'unknown
)
2062 (custom-redraw widget
)))
2064 (defun custom-variable-reset-standard (widget)
2065 "Restore the standard setting for the variable being edited by WIDGET."
2066 (let* ((symbol (widget-value widget
))
2067 (set (or (get symbol
'custom-set
) 'set-default
)))
2068 (if (get symbol
'standard-value
)
2069 (funcall set symbol
(eval (car (get symbol
'standard-value
))))
2070 (error "No standard setting known for %S" symbol
))
2071 (put symbol
'customized-value nil
)
2072 (when (get symbol
'saved-value
)
2073 (put symbol
'saved-value nil
)
2075 (widget-put widget
:custom-state
'unknown
)
2076 (custom-redraw widget
)))
2078 ;;; The `custom-face-edit' Widget.
2080 (define-widget 'custom-face-edit
'checklist
2081 "Edit face attributes."
2085 :button-args
'(:help-echo
"Control whether this attribute have any effect.")
2086 :args
(mapcar (lambda (att)
2089 :sibling-args
(widget-get (nth 1 att
) :sibling-args
)
2090 (list 'const
:format
"" :value
(nth 0 att
))
2092 custom-face-attributes
))
2094 ;;; The `custom-display' Widget.
2096 (define-widget 'custom-display
'menu-choice
2097 "Select a display type."
2100 :help-echo
"Specify frames where the face attributes should be used."
2101 :args
'((const :tag
"all" t
)
2105 :args
((group :sibling-args
(:help-echo
"\
2106 Only match the specified window systems.")
2107 (const :format
"Type: "
2109 (checklist :inline t
2112 :sibling-args
(:help-echo
"\
2113 The X11 Window System.")
2115 (const :format
"PM "
2116 :sibling-args
(:help-echo
"\
2117 OS/2 Presentation Manager.")
2119 (const :format
"W32 "
2120 :sibling-args
(:help-echo
"\
2123 (const :format
"DOS "
2124 :sibling-args
(:help-echo
"\
2127 (const :format
"TTY%n"
2128 :sibling-args
(:help-echo
"\
2129 Plain text terminals.")
2131 (group :sibling-args
(:help-echo
"\
2132 Only match the frames with the specified color support.")
2133 (const :format
"Class: "
2135 (checklist :inline t
2137 (const :format
"Color "
2138 :sibling-args
(:help-echo
"\
2139 Match color frames.")
2141 (const :format
"Grayscale "
2142 :sibling-args
(:help-echo
"\
2143 Match grayscale frames.")
2145 (const :format
"Monochrome%n"
2146 :sibling-args
(:help-echo
"\
2147 Match frames with no color support.")
2149 (group :sibling-args
(:help-echo
"\
2150 Only match frames with the specified intensity.")
2152 Background brightness: "
2154 (checklist :inline t
2156 (const :format
"Light "
2157 :sibling-args
(:help-echo
"\
2158 Match frames with light backgrounds.")
2160 (const :format
"Dark\n"
2161 :sibling-args
(:help-echo
"\
2162 Match frames with dark backgrounds.")
2165 ;;; The `custom-face' Widget.
2167 (defface custom-face-tag-face
'((t (:underline t
)))
2168 "Face used for face tags."
2169 :group
'custom-faces
)
2171 (define-widget 'custom-face
'custom
2173 :sample-face
'custom-face-tag-face
2174 :help-echo
"Set or reset this face."
2175 :documentation-property
'(lambda (face)
2176 (face-doc-string face
))
2177 :value-create
'custom-face-value-create
2178 :action
'custom-face-action
2179 :custom-category
'face
2180 :custom-form
'selected
2181 :custom-set
'custom-face-set
2182 :custom-save
'custom-face-save
2183 :custom-reset-current
'custom-redraw
2184 :custom-reset-saved
'custom-face-reset-saved
2185 :custom-reset-standard
'custom-face-reset-standard
2186 :custom-menu
'custom-face-menu-create
)
2188 (define-widget 'custom-face-all
'editable-list
2189 "An editable list of display specifications and attributes."
2190 :entry-format
"%i %d %v"
2191 :insert-button-args
'(:help-echo
"Insert new display specification here.")
2192 :append-button-args
'(:help-echo
"Append new display specification here.")
2193 :delete-button-args
'(:help-echo
"Delete this display specification.")
2194 :args
'((group :format
"%v" custom-display custom-face-edit
)))
2196 (defconst custom-face-all
(widget-convert 'custom-face-all
)
2197 "Converted version of the `custom-face-all' widget.")
2199 (define-widget 'custom-display-unselected
'item
2200 "A display specification that doesn't match the selected display."
2201 :match
'custom-display-unselected-match
)
2203 (defun custom-display-unselected-match (widget value
)
2204 "Non-nil if VALUE is an unselected display specification."
2205 (not (face-spec-set-match-display value
(selected-frame))))
2207 (define-widget 'custom-face-selected
'group
2208 "Edit the attributes of the selected display in a face specification."
2209 :args
'((repeat :format
""
2211 (group custom-display-unselected sexp
))
2212 (group (sexp :format
"") custom-face-edit
)
2217 (defconst custom-face-selected
(widget-convert 'custom-face-selected
)
2218 "Converted version of the `custom-face-selected' widget.")
2220 (defun custom-face-value-create (widget)
2221 "Create a list of the display specifications for WIDGET."
2222 (let ((buttons (widget-get widget
:buttons
))
2223 (symbol (widget-get widget
:value
))
2224 (tag (widget-get widget
:tag
))
2225 (state (widget-get widget
:custom-state
))
2227 (is-last (widget-get widget
:custom-last
))
2228 (prefix (widget-get widget
:custom-prefix
)))
2230 (setq tag
(prin1-to-string symbol
)))
2231 (cond ((eq custom-buffer-style
'tree
)
2232 (insert prefix
(if is-last
" `--- " " |--- "))
2233 (push (widget-create-child-and-convert
2234 widget
'custom-browse-face-tag
)
2236 (insert " " tag
"\n")
2237 (widget-put widget
:buttons buttons
))
2241 (if (eq custom-buffer-style
'face
)
2243 (widget-specify-sample widget begin
(point))
2246 (and (string-match "XEmacs" emacs-version
)
2247 ;; XEmacs cannot display uninitialized faces.
2248 (not (custom-facep symbol
))
2249 (copy-face 'custom-face-empty symbol
))
2250 (push (widget-create-child-and-convert widget
'item
2257 (push (widget-create-child-and-convert
2259 :help-echo
"Hide or show this face."
2260 :action
'custom-toggle-parent
2261 (not (eq state
'hidden
)))
2265 (let ((magic (widget-create-child-and-convert
2266 widget
'custom-magic nil
)))
2267 (widget-put widget
:custom-magic magic
)
2268 (push magic buttons
))
2270 (widget-put widget
:buttons buttons
)
2271 ;; Insert documentation.
2272 (widget-default-format-handler widget ?h
)
2274 (unless (eq state
'hidden
)
2275 (when (eq (widget-get widget
:custom-level
) 1)
2276 (custom-add-parent-links widget
))
2277 (custom-add-see-also widget
))
2279 (unless (eq (preceding-char) ?
\n)
2281 (unless (eq state
'hidden
)
2282 (message "Creating face editor...")
2283 (custom-load-widget widget
)
2284 (let* ((symbol (widget-value widget
))
2285 (spec (or (get symbol
'saved-face
)
2286 (get symbol
'face-defface-spec
)
2287 ;; Attempt to construct it.
2288 (list (list t
(custom-face-attributes-get
2289 symbol
(selected-frame))))))
2290 (form (widget-get widget
:custom-form
))
2291 (indent (widget-get widget
:indent
))
2293 ;; If the user has changed this face in some other way,
2294 ;; edit it as the user has specified it.
2295 (if (not (face-spec-match-p symbol spec
(selected-frame)))
2296 (setq spec
(list (list t
(face-attr-construct symbol
(selected-frame))))))
2297 (setq edit
(widget-create-child-and-convert
2299 (cond ((and (eq form
'selected
)
2300 (widget-apply custom-face-selected
2302 (when indent
(insert-char ?\ indent
))
2303 'custom-face-selected
)
2304 ((and (not (eq form
'lisp
))
2305 (widget-apply custom-face-all
2309 (when indent
(insert-char ?\ indent
))
2312 (custom-face-state-set widget
)
2313 (widget-put widget
:children
(list edit
)))
2314 (message "Creating face editor...done"))))))
2316 (defvar custom-face-menu
2317 '(("Set for Current Session" custom-face-set
)
2318 ("Save for Future Sessions" custom-face-save
)
2319 ("Reset to Saved" custom-face-reset-saved
2321 (get (widget-value widget
) 'saved-face
)))
2322 ("Reset to Standard Setting" custom-face-reset-standard
2324 (get (widget-value widget
) 'face-defface-spec
)))
2325 ("---" ignore ignore
)
2326 ("Show all display specs" custom-face-edit-all
2328 (not (eq (widget-get widget
:custom-form
) 'all
))))
2329 ("Just current attributes" custom-face-edit-selected
2331 (not (eq (widget-get widget
:custom-form
) 'selected
))))
2332 ("Show as Lisp expression" custom-face-edit-lisp
2334 (not (eq (widget-get widget
:custom-form
) 'lisp
)))))
2335 "Alist of actions for the `custom-face' widget.
2336 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2337 the menu entry, ACTION is the function to call on the widget when the
2338 menu is selected, and FILTER is a predicate which takes a `custom-face'
2339 widget as an argument, and returns non-nil if ACTION is valid on that
2340 widget. If FILTER is nil, ACTION is always valid.")
2342 (defun custom-face-edit-selected (widget)
2343 "Edit selected attributes of the value of WIDGET."
2344 (widget-put widget
:custom-state
'unknown
)
2345 (widget-put widget
:custom-form
'selected
)
2346 (custom-redraw widget
))
2348 (defun custom-face-edit-all (widget)
2349 "Edit all attributes of the value of WIDGET."
2350 (widget-put widget
:custom-state
'unknown
)
2351 (widget-put widget
:custom-form
'all
)
2352 (custom-redraw widget
))
2354 (defun custom-face-edit-lisp (widget)
2355 "Edit the lisp representation of the value of WIDGET."
2356 (widget-put widget
:custom-state
'unknown
)
2357 (widget-put widget
:custom-form
'lisp
)
2358 (custom-redraw widget
))
2360 (defun custom-face-state-set (widget)
2361 "Set the state of WIDGET."
2362 (let ((symbol (widget-value widget
)))
2363 (widget-put widget
:custom-state
(cond ((get symbol
'customized-face
)
2365 ((get symbol
'saved-face
)
2367 ((get symbol
'face-defface-spec
)
2372 (defun custom-face-action (widget &optional event
)
2373 "Show the menu for `custom-face' WIDGET.
2374 Optional EVENT is the location for the menu."
2375 (if (eq (widget-get widget
:custom-state
) 'hidden
)
2376 (custom-toggle-hide widget
)
2377 (let* ((completion-ignore-case t
)
2378 (symbol (widget-get widget
:value
))
2379 (answer (widget-choose (concat "Operation on "
2380 (custom-unlispify-tag-name symbol
))
2381 (custom-menu-filter custom-face-menu
2385 (funcall answer widget
)))))
2387 (defun custom-face-set (widget)
2388 "Make the face attributes in WIDGET take effect."
2389 (let* ((symbol (widget-value widget
))
2390 (child (car (widget-get widget
:children
)))
2391 (value (widget-value child
)))
2392 (put symbol
'customized-face value
)
2393 (face-spec-set symbol value
)
2394 (custom-face-state-set widget
)
2395 (custom-redraw-magic widget
)))
2397 (defun custom-face-save (widget)
2398 "Make the face attributes in WIDGET default."
2399 (let* ((symbol (widget-value widget
))
2400 (child (car (widget-get widget
:children
)))
2401 (value (widget-value child
)))
2402 (face-spec-set symbol value
)
2403 (put symbol
'saved-face value
)
2404 (put symbol
'customized-face nil
)
2405 (custom-face-state-set widget
)
2406 (custom-redraw-magic widget
)))
2408 (defun custom-face-reset-saved (widget)
2409 "Restore WIDGET to the face's default attributes."
2410 (let* ((symbol (widget-value widget
))
2411 (child (car (widget-get widget
:children
)))
2412 (value (get symbol
'saved-face
)))
2414 (error "No saved value for this face"))
2415 (put symbol
'customized-face nil
)
2416 (face-spec-set symbol value
)
2417 (widget-value-set child value
)
2418 (custom-face-state-set widget
)
2419 (custom-redraw-magic widget
)))
2421 (defun custom-face-reset-standard (widget)
2422 "Restore WIDGET to the face's standard settings."
2423 (let* ((symbol (widget-value widget
))
2424 (child (car (widget-get widget
:children
)))
2425 (value (get symbol
'face-defface-spec
)))
2427 (error "No standard setting for this face"))
2428 (put symbol
'customized-face nil
)
2429 (when (get symbol
'saved-face
)
2430 (put symbol
'saved-face nil
)
2432 (face-spec-set symbol value
)
2433 (widget-value-set child value
)
2434 (custom-face-state-set widget
)
2435 (custom-redraw-magic widget
)))
2437 ;;; The `face' Widget.
2439 (define-widget 'face
'default
2440 "Select and customize a face."
2441 :convert-widget
'widget-value-convert-widget
2442 :button-prefix
'widget-push-button-prefix
2443 :button-suffix
'widget-push-button-suffix
2444 :format
"%t: %[select face%] %v"
2447 :value-create
'widget-face-value-create
2448 :value-delete
'widget-face-value-delete
2449 :value-get
'widget-value-value-get
2450 :validate
'widget-children-validate
2451 :action
'widget-face-action
2452 :match
'(lambda (widget value
) (symbolp value
)))
2454 (defun widget-face-value-create (widget)
2455 ;; Create a `custom-face' child.
2456 (let* ((symbol (widget-value widget
))
2457 (custom-buffer-style 'face
)
2458 (child (widget-create-child-and-convert
2462 (custom-magic-reset child
)
2463 (setq custom-options
(cons child custom-options
))
2464 (widget-put widget
:children
(list child
))))
2466 (defun widget-face-value-delete (widget)
2467 ;; Remove the child from the options.
2468 (let ((child (car (widget-get widget
:children
))))
2469 (setq custom-options
(delq child custom-options
))
2470 (widget-children-value-delete widget
)))
2472 (defvar face-history nil
2473 "History of entered face names.")
2475 (defun widget-face-action (widget &optional event
)
2476 "Prompt for a face."
2477 (let ((answer (completing-read "Face: "
2478 (mapcar (lambda (face)
2479 (list (symbol-name face
)))
2483 (unless (zerop (length answer
))
2484 (widget-value-set widget
(intern answer
))
2485 (widget-apply widget
:notify widget event
)
2488 ;;; The `hook' Widget.
2490 (define-widget 'hook
'list
2492 :value-to-internal
(lambda (widget value
)
2496 :match
(lambda (widget value
)
2498 (widget-editable-list-match widget value
)))
2499 :convert-widget
'custom-hook-convert-widget
2502 (defun custom-hook-convert-widget (widget)
2503 ;; Handle `:custom-options'.
2504 (let* ((options (widget-get widget
:options
))
2505 (other `(editable-list :inline t
2506 :entry-format
"%i %d%v"
2507 (function :format
" %v")))
2509 (list `(checklist :inline t
2510 ,@(mapcar (lambda (entry)
2511 `(function-item ,entry
))
2515 (widget-put widget
:args args
)
2518 ;;; The `custom-group-link' Widget.
2520 (define-widget 'custom-group-link
'link
2521 "Show parent in other window when activated."
2522 :help-echo
"Create customization buffer for this group."
2523 :action
'custom-group-link-action
)
2525 (defun custom-group-link-action (widget &rest ignore
)
2526 (customize-group (widget-value widget
)))
2528 ;;; The `custom-group' Widget.
2530 (defcustom custom-group-tag-faces nil
2531 ;; In XEmacs, this ought to play games with font size.
2532 "Face used for group tags.
2533 The first member is used for level 1 groups, the second for level 2,
2534 and so forth. The remaining group tags are shown with
2535 `custom-group-tag-face'."
2536 :type
'(repeat face
)
2537 :group
'custom-faces
)
2539 (defface custom-group-tag-face-1
'((((class color
)
2541 (:foreground
"pink" :underline t
))
2544 (:foreground
"red" :underline t
))
2546 "Face used for group tags.")
2548 (defface custom-group-tag-face
'((((class color
)
2550 (:foreground
"light blue" :underline t
))
2553 (:foreground
"blue" :underline t
))
2555 "Face used for low level group tags."
2556 :group
'custom-faces
)
2558 (define-widget 'custom-group
'custom
2561 :sample-face-get
'custom-group-sample-face-get
2562 :documentation-property
'group-documentation
2563 :help-echo
"Set or reset all members of this group."
2564 :value-create
'custom-group-value-create
2565 :action
'custom-group-action
2566 :custom-category
'group
2567 :custom-set
'custom-group-set
2568 :custom-save
'custom-group-save
2569 :custom-reset-current
'custom-group-reset-current
2570 :custom-reset-saved
'custom-group-reset-saved
2571 :custom-reset-standard
'custom-group-reset-standard
2572 :custom-menu
'custom-group-menu-create
)
2574 (defun custom-group-sample-face-get (widget)
2575 ;; Use :sample-face.
2576 (or (nth (1- (widget-get widget
:custom-level
)) custom-group-tag-faces
)
2577 'custom-group-tag-face
))
2579 (define-widget 'custom-group-visibility
'visibility
2580 "An indicator and manipulator for hidden group contents."
2581 :create
'custom-group-visibility-create
)
2583 (defun custom-group-visibility-create (widget)
2584 (let ((visible (widget-value widget
)))
2586 (insert "--------")))
2587 (widget-default-create widget
))
2589 (defun custom-group-members (symbol groups-only
)
2590 "Return SYMBOL's custom group members.
2591 If GROUPS-ONLY non-nil, return only those members that are groups."
2592 (if (not groups-only
)
2593 (get symbol
'custom-group
)
2595 (dolist (entry (get symbol
'custom-group
))
2596 (when (eq (nth 1 entry
) 'custom-group
)
2597 (push entry members
)))
2598 (nreverse members
))))
2600 (defun custom-group-value-create (widget)
2601 "Insert a customize group for WIDGET in the current buffer."
2602 (let* ((state (widget-get widget
:custom-state
))
2603 (level (widget-get widget
:custom-level
))
2604 ;; (indent (widget-get widget :indent))
2605 (prefix (widget-get widget
:custom-prefix
))
2606 (buttons (widget-get widget
:buttons
))
2607 (tag (widget-get widget
:tag
))
2608 (symbol (widget-value widget
))
2609 (members (custom-group-members symbol
2610 (and (eq custom-buffer-style
'tree
)
2611 custom-browse-only-groups
))))
2612 (cond ((and (eq custom-buffer-style
'tree
)
2614 (or members
(custom-unloaded-widget-p widget
)))
2615 (custom-browse-insert-prefix prefix
)
2616 (push (widget-create-child-and-convert
2617 widget
'custom-browse-visibility
2618 ;; :tag-glyph "plus"
2622 ;; (widget-glyph-insert nil "-- " "horizontal")
2623 (push (widget-create-child-and-convert
2624 widget
'custom-browse-group-tag
)
2626 (insert " " tag
"\n")
2627 (widget-put widget
:buttons buttons
))
2628 ((and (eq custom-buffer-style
'tree
)
2629 (zerop (length members
)))
2630 (custom-browse-insert-prefix prefix
)
2632 ;; (widget-glyph-insert nil "[ ]" "empty")
2633 ;; (widget-glyph-insert nil "-- " "horizontal")
2634 (push (widget-create-child-and-convert
2635 widget
'custom-browse-group-tag
)
2637 (insert " " tag
"\n")
2638 (widget-put widget
:buttons buttons
))
2639 ((eq custom-buffer-style
'tree
)
2640 (custom-browse-insert-prefix prefix
)
2641 (custom-load-widget widget
)
2642 (if (zerop (length members
))
2644 (custom-browse-insert-prefix prefix
)
2646 ;; (widget-glyph-insert nil "[ ]" "empty")
2647 ;; (widget-glyph-insert nil "-- " "horizontal")
2648 (push (widget-create-child-and-convert
2649 widget
'custom-browse-group-tag
)
2651 (insert " " tag
"\n")
2652 (widget-put widget
:buttons buttons
))
2653 (push (widget-create-child-and-convert
2654 widget
'custom-browse-visibility
2655 ;; :tag-glyph "minus"
2659 ;; (widget-glyph-insert nil "-\\ " "top")
2660 (push (widget-create-child-and-convert
2661 widget
'custom-browse-group-tag
)
2663 (insert " " tag
"\n")
2664 (widget-put widget
:buttons buttons
)
2665 (message "Creating group...")
2666 (let* ((members (custom-sort-items members
2667 custom-browse-sort-alphabetically
2668 custom-browse-order-groups
))
2669 (prefixes (widget-get widget
:custom-prefixes
))
2670 (custom-prefix-list (custom-prefix-add symbol prefixes
))
2671 (extra-prefix (if (widget-get widget
:custom-last
)
2674 (prefix (concat prefix extra-prefix
))
2677 (setq entry
(car members
)
2678 members
(cdr members
))
2679 (push (widget-create-child-and-convert
2680 widget
(nth 1 entry
)
2682 :tag
(custom-unlispify-tag-name (nth 0 entry
))
2683 :custom-prefixes custom-prefix-list
2684 :custom-level
(1+ level
)
2685 :custom-last
(null members
)
2686 :value
(nth 0 entry
)
2687 :custom-prefix prefix
)
2689 (widget-put widget
:children
(reverse children
)))
2690 (message "Creating group...done")))
2693 ;; Create level indicator.
2694 (unless (eq custom-buffer-style
'links
)
2695 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
2698 (let ((begin (point)))
2700 (widget-specify-sample widget begin
(point)))
2702 ;; Create link/visibility indicator.
2703 (if (eq custom-buffer-style
'links
)
2704 (push (widget-create-child-and-convert
2705 widget
'custom-group-link
2709 (push (widget-create-child-and-convert
2710 widget
'group-visibility
2711 :help-echo
"Show members of this group."
2712 :action
'custom-toggle-parent
2713 (not (eq state
'hidden
)))
2716 ;; Create magic button.
2717 (let ((magic (widget-create-child-and-convert
2718 widget
'custom-magic nil
)))
2719 (widget-put widget
:custom-magic magic
)
2720 (push magic buttons
))
2722 (widget-put widget
:buttons buttons
)
2723 ;; Insert documentation.
2724 (if (and (eq custom-buffer-style
'links
) (> level
1))
2725 (widget-put widget
:documentation-indent
0))
2726 (widget-default-format-handler widget ?h
))
2729 ;; Add parent groups references above the group.
2730 (if t
;;; This should test that the buffer
2731 ;;; was made to display a group.
2733 (if (custom-add-parent-links widget
2734 "Go to parent group:")
2736 ;; Create level indicator.
2737 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
2740 (let ((start (point)))
2742 (widget-specify-sample widget start
(point)))
2744 ;; Create visibility indicator.
2745 (unless (eq custom-buffer-style
'links
)
2747 (push (widget-create-child-and-convert
2749 :help-echo
"Hide members of this group."
2750 :action
'custom-toggle-parent
2751 (not (eq state
'hidden
)))
2754 ;; Create more dashes.
2755 ;; Use 76 instead of 75 to compensate for the temporary "<"
2756 ;; added by `widget-insert'.
2757 (insert-char ?-
(- 76 (current-column)
2758 (* custom-buffer-indent level
)))
2760 ;; Create magic button.
2761 (let ((magic (widget-create-child-and-convert
2762 widget
'custom-magic
2765 (widget-put widget
:custom-magic magic
)
2766 (push magic buttons
))
2768 (widget-put widget
:buttons buttons
)
2769 ;; Insert documentation.
2770 (widget-default-format-handler widget ?h
)
2772 (if nil
;;; This should test that the buffer
2773 ;;; was not made to display a group.
2775 (insert-char ?\ custom-buffer-indent
)
2776 (custom-add-parent-links widget
)))
2777 (custom-add-see-also widget
2778 (make-string (* custom-buffer-indent level
)
2781 (message "Creating group...")
2782 (custom-load-widget widget
)
2783 (let* ((members (custom-sort-items members
2784 custom-buffer-sort-alphabetically
2785 custom-buffer-order-groups
))
2786 (prefixes (widget-get widget
:custom-prefixes
))
2787 (custom-prefix-list (custom-prefix-add symbol prefixes
))
2788 (length (length members
))
2790 (children (mapcar (lambda (entry)
2791 (widget-insert "\n")
2793 Creating group members... %2d%%"
2794 (/ (* 100.0 count
) length
))
2795 (setq count
(1+ count
))
2797 (widget-create-child-and-convert
2798 widget
(nth 1 entry
)
2800 :tag
(custom-unlispify-tag-name
2802 :custom-prefixes custom-prefix-list
2803 :custom-level
(1+ level
)
2804 :value
(nth 0 entry
))
2805 (unless (eq (preceding-char) ?
\n)
2806 (widget-insert "\n"))))
2808 (message "Creating group magic...")
2809 (mapcar 'custom-magic-reset children
)
2810 (message "Creating group state...")
2811 (widget-put widget
:children children
)
2812 (custom-group-state-update widget
)
2813 (message "Creating group... done"))
2816 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
2817 (insert "\\- " (widget-get widget
:tag
) " group end ")
2818 (insert-char ?-
(- 75 (current-column) (* custom-buffer-indent level
)))
2821 (defvar custom-group-menu
2822 '(("Set for Current Session" custom-group-set
2824 (eq (widget-get widget
:custom-state
) 'modified
)))
2825 ("Save for Future Sessions" custom-group-save
2827 (memq (widget-get widget
:custom-state
) '(modified set
))))
2828 ("Reset to Current" custom-group-reset-current
2830 (memq (widget-get widget
:custom-state
) '(modified))))
2831 ("Reset to Saved" custom-group-reset-saved
2833 (memq (widget-get widget
:custom-state
) '(modified set
))))
2834 ("Reset to standard setting" custom-group-reset-standard
2836 (memq (widget-get widget
:custom-state
) '(modified set saved
)))))
2837 "Alist of actions for the `custom-group' widget.
2838 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2839 the menu entry, ACTION is the function to call on the widget when the
2840 menu is selected, and FILTER is a predicate which takes a `custom-group'
2841 widget as an argument, and returns non-nil if ACTION is valid on that
2842 widget. If FILTER is nil, ACTION is always valid.")
2844 (defun custom-group-action (widget &optional event
)
2845 "Show the menu for `custom-group' WIDGET.
2846 Optional EVENT is the location for the menu."
2847 (if (eq (widget-get widget
:custom-state
) 'hidden
)
2848 (custom-toggle-hide widget
)
2849 (let* ((completion-ignore-case t
)
2850 (answer (widget-choose (concat "Operation on "
2851 (custom-unlispify-tag-name
2852 (widget-get widget
:value
)))
2853 (custom-menu-filter custom-group-menu
2857 (funcall answer widget
)))))
2859 (defun custom-group-set (widget)
2860 "Set changes in all modified group members."
2861 (let ((children (widget-get widget
:children
)))
2862 (mapcar (lambda (child)
2863 (when (eq (widget-get child
:custom-state
) 'modified
)
2864 (widget-apply child
:custom-set
)))
2867 (defun custom-group-save (widget)
2868 "Save all modified group members."
2869 (let ((children (widget-get widget
:children
)))
2870 (mapcar (lambda (child)
2871 (when (memq (widget-get child
:custom-state
) '(modified set
))
2872 (widget-apply child
:custom-save
)))
2875 (defun custom-group-reset-current (widget)
2876 "Reset all modified group members."
2877 (let ((children (widget-get widget
:children
)))
2878 (mapcar (lambda (child)
2879 (when (eq (widget-get child
:custom-state
) 'modified
)
2880 (widget-apply child
:custom-reset-current
)))
2883 (defun custom-group-reset-saved (widget)
2884 "Reset all modified or set group members."
2885 (let ((children (widget-get widget
:children
)))
2886 (mapcar (lambda (child)
2887 (when (memq (widget-get child
:custom-state
) '(modified set
))
2888 (widget-apply child
:custom-reset-saved
)))
2891 (defun custom-group-reset-standard (widget)
2892 "Reset all modified, set, or saved group members."
2893 (let ((children (widget-get widget
:children
)))
2894 (mapcar (lambda (child)
2895 (when (memq (widget-get child
:custom-state
)
2896 '(modified set saved
))
2897 (widget-apply child
:custom-reset-standard
)))
2900 (defun custom-group-state-update (widget)
2902 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
2903 (let* ((children (widget-get widget
:children
))
2904 (states (mapcar (lambda (child)
2905 (widget-get child
:custom-state
))
2907 (magics custom-magic-alist
)
2910 (let ((magic (car (car magics
))))
2911 (if (and (not (eq magic
'hidden
))
2912 (memq magic states
))
2915 (setq magics
(cdr magics
)))))
2916 (widget-put widget
:custom-state found
)))
2917 (custom-magic-reset widget
))
2919 ;;; The `custom-save-all' Function.
2921 (defcustom custom-file nil
2922 "File used for storing customization information.
2923 The default is nil, which means to use your init file
2924 as specified by `user-init-file'. If you specify some other file,
2925 you need to explicitly load that file for the settings to take effect."
2926 :type
'(choice (const :tag
"Your Emacs init file" nil
) file
)
2929 (defun custom-save-delete (symbol)
2930 "Delete the call to SYMBOL form `custom-file'.
2931 Leave point at the location of the call, or after the last expression."
2932 (set-buffer (find-file-noselect (or custom-file user-init-file
)))
2933 (goto-char (point-min))
2936 (let ((sexp (condition-case nil
2937 (read (current-buffer))
2938 (end-of-file (throw 'found nil
)))))
2939 (when (and (listp sexp
)
2940 (eq (car sexp
) symbol
))
2941 (delete-region (save-excursion
2945 (throw 'found nil
))))))
2947 (defun custom-save-variables ()
2948 "Save all customized variables in `custom-file'."
2950 (custom-save-delete 'custom-set-variables
)
2951 (let ((standard-output (current-buffer)))
2954 (princ "(custom-set-variables")
2955 (mapatoms (lambda (symbol)
2956 (let ((value (get symbol
'saved-value
))
2957 (requests (get symbol
'custom-requests
))
2958 (now (not (or (get symbol
'standard-value
)
2959 (and (not (boundp symbol
))
2960 (not (get symbol
'force-value
)))))))
2977 (unless (looking-at "\n")
2980 (defun custom-save-faces ()
2981 "Save all customized faces in `custom-file'."
2983 (custom-save-delete 'custom-set-faces
)
2984 (let ((standard-output (current-buffer)))
2987 (princ "(custom-set-faces")
2988 (let ((value (get 'default
'saved-face
)))
2989 ;; The default face must be first, since it affects the others.
2991 (princ "\n '(default ")
2993 (if (or (get 'default
'face-defface-spec
)
2994 (and (not (custom-facep 'default
))
2995 (not (get 'default
'force-face
))))
2998 (mapatoms (lambda (symbol)
2999 (let ((value (get symbol
'saved-face
)))
3000 (when (and (not (eq symbol
'default
))
3001 ;; Don't print default face here.
3007 (if (or (get symbol
'face-defface-spec
)
3008 (and (not (custom-facep symbol
))
3009 (not (get symbol
'force-face
))))
3013 (unless (looking-at "\n")
3017 (defun customize-save-customized ()
3018 "Save all user options which have been set in this session."
3020 (mapatoms (lambda (symbol)
3021 (let ((face (get symbol
'customized-face
))
3022 (value (get symbol
'customized-value
)))
3024 (put symbol
'saved-face face
)
3025 (put symbol
'customized-face nil
))
3027 (put symbol
'saved-value value
)
3028 (put symbol
'customized-value nil
)))))
3029 ;; We really should update all custom buffers here.
3033 (defun custom-save-all ()
3034 "Save all customizations in `custom-file'."
3035 (let ((inhibit-read-only t
))
3036 (custom-save-variables)
3039 (set-buffer (find-file-noselect (or custom-file user-init-file
)))
3042 ;;; The Customize Menu.
3046 (defcustom custom-menu-nesting
2
3047 "Maximum nesting in custom menus."
3049 :group
'custom-menu
)
3051 (defun custom-face-menu-create (widget symbol
)
3052 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
3053 (vector (custom-unlispify-menu-entry symbol
)
3054 `(customize-face ',symbol
)
3057 (defun custom-variable-menu-create (widget symbol
)
3058 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
3059 (let ((type (get symbol
'custom-type
)))
3060 (unless (listp type
)
3061 (setq type
(list type
)))
3062 (if (and type
(widget-get type
:custom-menu
))
3063 (widget-apply type
:custom-menu symbol
)
3064 (vector (custom-unlispify-menu-entry symbol
)
3065 `(customize-variable ',symbol
)
3068 ;; Add checkboxes to boolean variable entries.
3069 (widget-put (get 'boolean
'widget-type
)
3070 :custom-menu
(lambda (widget symbol
)
3071 (vector (custom-unlispify-menu-entry symbol
)
3072 `(customize-variable ',symbol
)
3074 ':selected symbol
)))
3076 (if (string-match "XEmacs" emacs-version
)
3077 ;; XEmacs can create menus dynamically.
3078 (defun custom-group-menu-create (widget symbol
)
3079 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
3080 `( ,(custom-unlispify-menu-entry symbol t
)
3081 :filter
(lambda (&rest junk
)
3082 (cdr (custom-menu-create ',symbol
)))))
3084 (defun custom-group-menu-create (widget symbol
)
3085 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
3086 ;; Limit the nesting.
3087 (let ((custom-menu-nesting (1- custom-menu-nesting
)))
3088 (custom-menu-create symbol
))))
3091 (defun custom-menu-create (symbol)
3092 "Create menu for customization group SYMBOL.
3093 The menu is in a format applicable to `easy-menu-define'."
3094 (let* ((item (vector (custom-unlispify-menu-entry symbol
)
3095 `(customize-group ',symbol
)
3097 (if (and (or (not (boundp 'custom-menu-nesting
))
3098 (>= custom-menu-nesting
0))
3099 (< (length (get symbol
'custom-group
)) widget-menu-max-size
))
3100 (let ((custom-prefix-list (custom-prefix-add symbol
3101 custom-prefix-list
))
3102 (members (custom-sort-items (get symbol
'custom-group
)
3103 custom-menu-sort-alphabetically
3104 custom-menu-order-groups
)))
3105 (custom-load-symbol symbol
)
3106 `(,(custom-unlispify-menu-entry symbol t
)
3109 ,@(mapcar (lambda (entry)
3110 (widget-apply (if (listp (nth 1 entry
))
3112 (list (nth 1 entry
)))
3113 :custom-menu
(nth 0 entry
)))
3118 (defun customize-menu-create (symbol &optional name
)
3119 "Return a customize menu for customization group SYMBOL.
3120 If optional NAME is given, use that as the name of the menu.
3121 Otherwise the menu will be named `Customize'.
3122 The format is suitable for use with `easy-menu-define'."
3124 (setq name
"Customize"))
3125 (if (string-match "XEmacs" emacs-version
)
3126 ;; We can delay it under XEmacs.
3128 :filter
(lambda (&rest junk
)
3129 (cdr (custom-menu-create ',symbol
))))
3130 ;; But we must create it now under Emacs.
3131 (cons name
(cdr (custom-menu-create symbol
)))))
3133 ;;; The Custom Mode.
3135 (defvar custom-mode-map nil
3136 "Keymap for `custom-mode'.")
3138 (unless custom-mode-map
3139 (setq custom-mode-map
(make-sparse-keymap))
3140 (set-keymap-parent custom-mode-map widget-keymap
)
3141 (suppress-keymap custom-mode-map
)
3142 (define-key custom-mode-map
" " 'scroll-up
)
3143 (define-key custom-mode-map
"\177" 'scroll-down
)
3144 (define-key custom-mode-map
"q" 'bury-buffer
)
3145 (define-key custom-mode-map
"u" 'Custom-goto-parent
)
3146 (define-key custom-mode-map
"n" 'widget-forward
)
3147 (define-key custom-mode-map
"p" 'widget-backward
)
3148 (define-key custom-mode-map
[mouse-1
] 'Custom-move-and-invoke
))
3150 (defun Custom-move-and-invoke (event)
3151 "Move to where you click, and if it is an active field, invoke it."
3153 (mouse-set-point event
)
3154 (if (widget-event-point event
)
3155 (let* ((pos (widget-event-point event
))
3156 (button (get-char-property pos
'button
)))
3158 (widget-button-click event
)))))
3160 (easy-menu-define Custom-mode-menu
3162 "Menu used in customization buffers."
3164 ,(customize-menu-create 'customize
)
3165 ["Set" Custom-set t
]
3166 ["Save" Custom-save t
]
3167 ["Reset to Current" Custom-reset-current t
]
3168 ["Reset to Saved" Custom-reset-saved t
]
3169 ["Reset to Standard Settings" Custom-reset-standard t
]
3170 ["Info" (Info-goto-node "(custom)The Customization Buffer") t
]))
3172 (defun Custom-goto-parent ()
3173 "Go to the parent group listed at the top of this buffer.
3174 If several parents are listed, go to the first of them."
3177 (goto-char (point-min))
3178 (if (search-forward "\nGo to parent group: " nil t
)
3179 (let* ((button (get-char-property (point) 'button
))
3180 (parent (downcase (widget-get button
:tag
))))
3181 (customize-group parent
)))))
3183 (defcustom custom-mode-hook nil
3184 "Hook called when entering custom-mode."
3186 :group
'custom-buffer
)
3188 (defun custom-state-buffer-message (widget)
3189 (if (eq (widget-get (widget-get widget
:parent
) :custom-state
) 'modified
)
3190 (message "To install your edits, invoke [State] and choose the Set operation")))
3192 (defun custom-mode ()
3193 "Major mode for editing customization buffers.
3195 The following commands are available:
3197 Move to next button or editable field. \\[widget-forward]
3198 Move to previous button or editable field. \\[widget-backward]
3199 \\<widget-field-keymap>\
3200 Complete content of editable text field. \\[widget-complete]
3201 \\<custom-mode-map>\
3202 Invoke button under the mouse pointer. \\[Custom-move-and-invoke]
3203 Invoke button under point. \\[widget-button-press]
3204 Set all modifications. \\[Custom-set]
3205 Make all modifications default. \\[Custom-save]
3206 Reset all modified options. \\[Custom-reset-current]
3207 Reset all modified or set options. \\[Custom-reset-saved]
3208 Reset all options. \\[Custom-reset-standard]
3210 Entry to this mode calls the value of `custom-mode-hook'
3211 if that value is non-nil."
3212 (kill-all-local-variables)
3213 (setq major-mode
'custom-mode
3215 (use-local-map custom-mode-map
)
3216 (easy-menu-add Custom-mode-menu
)
3217 (make-local-variable 'custom-options
)
3218 (make-local-variable 'widget-documentation-face
)
3219 (setq widget-documentation-face
'custom-documentation-face
)
3220 (make-local-variable 'widget-button-face
)
3221 (setq widget-button-face
'custom-button-face
)
3222 (make-local-hook 'widget-edit-functions
)
3223 (add-hook 'widget-edit-functions
'custom-state-buffer-message nil t
)
3224 (run-hooks 'custom-mode-hook
))
3230 ;; cus-edit.el ends here