1 ;;; cus-edit.el --- Tools for customizating Emacs and Lisp packages.
3 ;; Copyright (C) 1996, 1997 Free Software Foundation, Inc.
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
6 ;; Keywords: help, faces
8 ;; X-URL: http://www.dina.kvl.dk/~abraham/custom/
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
29 ;; This file implements the code to create and edit customize buffers.
33 ;; No commands should have names starting with `custom-' because
34 ;; that interferes with completion. Use `customize-' for commands
35 ;; that the user will run with M-x, and `Custom-' for interactive commands.
42 (eval-when-compile (require 'cl
))
52 (define-widget-keywords :custom-last
:custom-prefix
:custom-category
53 :custom-prefixes
:custom-menu
55 :custom-magic
:custom-state
:custom-level
:custom-form
56 :custom-set
:custom-save
:custom-reset-current
:custom-reset-saved
57 :custom-reset-standard
)
59 (put 'custom-define-hook
'custom-type
'hook
)
60 (put 'custom-define-hook
'standard-value
'(nil))
61 (custom-add-to-group 'customize
'custom-define-hook
'custom-variable
)
63 ;;; Customization Groups.
66 "Customization of the One True Editor."
67 :link
'(custom-manual "(emacs)Top"))
69 ;; Most of these groups are stolen from `finder.el',
71 "Basic text editing facilities."
75 "Abbreviation handling, typing shortcuts, macros."
79 (defgroup matching nil
80 "Various sorts of searching and matching."
83 (defgroup emulations nil
84 "Emulations of other editors."
91 (defgroup outlines nil
92 "Support for hierarchical outlining."
95 (defgroup external nil
96 "Interfacing to external utilities."
100 "Code related to the `bib' bibliography processor."
104 (defgroup processes nil
105 "Process, subshell, compilation, and job control support."
109 (defgroup convenience nil
110 "Convenience features for faster editing."
113 (defgroup programming nil
114 "Support for programming in other languages."
117 (defgroup languages nil
118 "Specialized modes for editing programming languages."
122 "Lisp support, including Emacs Lisp."
127 "Support for the C language and related languages."
135 "Support for object-oriented programming."
138 (defgroup applications nil
139 "Applications written in Emacs."
142 (defgroup calendar nil
143 "Calendar and time management support."
144 :group
'applications
)
147 "Modes for electronic-mail handling."
148 :group
'applications
)
151 "Support for netnews reading and posting."
152 :group
'applications
)
155 "Games, jokes and amusements."
156 :group
'applications
)
158 (defgroup development nil
159 "Support for further development of Emacs."
163 "Support for Emacs documentation."
166 (defgroup extensions nil
167 "Emacs Lisp language extensions."
170 (defgroup internal nil
171 "Code for Emacs internals, build process, defaults."
175 "Maintenance aids for the Emacs development group."
179 (defgroup environment nil
180 "Fitting Emacs with its environment."
184 "Communications, networking, remote access to files."
188 (defgroup hardware nil
189 "Support for interfacing with exotic hardware."
192 (defgroup terminals nil
193 "Support for terminal types."
197 "Front-ends/assistants for, or emulators of, UNIX features."
201 "Support code for vms."
205 "Internationalization and alternate character-set support."
210 "The X Window system."
214 "Support for Emacs frames and window systems."
218 "Support editing files of data."
222 "Support editing files."
230 "Code related to the TeX formatter."
234 "Support for multiple fonts."
237 (defgroup hypermedia nil
238 "Support for links between text or other media types."
242 "Support for on-line help systems."
246 "Code local to your site."
249 (defgroup customize
'((widgets custom-group
))
250 "Customization of the Customization support."
251 :link
'(custom-manual "(custom)Top")
252 :link
'(url-link :tag
"Development Page"
253 "http://www.dina.kvl.dk/~abraham/custom/")
257 (defgroup custom-faces nil
258 "Faces used by customize."
262 (defgroup custom-browse nil
263 "Control customize browser."
267 (defgroup custom-buffer nil
268 "Control customize buffers."
272 (defgroup custom-menu nil
273 "Control customize menus."
277 (defgroup abbrev-mode nil
278 "Word abbreviations mode."
282 "Storage allocation and gc for GNU Emacs Lisp interpreter."
283 :tag
"Storage Allocation"
287 "Undoing changes in buffers."
290 (defgroup modeline nil
291 "Content of the modeline."
295 "Indenting and filling text."
298 (defgroup editing-basics nil
299 "Most basic editing facilities."
302 (defgroup display nil
303 "How characters are displayed in buffers."
306 (defgroup execute nil
307 "Executing external commands."
310 (defgroup installation nil
311 "The Emacs installation."
319 "Internal Emacs limits."
323 "Debugging Emacs itself."
326 (defgroup minibuffer nil
327 "Controling the behaviour of the minibuffer."
330 (defgroup keyboard nil
331 "Input from the keyboard."
335 "Input from the mouse."
339 "Input from the menus."
342 (defgroup auto-save nil
343 "Preventing accidential loss of data."
346 (defgroup processes-basics nil
347 "Basic stuff dealing with processes."
351 "MULE Emacs internationalization."
354 (defgroup windows nil
355 "Windows within a frame."
360 (defun custom-last (x &optional n
)
361 ;; Stolen from `cl.el'.
362 "Returns the last link in the list LIST.
363 With optional argument N, returns Nth-to-last link (default 1)."
366 (while (consp p
) (incf m
) (pop p
))
368 (if (< n m
) (nthcdr (- m n
) x
) x
)))
369 (while (consp (cdr x
)) (pop x
))
372 (defun custom-quote (sexp)
373 "Quote SEXP iff it is not self quoting."
374 (if (or (memq sexp
'(t nil
))
376 (eq (aref (symbol-name sexp
) 0) ?
:))
378 (memq (car sexp
) '(lambda)))
381 (and (fboundp 'characterp
)
386 (defun custom-split-regexp-maybe (regexp)
387 "If REGEXP is a string, split it to a list at `\\|'.
388 You can get the original back with from the result with:
389 (mapconcat 'identity result \"\\|\")
391 IF REGEXP is not a string, return it unchanged."
395 (while (string-match "\\\\|" regexp start
)
396 (setq all
(cons (substring regexp start
(match-beginning 0)) all
)
397 start
(match-end 0)))
398 (nreverse (cons (substring regexp start
) all
)))
401 (defun custom-variable-prompt ()
402 ;; Code stolen from `help.el'.
403 "Prompt for a variable, defaulting to the variable at point.
404 Return a list suitable for use in `interactive'."
405 (let ((v (variable-at-point))
406 (enable-recursive-minibuffers t
)
408 (setq val
(completing-read
410 (format "Customize option: (default %s) " v
)
411 "Customize variable: ")
412 obarray
(lambda (symbol)
414 (or (get symbol
'custom-type
)
415 (user-variable-p symbol
)))) t
))
416 (list (if (equal val
"")
417 (if (symbolp v
) v nil
)
420 (defun custom-menu-filter (menu widget
)
421 "Convert MENU to the form used by `widget-choose'.
422 MENU should be in the same format as `custom-variable-menu'.
423 WIDGET is the widget to apply the filter entries of MENU on."
425 current name action filter
)
427 (setq current
(car menu
)
429 action
(nth 1 current
)
430 filter
(nth 2 current
)
432 (if (or (null filter
) (funcall filter widget
))
433 (push (cons name action
) result
)
439 (defvar custom-prefix-list nil
440 "List of prefixes that should be ignored by `custom-unlispify'")
442 (defcustom custom-unlispify-menu-entries t
443 "Display menu entries as words instead of symbols if non nil."
447 (defcustom custom-unlispify-remove-prefixes nil
448 "Non-nil means remove group prefixes from option names in buffer."
452 (defun custom-unlispify-menu-entry (symbol &optional no-suffix
)
453 "Convert symbol into a menu entry."
454 (cond ((not custom-unlispify-menu-entries
)
455 (symbol-name symbol
))
456 ((get symbol
'custom-tag
)
458 (get symbol
'custom-tag
)
459 (concat (get symbol
'custom-tag
) "...")))
462 (set-buffer (get-buffer-create " *Custom-Work*"))
464 (princ symbol
(current-buffer))
465 (goto-char (point-min))
466 (when (and (eq (get symbol
'custom-type
) 'boolean
)
467 (re-search-forward "-p\\'" nil t
))
468 (replace-match "" t t
)
469 (goto-char (point-min)))
470 (if custom-unlispify-remove-prefixes
471 (let ((prefixes custom-prefix-list
)
474 (setq prefix
(car prefixes
))
475 (if (search-forward prefix
(+ (point) (length prefix
)) t
)
478 (delete-region (point-min) (point)))
479 (setq prefixes
(cdr prefixes
))))))
480 (subst-char-in-region (point-min) (point-max) ?- ?\ t
)
481 (capitalize-region (point-min) (point-max))
483 (goto-char (point-max))
487 (defcustom custom-unlispify-tag-names t
488 "Display tag names as words instead of symbols if non nil."
489 :group
'custom-buffer
492 (defun custom-unlispify-tag-name (symbol)
493 "Convert symbol into a menu entry."
494 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names
))
495 (custom-unlispify-menu-entry symbol t
)))
497 (defun custom-prefix-add (symbol prefixes
)
498 ;; Addd SYMBOL to list of ignored PREFIXES.
499 (cons (or (get symbol
'custom-prefix
)
500 (concat (symbol-name symbol
) "-"))
505 (defcustom custom-guess-name-alist
510 ("-function\\'" function
)
511 ("-functions\\'" (repeat function
))
512 ("-list\\'" (repeat sexp
))
513 ("-alist\\'" (repeat (cons sexp sexp
))))
514 "Alist of (MATCH TYPE).
516 MATCH should be a regexp matching the name of a symbol, and TYPE should
517 be a widget suitable for editing the value of that symbol. The TYPE
518 of the first entry where MATCH matches the name of the symbol will be
521 This is used for guessing the type of variables not declared with
523 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
526 (defcustom custom-guess-doc-alist
527 '(("\\`\\*?Non-nil " boolean
))
528 "Alist of (MATCH TYPE).
530 MATCH should be a regexp matching a documentation string, and TYPE
531 should be a widget suitable for editing the value of a variable with
532 that documentation string. The TYPE of the first entry where MATCH
533 matches the name of the symbol will be used.
535 This is used for guessing the type of variables not declared with
537 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
540 (defun custom-guess-type (symbol)
541 "Guess a widget suitable for editing the value of SYMBOL.
542 This is done by matching SYMBOL with `custom-guess-name-alist' and
543 if that fails, the doc string with `custom-guess-doc-alist'."
544 (let ((name (symbol-name symbol
))
545 (names custom-guess-name-alist
)
548 (setq current
(car names
)
550 (when (string-match (nth 0 current
) name
)
551 (setq found
(nth 1 current
)
554 (let ((doc (documentation-property symbol
'variable-documentation
))
555 (docs custom-guess-doc-alist
))
558 (setq current
(car docs
)
560 (when (string-match (nth 0 current
) doc
)
561 (setq found
(nth 1 current
)
567 (defcustom custom-browse-sort-alphabetically nil
568 "If non-nil, sort members of each customization group alphabetically."
570 :group
'custom-browse
)
572 (defcustom custom-browse-order-groups nil
573 "If non-nil, order group members within each customization group.
574 If `first', order groups before non-groups.
575 If `last', order groups after non-groups."
576 :type
'(choice (const first
)
578 (const :tag
"none" nil
))
579 :group
'custom-browse
)
581 (defcustom custom-browse-only-groups nil
582 "If non-nil, show group members only within each customization group."
584 :group
'custom-browse
)
586 (defcustom custom-buffer-sort-alphabetically nil
587 "If non-nil, sort members of each customization group alphabetically."
589 :group
'custom-buffer
)
591 (defcustom custom-buffer-order-groups
'last
592 "If non-nil, order group members within each customization group.
593 If `first', order groups before non-groups.
594 If `last', order groups after non-groups."
595 :type
'(choice (const first
)
597 (const :tag
"none" nil
))
598 :group
'custom-buffer
)
600 (defcustom custom-menu-sort-alphabetically nil
601 "If non-nil, sort members of each customization group alphabetically."
605 (defcustom custom-menu-order-groups
'first
606 "If non-nil, order group members within each customization group.
607 If `first', order groups before non-groups.
608 If `last', order groups after non-groups."
609 :type
'(choice (const first
)
611 (const :tag
"none" nil
))
614 ;;;###autoload (add-hook 'same-window-regexps "\\`\\*Customiz.*\\*\\'")
616 (defun custom-sort-items (items sort-alphabetically order-groups
)
617 "Return a sorted copy of ITEMS.
618 ITEMS should be a `custom-group' property.
619 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
620 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
621 groups after non-groups, if nil do not order groups at all."
622 (sort (copy-sequence items
)
624 (let ((typea (nth 1 a
)) (typeb (nth 1 b
))
625 (namea (symbol-name (nth 0 a
))) (nameb (symbol-name (nth 0 b
))))
626 (cond ((not order-groups
)
627 ;; Since we don't care about A and B order, maybe sort.
628 (when sort-alphabetically
629 (string-lessp namea nameb
)))
630 ((eq typea
'custom-group
)
631 ;; If B is also a group, maybe sort. Otherwise, order A and B.
632 (if (eq typeb
'custom-group
)
633 (when sort-alphabetically
634 (string-lessp namea nameb
))
635 (eq order-groups
'first
)))
636 ((eq typeb
'custom-group
)
637 ;; Since A cannot be a group, order A and B.
638 (eq order-groups
'last
))
640 ;; Since A and B cannot be groups, sort.
641 (string-lessp namea nameb
)))))))
643 ;;; Custom Mode Commands.
645 (defvar custom-options nil
646 "Customization widgets in the current buffer.")
649 "Set changes in all modified options."
651 (let ((children custom-options
))
652 (mapcar (lambda (child)
653 (when (eq (widget-get child
:custom-state
) 'modified
)
654 (widget-apply child
:custom-set
)))
657 (defun Custom-save ()
658 "Set all modified group members and save them."
660 (let ((children custom-options
))
661 (mapcar (lambda (child)
662 (when (memq (widget-get child
:custom-state
) '(modified set
))
663 (widget-apply child
:custom-save
)))
667 (defvar custom-reset-menu
668 '(("Current" . Custom-reset-current
)
669 ("Saved" . Custom-reset-saved
)
670 ("Standard Settings" . Custom-reset-standard
))
671 "Alist of actions for the `Reset' button.
672 The key is a string containing the name of the action, the value is a
673 lisp function taking the widget as an element which will be called
674 when the action is chosen.")
676 (defun custom-reset (event)
677 "Select item from reset menu."
678 (let* ((completion-ignore-case t
)
679 (answer (widget-choose "Reset to"
685 (defun Custom-reset-current (&rest ignore
)
686 "Reset all modified group members to their current value."
688 (let ((children custom-options
))
689 (mapcar (lambda (child)
690 (when (eq (widget-get child
:custom-state
) 'modified
)
691 (widget-apply child
:custom-reset-current
)))
694 (defun Custom-reset-saved (&rest ignore
)
695 "Reset all modified or set group members to their saved value."
697 (let ((children custom-options
))
698 (mapcar (lambda (child)
699 (when (eq (widget-get child
:custom-state
) 'modified
)
700 (widget-apply child
:custom-reset-saved
)))
703 (defun Custom-reset-standard (&rest ignore
)
704 "Reset all modified, set, or saved group members to their standard settings."
706 (let ((children custom-options
))
707 (mapcar (lambda (child)
708 (when (eq (widget-get child
:custom-state
) 'modified
)
709 (widget-apply child
:custom-reset-standard
)))
712 ;;; The Customize Commands
714 (defun custom-prompt-variable (prompt-var prompt-val
)
715 "Prompt for a variable and a value and return them as a list.
716 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
717 prompt for the value. The %s escape in PROMPT-VAL is replaced with
718 the name of the variable.
720 If the variable has a `variable-interactive' property, that is used as if
721 it were the arg to `interactive' (which see) to interactively read the value.
723 If the variable has a `custom-type' property, it must be a widget and the
724 `:prompt-value' property of that widget will be used for reading the value."
725 (let* ((var (read-variable prompt-var
))
726 (minibuffer-help-form '(describe-variable var
)))
728 (let ((prop (get var
'variable-interactive
))
729 (type (get var
'custom-type
))
730 (prompt (format prompt-val var
)))
732 (setq type
(list type
)))
734 ;; Use VAR's `variable-interactive' property
735 ;; as an interactive spec for prompting.
736 (call-interactively (list 'lambda
'(arg)
737 (list 'interactive prop
)
740 (widget-prompt-value type
746 (eval-minibuffer prompt
)))))))
749 (defun customize-set-value (var val
)
750 "Set VARIABLE to VALUE. VALUE is a Lisp object.
752 If VARIABLE has a `variable-interactive' property, that is used as if
753 it were the arg to `interactive' (which see) to interactively read the value.
755 If VARIABLE has a `custom-type' property, it must be a widget and the
756 `:prompt-value' property of that widget will be used for reading the value."
757 (interactive (custom-prompt-variable "Set variable: "
758 "Set %s to value: "))
763 (defun customize-set-variable (var val
)
764 "Set the default for VARIABLE to VALUE. VALUE is a Lisp object.
766 If VARIABLE has a `custom-set' property, that is used for setting
767 VARIABLE, otherwise `set-default' is used.
769 The `customized-value' property of the VARIABLE will be set to a list
770 with a quoted VALUE as its sole list member.
772 If VARIABLE has a `variable-interactive' property, that is used as if
773 it were the arg to `interactive' (which see) to interactively read the value.
775 If VARIABLE has a `custom-type' property, it must be a widget and the
776 `:prompt-value' property of that widget will be used for reading the value. "
777 (interactive (custom-prompt-variable "Set variable: "
778 "Set customized value for %s to: "))
779 (funcall (or (get var
'custom-set
) 'set-default
) var val
)
780 (put var
'customized-value
(list (custom-quote val
))))
783 (defun customize-save-variable (var val
)
784 "Set the default for VARIABLE to VALUE, and save it for future sessions.
785 If VARIABLE has a `custom-set' property, that is used for setting
786 VARIABLE, otherwise `set-default' is used.
788 The `customized-value' property of the VARIABLE will be set to a list
789 with a quoted VALUE as its sole list member.
791 If VARIABLE has a `variable-interactive' property, that is used as if
792 it were the arg to `interactive' (which see) to interactively read the value.
794 If VARIABLE has a `custom-type' property, it must be a widget and the
795 `:prompt-value' property of that widget will be used for reading the value. "
796 (interactive (custom-prompt-variable "Set and ave variable: "
797 "Set and save value for %s as: "))
798 (funcall (or (get var
'custom-set
) 'set-default
) var val
)
799 (put var
'saved-value
(list (custom-quote val
)))
804 "Select a customization buffer which you can use to set user options.
805 User options are structured into \"groups\".
806 Initially the top-level group `Emacs' and its immediate subgroups
807 are shown; the contents of those subgroups are initially hidden."
809 (customize-group 'emacs
))
812 (defun customize-group (group)
813 "Customize GROUP, which must be a customization group."
814 (interactive (list (let ((completion-ignore-case t
))
815 (completing-read "Customize group: (default emacs) "
818 (or (get symbol
'custom-loads
)
819 (get symbol
'custom-group
)))
821 (when (stringp group
)
822 (if (string-equal "" group
)
824 (setq group
(intern group
))))
825 (or (get group
'custom-group
)
826 (custom-load-symbol group
))
827 (let ((name (format "*Customize Group: %s*"
828 (custom-unlispify-tag-name group
))))
829 (if (get-buffer name
)
831 (custom-buffer-create (list (list group
'custom-group
))
833 (concat " for group "
834 (custom-unlispify-tag-name group
))))))
837 (defun customize-group-other-window (group)
838 "Customize GROUP, which must be a customization group."
839 (interactive (list (let ((completion-ignore-case t
))
840 (completing-read "Customize group: (default emacs) "
843 (or (get symbol
'custom-loads
)
844 (get symbol
'custom-group
)))
846 (when (stringp group
)
847 (if (string-equal "" group
)
849 (setq group
(intern group
))))
850 (or (get group
'custom-group
)
851 (custom-load-symbol group
))
852 (let ((name (format "*Customize Group: %s*"
853 (custom-unlispify-tag-name group
))))
854 (if (get-buffer name
)
855 (let ((window (selected-window)))
857 (select-window window
))
858 (custom-buffer-create-other-window
859 (list (list group
'custom-group
))
861 (concat " for group "
862 (custom-unlispify-tag-name group
))))))
865 (defalias 'customize-variable
'customize-option
)
868 (defun customize-option (symbol)
869 "Customize SYMBOL, which must be a user option variable."
870 (interactive (custom-variable-prompt))
871 (custom-buffer-create (list (list symbol
'custom-variable
))
872 (format "*Customize Option: %s*"
873 (custom-unlispify-tag-name symbol
))))
876 (defun customize-changed-options (since-version)
877 "Customize all user option variables whose default values changed recently.
878 This means, in other words, variables and groups defined with a `:version'
880 (interactive "sCustomize options changed, since version (default all versions): ")
881 (if (equal since-version
"")
882 (setq since-version nil
))
884 (mapatoms (lambda (symbol)
885 (and (or (boundp symbol
)
886 ;; For groups the previous test fails, this one
887 ;; could be used to determine if symbol is a
888 ;; group. Is there a better way for this?
889 (get symbol
'group-documentation
))
890 (let ((version (get symbol
'custom-version
)))
892 (or (null since-version
)
893 (customize-version-lessp since-version version
))))
895 ;; We have to set the right thing here,
896 ;; depending if we have a group or a
898 (if (get symbol
'group-documentation
)
899 (cons (list symbol
'custom-group
) found
)
900 (cons (list symbol
'custom-variable
) found
))))))
902 (error "No user options have changed defaults in recent Emacs versions")
903 (custom-buffer-create (custom-sort-items found t nil
)
904 "*Customize Changed Options*"))))
906 (defun customize-version-lessp (version1 version2
)
907 (let (major1 major2 minor1 minor2
)
908 (string-match "\\([0-9]+\\)[.]\\([0-9]+\\)" version1
)
909 (setq major1
(read (match-string 1 version1
)))
910 (setq minor1
(read (match-string 2 version1
)))
911 (string-match "\\([0-9]+\\)[.]\\([0-9]+\\)" version2
)
912 (setq major2
(read (match-string 1 version2
)))
913 (setq minor2
(read (match-string 2 version2
)))
914 (or (< major1 major2
)
915 (and (= major1 major2
)
916 (< minor1 minor2
)))))
919 (defalias 'customize-variable-other-window
'customize-option-other-window
)
922 (defun customize-option-other-window (symbol)
923 "Customize SYMBOL, which must be a user option variable.
924 Show the buffer in another window, but don't select it."
925 (interactive (custom-variable-prompt))
926 (custom-buffer-create-other-window
927 (list (list symbol
'custom-variable
))
928 (format "*Customize Option: %s*" (custom-unlispify-tag-name symbol
))))
931 (defun customize-face (&optional symbol
)
932 "Customize SYMBOL, which should be a face name or nil.
933 If SYMBOL is nil, customize all faces."
934 (interactive (list (completing-read "Customize face: (default all) "
935 obarray
'custom-facep
)))
936 (if (or (null symbol
) (and (stringp symbol
) (zerop (length symbol
))))
937 (custom-buffer-create (custom-sort-items
938 (mapcar (lambda (symbol)
939 (list symbol
'custom-face
))
943 (when (stringp symbol
)
944 (setq symbol
(intern symbol
)))
945 (unless (symbolp symbol
)
946 (error "Should be a symbol %S" symbol
))
947 (custom-buffer-create (list (list symbol
'custom-face
))
948 (format "*Customize Face: %s*"
949 (custom-unlispify-tag-name symbol
)))))
952 (defun customize-face-other-window (&optional symbol
)
953 "Show customization buffer for FACE in other window."
954 (interactive (list (completing-read "Customize face: "
955 obarray
'custom-facep
)))
956 (if (or (null symbol
) (and (stringp symbol
) (zerop (length symbol
))))
959 (setq symbol
(intern symbol
)))
960 (unless (symbolp symbol
)
961 (error "Should be a symbol %S" symbol
))
962 (custom-buffer-create-other-window
963 (list (list symbol
'custom-face
))
964 (format "*Customize Face: %s*" (custom-unlispify-tag-name symbol
)))))
967 (defun customize-customized ()
968 "Customize all user options set since the last save in this session."
971 (mapatoms (lambda (symbol)
972 (and (get symbol
'customized-face
)
973 (custom-facep symbol
)
974 (push (list symbol
'custom-face
) found
))
975 (and (get symbol
'customized-value
)
977 (push (list symbol
'custom-variable
) found
))))
979 (error "No customized user options")
980 (custom-buffer-create (custom-sort-items found t nil
)
981 "*Customize Customized*"))))
984 (defun customize-saved ()
985 "Customize all already saved user options."
988 (mapatoms (lambda (symbol)
989 (and (get symbol
'saved-face
)
990 (custom-facep symbol
)
991 (push (list symbol
'custom-face
) found
))
992 (and (get symbol
'saved-value
)
994 (push (list symbol
'custom-variable
) found
))))
996 (error "No saved user options")
997 (custom-buffer-create (custom-sort-items found t nil
)
998 "*Customize Saved*"))))
1001 (defun customize-apropos (regexp &optional all
)
1002 "Customize all user options matching REGEXP.
1003 If ALL is `options', include only options.
1004 If ALL is `faces', include only faces.
1005 If ALL is `groups', include only groups.
1006 If ALL is t (interactively, with prefix arg), include options which are not
1007 user-settable, as well as faces and groups."
1008 (interactive "sCustomize regexp: \nP")
1010 (mapatoms (lambda (symbol)
1011 (when (string-match regexp
(symbol-name symbol
))
1012 (when (and (not (memq all
'(faces options
)))
1013 (get symbol
'custom-group
))
1014 (push (list symbol
'custom-group
) found
))
1015 (when (and (not (memq all
'(options groups
)))
1016 (custom-facep symbol
))
1017 (push (list symbol
'custom-face
) found
))
1018 (when (and (not (memq all
'(groups faces
)))
1020 (or (get symbol
'saved-value
)
1021 (get symbol
'standard-value
)
1022 (if (memq all
'(nil options
))
1023 (user-variable-p symbol
)
1024 (get symbol
'variable-documentation
))))
1025 (push (list symbol
'custom-variable
) found
)))))
1027 (error "No matches")
1028 (custom-buffer-create (custom-sort-items found t
1029 custom-buffer-order-groups
)
1030 "*Customize Apropos*"))))
1033 (defun customize-apropos-options (regexp &optional arg
)
1034 "Customize all user options matching REGEXP.
1035 With prefix arg, include options which are not user-settable."
1036 (interactive "sCustomize regexp: \nP")
1037 (customize-apropos regexp
(or arg
'options
)))
1040 (defun customize-apropos-faces (regexp)
1041 "Customize all user faces matching REGEXP."
1042 (interactive "sCustomize regexp: \n")
1043 (customize-apropos regexp
'faces
))
1046 (defun customize-apropos-groups (regexp)
1047 "Customize all user groups matching REGEXP."
1048 (interactive "sCustomize regexp: \n")
1049 (customize-apropos regexp
'groups
))
1053 (defcustom custom-buffer-style
'links
1054 "Control the presentation style for customization buffers.
1055 The value should be a symbol, one of:
1057 brackets: groups nest within each other with big horizontal brackets.
1058 links: groups have links to subgroups."
1059 :type
'(radio (const brackets
)
1061 :group
'custom-buffer
)
1063 (defcustom custom-buffer-indent
3
1064 "Number of spaces to indent nested groups."
1066 :group
'custom-buffer
)
1069 (defun custom-buffer-create (options &optional name description
)
1070 "Create a buffer containing OPTIONS.
1071 Optional NAME is the name of the buffer.
1072 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1073 SYMBOL is a customization option, and WIDGET is a widget for editing
1075 (unless name
(setq name
"*Customization*"))
1076 (kill-buffer (get-buffer-create name
))
1077 (pop-to-buffer (get-buffer-create name
))
1078 (custom-buffer-create-internal options description
))
1081 (defun custom-buffer-create-other-window (options &optional name description
)
1082 "Create a buffer containing OPTIONS.
1083 Optional NAME is the name of the buffer.
1084 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1085 SYMBOL is a customization option, and WIDGET is a widget for editing
1087 (unless name
(setq name
"*Customization*"))
1088 (kill-buffer (get-buffer-create name
))
1089 (let ((window (selected-window))
1091 (special-display-buffer-names nil
)
1092 (special-display-regexps nil
)
1093 (same-window-buffer-names nil
)
1094 (same-window-regexps nil
))
1095 (pop-to-buffer (get-buffer-create name
))
1096 (custom-buffer-create-internal options description
)
1097 (select-window window
)))
1099 (defcustom custom-reset-button-menu nil
1100 "If non-nil, only show a single reset button in customize buffers.
1101 This button will have a menu with all three reset operations."
1103 :group
'custom-buffer
)
1105 (defun custom-buffer-create-internal (options &optional description
)
1106 (message "Creating customization buffer...")
1108 (widget-insert "This is a customization buffer")
1110 (widget-insert description
))
1112 Square brackets show active fields; type RET or click mouse-1
1113 on an active field to invoke its action. Editing an option value
1114 changes the text in the buffer; invoke the State button and
1115 choose the Set operation to set the option value.
1117 (widget-create 'info-link
1119 :help-echo
"Read the online help."
1120 "(emacs)Easy Customization")
1121 (widget-insert " for more information.\n\n")
1122 (message "Creating customization buttons...")
1123 (widget-insert "Operate on everything in this buffer:\n ")
1124 (widget-create 'push-button
1125 :tag
"Set for Current Session"
1127 Make your editing in this buffer take effect for this session."
1128 :action
(lambda (widget &optional event
)
1131 (widget-create 'push-button
1132 :tag
"Save for Future Sessions"
1134 Make your editing in this buffer take effect for future Emacs sessions."
1135 :action
(lambda (widget &optional event
)
1137 (if custom-reset-button-menu
1140 (widget-create 'push-button
1142 :help-echo
"Show a menu with reset operations."
1143 :mouse-down-action
(lambda (&rest junk
) t
)
1144 :action
(lambda (widget &optional event
)
1145 (custom-reset event
))))
1146 (widget-insert "\n ")
1147 (widget-create 'push-button
1150 Reset all edited text in this buffer to reflect current values."
1151 :action
'Custom-reset-current
)
1153 (widget-create 'push-button
1154 :tag
"Reset to Saved"
1156 Reset all values in this buffer to their saved settings."
1157 :action
'Custom-reset-saved
)
1159 (widget-create 'push-button
1160 :tag
"Reset to Standard"
1162 Reset all values in this buffer to their standard settings."
1163 :action
'Custom-reset-standard
))
1165 (widget-create 'push-button
1167 :help-echo
"Bury the buffer."
1168 :action
(lambda (widget &optional event
)
1170 (widget-insert "\n\n")
1171 (message "Creating customization items...")
1172 (setq custom-options
1173 (if (= (length options
) 1)
1174 (mapcar (lambda (entry)
1175 (widget-create (nth 1 entry
)
1176 :documentation-shown t
1177 :custom-state
'unknown
1178 :tag
(custom-unlispify-tag-name
1180 :value
(nth 0 entry
)))
1183 (length (length options
)))
1184 (mapcar (lambda (entry)
1186 (message "Creating customization items %2d%%..."
1187 (/ (* 100.0 count
) length
))
1188 (widget-create (nth 1 entry
)
1189 :tag
(custom-unlispify-tag-name
1191 :value
(nth 0 entry
))
1192 (setq count
(1+ count
))
1193 (unless (eq (preceding-char) ?
\n)
1194 (widget-insert "\n"))
1195 (widget-insert "\n")))
1197 (unless (eq (preceding-char) ?
\n)
1198 (widget-insert "\n"))
1199 (message "Creating customization items %2d%%...done" 100)
1200 (unless (eq custom-buffer-style
'tree
)
1201 (mapcar 'custom-magic-reset custom-options
))
1202 (message "Creating customization setup...")
1204 (goto-char (point-min))
1205 (message "Creating customization buffer...done"))
1207 ;;; The Tree Browser.
1210 (defun customize-browse (&optional group
)
1211 "Create a tree browser for the customize hierarchy."
1214 (setq group
'emacs
))
1215 (let ((name "*Customize Browser*"))
1216 (kill-buffer (get-buffer-create name
))
1217 (pop-to-buffer (get-buffer-create name
)))
1220 Square brackets show active fields; type RET or click mouse-1
1221 on an active field to invoke its action.
1222 Invoke [+] below to expand a group, and [-] to collapse an expanded group.\n")
1223 (if custom-browse-only-groups
1225 Invoke the [Group] button below to edit that item in another window.\n\n")
1226 (widget-insert "Invoke the ")
1227 (widget-create 'item
1230 :tag-glyph
"folder")
1231 (widget-insert ", ")
1232 (widget-create 'item
1236 (widget-insert ", and ")
1237 (widget-create 'item
1240 :tag-glyph
"option")
1241 (widget-insert " buttons below to edit that
1242 item in another window.\n\n"))
1243 (let ((custom-buffer-style 'tree
))
1244 (widget-create 'custom-group
1246 :custom-state
'unknown
1247 :tag
(custom-unlispify-tag-name group
)
1249 (goto-char (point-min)))
1251 (define-widget 'custom-browse-visibility
'item
1252 "Control visibility of items in the customize tree browser."
1254 :action
'custom-browse-visibility-action
)
1256 (defun custom-browse-visibility-action (widget &rest ignore
)
1257 (let ((custom-buffer-style 'tree
))
1258 (custom-toggle-parent widget
)))
1260 (define-widget 'custom-browse-group-tag
'push-button
1261 "Show parent in other window when activated."
1264 :action
'custom-browse-group-tag-action
)
1266 (defun custom-browse-group-tag-action (widget &rest ignore
)
1267 (let ((parent (widget-get widget
:parent
)))
1268 (customize-group-other-window (widget-value parent
))))
1270 (define-widget 'custom-browse-variable-tag
'push-button
1271 "Show parent in other window when activated."
1274 :action
'custom-browse-variable-tag-action
)
1276 (defun custom-browse-variable-tag-action (widget &rest ignore
)
1277 (let ((parent (widget-get widget
:parent
)))
1278 (customize-variable-other-window (widget-value parent
))))
1280 (define-widget 'custom-browse-face-tag
'push-button
1281 "Show parent in other window when activated."
1284 :action
'custom-browse-face-tag-action
)
1286 (defun custom-browse-face-tag-action (widget &rest ignore
)
1287 (let ((parent (widget-get widget
:parent
)))
1288 (customize-face-other-window (widget-value parent
))))
1290 (defconst custom-browse-alist
'((" " "space")
1296 (defun custom-browse-insert-prefix (prefix)
1297 "Insert PREFIX. On XEmacs convert it to line graphics."
1298 (if nil
; (string-match "XEmacs" emacs-version)
1301 (while (not (string-equal prefix
""))
1302 (let ((entry (substring prefix
0 3)))
1303 (setq prefix
(substring prefix
3))
1304 (let ((overlay (make-overlay (1- (point)) (point) nil t nil
))
1305 (name (nth 1 (assoc entry custom-browse-alist
))))
1306 (overlay-put overlay
'end-glyph
(widget-glyph-find name entry
))
1307 (overlay-put overlay
'start-open t
)
1308 (overlay-put overlay
'end-open t
)))))
1311 ;;; Modification of Basic Widgets.
1313 ;; We add extra properties to the basic widgets needed here. This is
1314 ;; fine, as long as we are careful to stay within out own namespace.
1316 ;; We want simple widgets to be displayed by default, but complex
1317 ;; widgets to be hidden.
1319 (widget-put (get 'item
'widget-type
) :custom-show t
)
1320 (widget-put (get 'editable-field
'widget-type
)
1321 :custom-show
(lambda (widget value
)
1322 (let ((pp (pp-to-string value
)))
1323 (cond ((string-match "\n" pp
)
1328 (widget-put (get 'menu-choice
'widget-type
) :custom-show t
)
1330 ;;; The `custom-manual' Widget.
1332 (define-widget 'custom-manual
'info-link
1333 "Link to the manual entry for this customization option."
1334 :help-echo
"Read the manual entry for this option."
1337 ;;; The `custom-magic' Widget.
1339 (defgroup custom-magic-faces nil
1340 "Faces used by the magic button."
1341 :group
'custom-faces
1342 :group
'custom-buffer
)
1344 (defface custom-invalid-face
'((((class color
))
1345 (:foreground
"yellow" :background
"red"))
1347 (:bold t
:italic t
:underline t
)))
1348 "Face used when the customize item is invalid."
1349 :group
'custom-magic-faces
)
1351 (defface custom-rogue-face
'((((class color
))
1352 (:foreground
"pink" :background
"black"))
1355 "Face used when the customize item is not defined for customization."
1356 :group
'custom-magic-faces
)
1358 (defface custom-modified-face
'((((class color
))
1359 (:foreground
"white" :background
"blue"))
1362 "Face used when the customize item has been modified."
1363 :group
'custom-magic-faces
)
1365 (defface custom-set-face
'((((class color
))
1366 (:foreground
"blue" :background
"white"))
1369 "Face used when the customize item has been set."
1370 :group
'custom-magic-faces
)
1372 (defface custom-changed-face
'((((class color
))
1373 (:foreground
"white" :background
"blue"))
1376 "Face used when the customize item has been changed."
1377 :group
'custom-magic-faces
)
1379 (defface custom-saved-face
'((t (:underline t
)))
1380 "Face used when the customize item has been saved."
1381 :group
'custom-magic-faces
)
1383 (defconst custom-magic-alist
'((nil "#" underline
"\
1384 uninitialized, you should not see this.")
1385 (unknown "?" italic
"\
1386 unknown, you should not see this.")
1387 (hidden "-" default
"\
1388 hidden, invoke \"Show\" in the previous line to show." "\
1389 group now hidden, invoke \"Show\", above, to show contents.")
1390 (invalid "x" custom-invalid-face
"\
1391 the value displayed for this %c is invalid and cannot be set.")
1392 (modified "*" custom-modified-face
"\
1393 you have edited the value as text, but you have not set the %c." "\
1394 you have edited something in this group, but not set it.")
1395 (set "+" custom-set-face
"\
1396 you have set this %c, but not saved it for future sessions." "\
1397 something in this group has been set, but not saved.")
1398 (changed ":" custom-changed-face
"\
1399 this %c has been changed outside the customize buffer." "\
1400 something in this group has been changed outside customize.")
1401 (saved "!" custom-saved-face
"\
1402 this %c has been set and saved." "\
1403 something in this group has been set and saved.")
1404 (rogue "@" custom-rogue-face
"\
1405 this %c has not been changed with customize." "\
1406 something in this group is not prepared for customization.")
1407 (standard " " nil
"\
1408 this %c is unchanged from its standard setting." "\
1409 visible group members are all at standard settings."))
1410 "Alist of customize option states.
1411 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1413 STATE is one of the following symbols:
1416 For internal use, should never occur.
1418 For internal use, should never occur.
1420 This item is not being displayed.
1422 This item is modified, but has an invalid form.
1424 This item is modified, and has a valid form.
1426 This item has been set but not saved.
1428 The current value of this item has been changed temporarily.
1430 This item is marked for saving.
1432 This item has no customization information.
1434 This item is unchanged from the standard setting.
1436 MAGIC is a string used to present that state.
1438 FACE is a face used to present the state.
1440 ITEM-DESC is a string describing the state for options.
1442 GROUP-DESC is a string describing the state for groups. If this is
1443 left out, ITEM-DESC will be used.
1445 The string %c in either description will be replaced with the
1446 category of the item. These are `group'. `option', and `face'.
1448 The list should be sorted most significant first.")
1450 (defcustom custom-magic-show
'long
1451 "If non-nil, show textual description of the state.
1452 If `long', show a full-line description, not just one word."
1453 :type
'(choice (const :tag
"no" nil
)
1456 :group
'custom-buffer
)
1458 (defcustom custom-magic-show-hidden
'(option face
)
1459 "Control whether the State button is shown for hidden items.
1460 The value should be a list with the custom categories where the State
1461 button should be visible. Possible categories are `group', `option',
1463 :type
'(set (const group
) (const option
) (const face
))
1464 :group
'custom-buffer
)
1466 (defcustom custom-magic-show-button nil
1467 "Show a \"magic\" button indicating the state of each customization option."
1469 :group
'custom-buffer
)
1471 (define-widget 'custom-magic
'default
1472 "Show and manipulate state for a customization option."
1474 :action
'widget-parent-action
1477 :value-create
'custom-magic-value-create
1478 :value-delete
'widget-children-value-delete
)
1480 (defun widget-magic-mouse-down-action (widget &optional event
)
1481 ;; Non-nil unless hidden.
1482 (not (eq (widget-get (widget-get (widget-get widget
:parent
) :parent
)
1486 (defun custom-magic-value-create (widget)
1487 ;; Create compact status report for WIDGET.
1488 (let* ((parent (widget-get widget
:parent
))
1489 (state (widget-get parent
:custom-state
))
1490 (hidden (eq state
'hidden
))
1491 (entry (assq state custom-magic-alist
))
1492 (magic (nth 1 entry
))
1493 (face (nth 2 entry
))
1494 (category (widget-get parent
:custom-category
))
1495 (text (or (and (eq category
'group
)
1498 (form (widget-get parent
:custom-form
))
1500 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text
)
1501 (setq text
(concat (match-string 1 text
)
1502 (symbol-name category
)
1503 (match-string 2 text
))))
1504 (when (and custom-magic-show
1506 (memq category custom-magic-show-hidden
)))
1508 (when (and (eq category
'group
)
1509 (not (and (eq custom-buffer-style
'links
)
1510 (> (widget-get parent
:custom-level
) 1))))
1511 (insert-char ?\
(* custom-buffer-indent
1512 (widget-get parent
:custom-level
))))
1513 (push (widget-create-child-and-convert
1515 :help-echo
"Change the state of this item."
1516 :format
(if hidden
"%t" "%[%t%]")
1517 :button-prefix
'widget-push-button-prefix
1518 :button-suffix
'widget-push-button-suffix
1519 :mouse-down-action
'widget-magic-mouse-down-action
1523 (let ((start (point)))
1524 (if (eq custom-magic-show
'long
)
1526 (insert (symbol-name state
)))
1527 (cond ((eq form
'lisp
)
1529 ((eq form
'mismatch
)
1530 (insert " (mismatch)")))
1531 (put-text-property start
(point) 'face
'custom-state-face
))
1533 (when (and (eq category
'group
)
1534 (not (and (eq custom-buffer-style
'links
)
1535 (> (widget-get parent
:custom-level
) 1))))
1536 (insert-char ?\
(* custom-buffer-indent
1537 (widget-get parent
:custom-level
))))
1538 (when custom-magic-show-button
1539 (when custom-magic-show
1540 (let ((indent (widget-get parent
:indent
)))
1542 (insert-char ? indent
))))
1543 (push (widget-create-child-and-convert
1545 :mouse-down-action
'widget-magic-mouse-down-action
1549 :help-echo
"Change the state."
1550 :format
(if hidden
"%t" "%[%t%]")
1551 :tag
(if (memq form
'(lisp mismatch
))
1552 (concat "(" magic
")")
1553 (concat "[" magic
"]")))
1556 (widget-put widget
:children children
)))
1558 (defun custom-magic-reset (widget)
1559 "Redraw the :custom-magic property of WIDGET."
1560 (let ((magic (widget-get widget
:custom-magic
)))
1561 (widget-value-set magic
(widget-value magic
))))
1563 ;;; The `custom' Widget.
1565 (defface custom-button-face nil
1566 "Face used for buttons in customization buffers."
1567 :group
'custom-faces
)
1569 (defface custom-documentation-face nil
1570 "Face used for documentation strings in customization buffers."
1571 :group
'custom-faces
)
1573 (defface custom-state-face
'((((class color
)
1575 (:foreground
"lime green"))
1578 (:foreground
"dark green"))
1580 "Face used for State descriptions in the customize buffer."
1581 :group
'custom-faces
)
1583 (define-widget 'custom
'default
1584 "Customize a user option."
1586 :convert-widget
'custom-convert-widget
1587 :notify
'custom-notify
1590 :custom-state
'hidden
1591 :documentation-property
'widget-subclass-responsibility
1592 :value-create
'widget-subclass-responsibility
1593 :value-delete
'widget-children-value-delete
1594 :value-get
'widget-value-value-get
1595 :validate
'widget-children-validate
1596 :match
(lambda (widget value
) (symbolp value
)))
1598 (defun custom-convert-widget (widget)
1599 ;; Initialize :value and :tag from :args in WIDGET.
1600 (let ((args (widget-get widget
:args
)))
1602 (widget-put widget
:value
(widget-apply widget
1603 :value-to-internal
(car args
)))
1604 (widget-put widget
:tag
(custom-unlispify-tag-name (car args
)))
1605 (widget-put widget
:args nil
)))
1608 (defun custom-notify (widget &rest args
)
1609 "Keep track of changes."
1610 (let ((state (widget-get widget
:custom-state
)))
1611 (unless (eq state
'modified
)
1612 (unless (memq state
'(nil unknown hidden
))
1613 (widget-put widget
:custom-state
'modified
))
1614 (custom-magic-reset widget
)
1615 (apply 'widget-default-notify widget args
))))
1617 (defun custom-redraw (widget)
1618 "Redraw WIDGET with current settings."
1619 (let ((line (count-lines (point-min) (point)))
1620 (column (current-column))
1622 (from (marker-position (widget-get widget
:from
)))
1623 (to (marker-position (widget-get widget
:to
))))
1625 (widget-value-set widget
(widget-value widget
))
1626 (custom-redraw-magic widget
))
1627 (when (and (>= pos from
) (<= pos to
))
1632 (goto-line (1+ line
)))
1633 (move-to-column column
))
1636 (defun custom-redraw-magic (widget)
1637 "Redraw WIDGET state with current settings."
1639 (let ((magic (widget-get widget
:custom-magic
)))
1641 (widget-value-set magic
(widget-value magic
))
1642 (when (setq widget
(widget-get widget
:group
))
1643 (custom-group-state-update widget
)))
1645 (setq widget nil
)))))
1648 (defun custom-show (widget value
)
1649 "Non-nil if WIDGET should be shown with VALUE by default."
1650 (let ((show (widget-get widget
:custom-show
)))
1656 (funcall show widget value
)))))
1658 (defvar custom-load-recursion nil
1659 "Hack to avoid recursive dependencies.")
1661 (defun custom-load-symbol (symbol)
1662 "Load all dependencies for SYMBOL."
1663 (unless custom-load-recursion
1664 (let ((custom-load-recursion t
)
1665 (loads (get symbol
'custom-loads
))
1668 (setq load
(car loads
)
1670 (cond ((symbolp load
)
1674 ;; Don't reload a file already loaded.
1675 ((and (boundp 'preloaded-file-list
)
1676 (member load preloaded-file-list
)))
1677 ((assoc load load-history
))
1678 ((assoc (locate-library load
) load-history
))
1681 ;; Without this, we would load cus-edit recursively.
1682 ;; We are still loading it when we call this,
1683 ;; and it is not in load-history yet.
1684 (or (equal load
"cus-edit")
1685 (load-library load
))
1688 (defun custom-load-widget (widget)
1689 "Load all dependencies for WIDGET."
1690 (custom-load-symbol (widget-value widget
)))
1692 (defun custom-unloaded-symbol-p (symbol)
1693 "Return non-nil if the dependencies of SYMBOL has not yet been loaded."
1695 (loads (get symbol
'custom-loads
))
1698 (setq load
(car loads
)
1700 (cond ((symbolp load
)
1701 (unless (featurep load
)
1703 ((assoc load load-history
))
1704 ((assoc (locate-library load
) load-history
)
1710 (defun custom-unloaded-widget-p (widget)
1711 "Return non-nil if the dependencies of WIDGET has not yet been loaded."
1712 (custom-unloaded-symbol-p (widget-value widget
)))
1714 (defun custom-toggle-hide (widget)
1715 "Toggle visibility of WIDGET."
1716 (custom-load-widget widget
)
1717 (let ((state (widget-get widget
:custom-state
)))
1718 (cond ((memq state
'(invalid modified
))
1719 (error "There are unset changes"))
1721 (widget-put widget
:custom-state
'unknown
))
1723 (widget-put widget
:documentation-shown nil
)
1724 (widget-put widget
:custom-state
'hidden
)))
1725 (custom-redraw widget
)
1728 (defun custom-toggle-parent (widget &rest ignore
)
1729 "Toggle visibility of parent of WIDGET."
1730 (custom-toggle-hide (widget-get widget
:parent
)))
1732 (defun custom-add-see-also (widget &optional prefix
)
1733 "Add `See also ...' to WIDGET if there are any links.
1734 Insert PREFIX first if non-nil."
1735 (let* ((symbol (widget-get widget
:value
))
1736 (links (get symbol
'custom-links
))
1737 (many (> (length links
) 2))
1738 (buttons (widget-get widget
:buttons
))
1739 (indent (widget-get widget
:indent
)))
1742 (insert-char ?\ indent
))
1745 (insert "See also ")
1747 (push (widget-create-child-and-convert widget
(car links
))
1749 (setq links
(cdr links
))
1758 (widget-put widget
:buttons buttons
))))
1760 (defun custom-add-parent-links (widget &optional initial-string
)
1761 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
1762 The value if non-nil if any parents were found.
1763 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
1764 (let ((name (widget-value widget
))
1765 (type (widget-type widget
))
1766 (buttons (widget-get widget
:buttons
))
1769 (insert (or initial-string
"Parent groups:"))
1770 (mapatoms (lambda (symbol)
1771 (let ((entry (assq name
(get symbol
'custom-group
))))
1772 (when (eq (nth 1 entry
) type
)
1774 (push (widget-create-child-and-convert
1775 widget
'custom-group-link
1776 :tag
(custom-unlispify-tag-name symbol
)
1780 (widget-put widget
:buttons buttons
)
1783 (delete-region start
(point)))
1786 ;;; The `custom-variable' Widget.
1788 (defface custom-variable-tag-face
'((((class color
)
1790 (:foreground
"light blue" :underline t
))
1793 (:foreground
"blue" :underline t
))
1795 "Face used for unpushable variable tags."
1796 :group
'custom-faces
)
1798 (defface custom-variable-button-face
'((t (:underline t
:bold t
)))
1799 "Face used for pushable variable tags."
1800 :group
'custom-faces
)
1802 (defcustom custom-variable-default-form
'edit
1803 "Default form of displaying variable values."
1804 :type
'(choice (const edit
)
1806 :group
'custom-buffer
1809 (define-widget 'custom-variable
'custom
1810 "Customize variable."
1812 :help-echo
"Set or reset this variable."
1813 :documentation-property
'variable-documentation
1814 :custom-category
'option
1816 :custom-menu
'custom-variable-menu-create
1817 :custom-form nil
; defaults to value of `custom-variable-default-form'
1818 :value-create
'custom-variable-value-create
1819 :action
'custom-variable-action
1820 :custom-set
'custom-variable-set
1821 :custom-save
'custom-variable-save
1822 :custom-reset-current
'custom-redraw
1823 :custom-reset-saved
'custom-variable-reset-saved
1824 :custom-reset-standard
'custom-variable-reset-standard
)
1826 (defun custom-variable-type (symbol)
1827 "Return a widget suitable for editing the value of SYMBOL.
1828 If SYMBOL has a `custom-type' property, use that.
1829 Otherwise, look up symbol in `custom-guess-type-alist'."
1830 (let* ((type (or (get symbol
'custom-type
)
1831 (and (not (get symbol
'standard-value
))
1832 (custom-guess-type symbol
))
1834 (options (get symbol
'custom-options
))
1835 (tmp (if (listp type
)
1836 (copy-sequence type
)
1839 (widget-put tmp
:options options
))
1842 (defun custom-variable-value-create (widget)
1843 "Here is where you edit the variables value."
1844 (custom-load-widget widget
)
1845 (unless (widget-get widget
:custom-form
)
1846 (widget-put widget
:custom-form custom-variable-default-form
))
1847 (let* ((buttons (widget-get widget
:buttons
))
1848 (children (widget-get widget
:children
))
1849 (form (widget-get widget
:custom-form
))
1850 (state (widget-get widget
:custom-state
))
1851 (symbol (widget-get widget
:value
))
1852 (tag (widget-get widget
:tag
))
1853 (type (custom-variable-type symbol
))
1854 (conv (widget-convert type
))
1855 (get (or (get symbol
'custom-get
) 'default-value
))
1856 (prefix (widget-get widget
:custom-prefix
))
1857 (last (widget-get widget
:custom-last
))
1858 (value (if (default-boundp symbol
)
1859 (funcall get symbol
)
1860 (widget-get conv
:value
))))
1861 ;; If the widget is new, the child determine whether it is hidden.
1863 ((custom-show type value
)
1864 (setq state
'unknown
))
1866 (setq state
'hidden
)))
1867 ;; If we don't know the state, see if we need to edit it in lisp form.
1868 (when (eq state
'unknown
)
1869 (unless (widget-apply conv
:match value
)
1870 ;; (widget-apply (widget-convert type) :match value)
1871 (setq form
'mismatch
)))
1872 ;; Now we can create the child widget.
1873 (cond ((eq custom-buffer-style
'tree
)
1874 (insert prefix
(if last
" `--- " " |--- "))
1875 (push (widget-create-child-and-convert
1876 widget
'custom-browse-variable-tag
)
1878 (insert " " tag
"\n")
1879 (widget-put widget
:buttons buttons
))
1881 ;; Indicate hidden value.
1882 (push (widget-create-child-and-convert
1885 :sample-face
'custom-variable-tag-face
1889 (push (widget-create-child-and-convert
1891 :help-echo
"Show the value of this option."
1892 :action
'custom-toggle-parent
1895 ((memq form
'(lisp mismatch
))
1896 ;; In lisp mode edit the saved value when possible.
1897 (let* ((value (cond ((get symbol
'saved-value
)
1898 (car (get symbol
'saved-value
)))
1899 ((get symbol
'standard-value
)
1900 (car (get symbol
'standard-value
)))
1901 ((default-boundp symbol
)
1902 (custom-quote (funcall get symbol
)))
1904 (custom-quote (widget-get conv
:value
))))))
1905 (insert (symbol-name symbol
) ": ")
1906 (push (widget-create-child-and-convert
1908 :help-echo
"Hide the value of this option."
1909 :action
'custom-toggle-parent
1913 (push (widget-create-child-and-convert
1915 :button-face
'custom-variable-button-face
1917 :tag
(symbol-name symbol
)
1923 (let* ((format (widget-get type
:format
))
1924 tag-format value-format
)
1925 (unless (string-match ":" format
)
1926 (error "Bad format"))
1927 (setq tag-format
(substring format
0 (match-end 0)))
1928 (setq value-format
(substring format
(match-end 0)))
1929 (push (widget-create-child-and-convert
1932 :action
'custom-tag-action
1933 :help-echo
"Change value of this option."
1934 :mouse-down-action
'custom-tag-mouse-down-action
1935 :button-face
'custom-variable-button-face
1936 :sample-face
'custom-variable-tag-face
1940 (push (widget-create-child-and-convert
1942 :help-echo
"Hide the value of this option."
1943 :action
'custom-toggle-parent
1946 (push (widget-create-child-and-convert
1948 :format value-format
1951 (unless (eq custom-buffer-style
'tree
)
1952 ;; Now update the state.
1953 (unless (eq (preceding-char) ?
\n)
1954 (widget-insert "\n"))
1955 (if (eq state
'hidden
)
1956 (widget-put widget
:custom-state state
)
1957 (custom-variable-state-set widget
))
1958 ;; Create the magic button.
1959 (let ((magic (widget-create-child-and-convert
1960 widget
'custom-magic nil
)))
1961 (widget-put widget
:custom-magic magic
)
1962 (push magic buttons
))
1963 ;; Update properties.
1964 (widget-put widget
:custom-form form
)
1965 (widget-put widget
:buttons buttons
)
1966 (widget-put widget
:children children
)
1967 ;; Insert documentation.
1968 (widget-default-format-handler widget ?h
)
1970 (unless (eq state
'hidden
)
1971 (when (eq (widget-get widget
:custom-level
) 1)
1972 (custom-add-parent-links widget
))
1973 (custom-add-see-also widget
)))))
1975 (defun custom-tag-action (widget &rest args
)
1976 "Pass :action to first child of WIDGET's parent."
1977 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
1980 (defun custom-tag-mouse-down-action (widget &rest args
)
1981 "Pass :mouse-down-action to first child of WIDGET's parent."
1982 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
1983 :mouse-down-action args
))
1985 (defun custom-variable-state-set (widget)
1986 "Set the state of WIDGET."
1987 (let* ((symbol (widget-value widget
))
1988 (get (or (get symbol
'custom-get
) 'default-value
))
1989 (value (if (default-boundp symbol
)
1990 (funcall get symbol
)
1991 (widget-get widget
:value
)))
1993 (state (cond ((setq tmp
(get symbol
'customized-value
))
1994 (if (condition-case nil
1995 (equal value
(eval (car tmp
)))
1999 ((setq tmp
(get symbol
'saved-value
))
2000 (if (condition-case nil
2001 (equal value
(eval (car tmp
)))
2005 ((setq tmp
(get symbol
'standard-value
))
2006 (if (condition-case nil
2007 (equal value
(eval (car tmp
)))
2012 (widget-put widget
:custom-state state
)))
2014 (defvar custom-variable-menu
2015 '(("Set for Current Session" custom-variable-set
2017 (eq (widget-get widget
:custom-state
) 'modified
)))
2018 ("Save for Future Sessions" custom-variable-save
2020 (memq (widget-get widget
:custom-state
) '(modified set changed rogue
))))
2021 ("Reset to Current" custom-redraw
2023 (and (default-boundp (widget-value widget
))
2024 (memq (widget-get widget
:custom-state
) '(modified changed
)))))
2025 ("Reset to Saved" custom-variable-reset-saved
2027 (and (get (widget-value widget
) 'saved-value
)
2028 (memq (widget-get widget
:custom-state
)
2029 '(modified set changed rogue
)))))
2030 ("Reset to Standard Settings" custom-variable-reset-standard
2032 (and (get (widget-value widget
) 'standard-value
)
2033 (memq (widget-get widget
:custom-state
)
2034 '(modified set changed saved rogue
)))))
2035 ("---" ignore ignore
)
2036 ("Don't show as Lisp expression" custom-variable-edit
2038 (eq (widget-get widget
:custom-form
) 'lisp
)))
2039 ("Show initial Lisp expression" custom-variable-edit-lisp
2041 (eq (widget-get widget
:custom-form
) 'edit
))))
2042 "Alist of actions for the `custom-variable' widget.
2043 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2044 the menu entry, ACTION is the function to call on the widget when the
2045 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2046 widget as an argument, and returns non-nil if ACTION is valid on that
2047 widget. If FILTER is nil, ACTION is always valid.")
2049 (defun custom-variable-action (widget &optional event
)
2050 "Show the menu for `custom-variable' WIDGET.
2051 Optional EVENT is the location for the menu."
2052 (if (eq (widget-get widget
:custom-state
) 'hidden
)
2053 (custom-toggle-hide widget
)
2054 (unless (eq (widget-get widget
:custom-state
) 'modified
)
2055 (custom-variable-state-set widget
))
2056 (custom-redraw-magic widget
)
2057 (let* ((completion-ignore-case t
)
2058 (answer (widget-choose (concat "Operation on "
2059 (custom-unlispify-tag-name
2060 (widget-get widget
:value
)))
2061 (custom-menu-filter custom-variable-menu
2065 (funcall answer widget
)))))
2067 (defun custom-variable-edit (widget)
2068 "Edit value of WIDGET."
2069 (widget-put widget
:custom-state
'unknown
)
2070 (widget-put widget
:custom-form
'edit
)
2071 (custom-redraw widget
))
2073 (defun custom-variable-edit-lisp (widget)
2074 "Edit the lisp representation of the value of WIDGET."
2075 (widget-put widget
:custom-state
'unknown
)
2076 (widget-put widget
:custom-form
'lisp
)
2077 (custom-redraw widget
))
2079 (defun custom-variable-set (widget)
2080 "Set the current value for the variable being edited by WIDGET."
2081 (let* ((form (widget-get widget
:custom-form
))
2082 (state (widget-get widget
:custom-state
))
2083 (child (car (widget-get widget
:children
)))
2084 (symbol (widget-value widget
))
2085 (set (or (get symbol
'custom-set
) 'set-default
))
2087 (cond ((eq state
'hidden
)
2088 (error "Cannot set hidden variable"))
2089 ((setq val
(widget-apply child
:validate
))
2090 (goto-char (widget-get val
:from
))
2091 (error "%s" (widget-get val
:error
)))
2092 ((memq form
'(lisp mismatch
))
2093 (funcall set symbol
(eval (setq val
(widget-value child
))))
2094 (put symbol
'customized-value
(list val
)))
2096 (funcall set symbol
(setq val
(widget-value child
)))
2097 (put symbol
'customized-value
(list (custom-quote val
)))))
2098 (custom-variable-state-set widget
)
2099 (custom-redraw-magic widget
)))
2101 (defun custom-variable-save (widget)
2102 "Set and save the value for the variable being edited by WIDGET."
2103 (let* ((form (widget-get widget
:custom-form
))
2104 (state (widget-get widget
:custom-state
))
2105 (child (car (widget-get widget
:children
)))
2106 (symbol (widget-value widget
))
2107 (set (or (get symbol
'custom-set
) 'set-default
))
2109 (cond ((eq state
'hidden
)
2110 (error "Cannot set hidden variable"))
2111 ((setq val
(widget-apply child
:validate
))
2112 (goto-char (widget-get val
:from
))
2113 (error "%s" (widget-get val
:error
)))
2114 ((memq form
'(lisp mismatch
))
2115 (put symbol
'saved-value
(list (widget-value child
)))
2116 (funcall set symbol
(eval (widget-value child
))))
2119 'saved-value
(list (custom-quote (widget-value
2121 (funcall set symbol
(widget-value child
))))
2122 (put symbol
'customized-value nil
)
2124 (custom-variable-state-set widget
)
2125 (custom-redraw-magic widget
)))
2127 (defun custom-variable-reset-saved (widget)
2128 "Restore the saved value for the variable being edited by WIDGET."
2129 (let* ((symbol (widget-value widget
))
2130 (set (or (get symbol
'custom-set
) 'set-default
)))
2131 (if (get symbol
'saved-value
)
2133 (funcall set symbol
(eval (car (get symbol
'saved-value
))))
2135 (error "No saved value for %s" symbol
))
2136 (put symbol
'customized-value nil
)
2137 (widget-put widget
:custom-state
'unknown
)
2138 (custom-redraw widget
)))
2140 (defun custom-variable-reset-standard (widget)
2141 "Restore the standard setting for the variable being edited by WIDGET."
2142 (let* ((symbol (widget-value widget
))
2143 (set (or (get symbol
'custom-set
) 'set-default
)))
2144 (if (get symbol
'standard-value
)
2145 (funcall set symbol
(eval (car (get symbol
'standard-value
))))
2146 (error "No standard setting known for %S" symbol
))
2147 (put symbol
'customized-value nil
)
2148 (when (get symbol
'saved-value
)
2149 (put symbol
'saved-value nil
)
2151 (widget-put widget
:custom-state
'unknown
)
2152 (custom-redraw widget
)))
2154 ;;; The `custom-face-edit' Widget.
2156 (define-widget 'custom-face-edit
'checklist
2157 "Edit face attributes."
2161 :button-args
'(:help-echo
"Control whether this attribute have any effect.")
2162 :args
(mapcar (lambda (att)
2165 :sibling-args
(widget-get (nth 1 att
) :sibling-args
)
2166 (list 'const
:format
"" :value
(nth 0 att
))
2168 custom-face-attributes
))
2170 ;;; The `custom-display' Widget.
2172 (define-widget 'custom-display
'menu-choice
2173 "Select a display type."
2176 :help-echo
"Specify frames where the face attributes should be used."
2177 :args
'((const :tag
"all" t
)
2181 :args
((group :sibling-args
(:help-echo
"\
2182 Only match the specified window systems.")
2183 (const :format
"Type: "
2185 (checklist :inline t
2188 :sibling-args
(:help-echo
"\
2189 The X11 Window System.")
2191 (const :format
"PM "
2192 :sibling-args
(:help-echo
"\
2193 OS/2 Presentation Manager.")
2195 (const :format
"W32 "
2196 :sibling-args
(:help-echo
"\
2199 (const :format
"DOS "
2200 :sibling-args
(:help-echo
"\
2203 (const :format
"TTY%n"
2204 :sibling-args
(:help-echo
"\
2205 Plain text terminals.")
2207 (group :sibling-args
(:help-echo
"\
2208 Only match the frames with the specified color support.")
2209 (const :format
"Class: "
2211 (checklist :inline t
2213 (const :format
"Color "
2214 :sibling-args
(:help-echo
"\
2215 Match color frames.")
2217 (const :format
"Grayscale "
2218 :sibling-args
(:help-echo
"\
2219 Match grayscale frames.")
2221 (const :format
"Monochrome%n"
2222 :sibling-args
(:help-echo
"\
2223 Match frames with no color support.")
2225 (group :sibling-args
(:help-echo
"\
2226 Only match frames with the specified intensity.")
2228 Background brightness: "
2230 (checklist :inline t
2232 (const :format
"Light "
2233 :sibling-args
(:help-echo
"\
2234 Match frames with light backgrounds.")
2236 (const :format
"Dark\n"
2237 :sibling-args
(:help-echo
"\
2238 Match frames with dark backgrounds.")
2241 ;;; The `custom-face' Widget.
2243 (defface custom-face-tag-face
'((t (:underline t
)))
2244 "Face used for face tags."
2245 :group
'custom-faces
)
2247 (defcustom custom-face-default-form
'selected
2248 "Default form of displaying face definition."
2249 :type
'(choice (const all
)
2252 :group
'custom-buffer
2255 (define-widget 'custom-face
'custom
2257 :sample-face
'custom-face-tag-face
2258 :help-echo
"Set or reset this face."
2259 :documentation-property
'(lambda (face)
2260 (face-doc-string face
))
2261 :value-create
'custom-face-value-create
2262 :action
'custom-face-action
2263 :custom-category
'face
2264 :custom-form nil
; defaults to value of `custom-face-default-form'
2265 :custom-set
'custom-face-set
2266 :custom-save
'custom-face-save
2267 :custom-reset-current
'custom-redraw
2268 :custom-reset-saved
'custom-face-reset-saved
2269 :custom-reset-standard
'custom-face-reset-standard
2270 :custom-menu
'custom-face-menu-create
)
2272 (define-widget 'custom-face-all
'editable-list
2273 "An editable list of display specifications and attributes."
2274 :entry-format
"%i %d %v"
2275 :insert-button-args
'(:help-echo
"Insert new display specification here.")
2276 :append-button-args
'(:help-echo
"Append new display specification here.")
2277 :delete-button-args
'(:help-echo
"Delete this display specification.")
2278 :args
'((group :format
"%v" custom-display custom-face-edit
)))
2280 (defconst custom-face-all
(widget-convert 'custom-face-all
)
2281 "Converted version of the `custom-face-all' widget.")
2283 (define-widget 'custom-display-unselected
'item
2284 "A display specification that doesn't match the selected display."
2285 :match
'custom-display-unselected-match
)
2287 (defun custom-display-unselected-match (widget value
)
2288 "Non-nil if VALUE is an unselected display specification."
2289 (not (face-spec-set-match-display value
(selected-frame))))
2291 (define-widget 'custom-face-selected
'group
2292 "Edit the attributes of the selected display in a face specification."
2293 :args
'((repeat :format
""
2295 (group custom-display-unselected sexp
))
2296 (group (sexp :format
"") custom-face-edit
)
2301 (defconst custom-face-selected
(widget-convert 'custom-face-selected
)
2302 "Converted version of the `custom-face-selected' widget.")
2304 (defun custom-face-value-create (widget)
2305 "Create a list of the display specifications for WIDGET."
2306 (let ((buttons (widget-get widget
:buttons
))
2307 (symbol (widget-get widget
:value
))
2308 (tag (widget-get widget
:tag
))
2309 (state (widget-get widget
:custom-state
))
2311 (is-last (widget-get widget
:custom-last
))
2312 (prefix (widget-get widget
:custom-prefix
)))
2314 (setq tag
(prin1-to-string symbol
)))
2315 (cond ((eq custom-buffer-style
'tree
)
2316 (insert prefix
(if is-last
" `--- " " |--- "))
2317 (push (widget-create-child-and-convert
2318 widget
'custom-browse-face-tag
)
2320 (insert " " tag
"\n")
2321 (widget-put widget
:buttons buttons
))
2325 (if (eq custom-buffer-style
'face
)
2327 (widget-specify-sample widget begin
(point))
2330 (and (string-match "XEmacs" emacs-version
)
2331 ;; XEmacs cannot display uninitialized faces.
2332 (not (custom-facep symbol
))
2333 (copy-face 'custom-face-empty symbol
))
2334 (push (widget-create-child-and-convert widget
'item
2341 (push (widget-create-child-and-convert
2343 :help-echo
"Hide or show this face."
2344 :action
'custom-toggle-parent
2345 (not (eq state
'hidden
)))
2349 (let ((magic (widget-create-child-and-convert
2350 widget
'custom-magic nil
)))
2351 (widget-put widget
:custom-magic magic
)
2352 (push magic buttons
))
2354 (widget-put widget
:buttons buttons
)
2355 ;; Insert documentation.
2356 (widget-default-format-handler widget ?h
)
2358 (unless (eq state
'hidden
)
2359 (when (eq (widget-get widget
:custom-level
) 1)
2360 (custom-add-parent-links widget
))
2361 (custom-add-see-also widget
))
2363 (unless (eq (preceding-char) ?
\n)
2365 (unless (eq state
'hidden
)
2366 (message "Creating face editor...")
2367 (custom-load-widget widget
)
2368 (unless (widget-get widget
:custom-form
)
2369 (widget-put widget
:custom-form custom-face-default-form
))
2370 (let* ((symbol (widget-value widget
))
2371 (spec (or (get symbol
'saved-face
)
2372 (get symbol
'face-defface-spec
)
2373 ;; Attempt to construct it.
2374 (list (list t
(custom-face-attributes-get
2375 symbol
(selected-frame))))))
2376 (form (widget-get widget
:custom-form
))
2377 (indent (widget-get widget
:indent
))
2379 ;; If the user has changed this face in some other way,
2380 ;; edit it as the user has specified it.
2381 (if (not (face-spec-match-p symbol spec
(selected-frame)))
2382 (setq spec
(list (list t
(face-attr-construct symbol
(selected-frame))))))
2383 (setq edit
(widget-create-child-and-convert
2385 (cond ((and (eq form
'selected
)
2386 (widget-apply custom-face-selected
2388 (when indent
(insert-char ?\ indent
))
2389 'custom-face-selected
)
2390 ((and (not (eq form
'lisp
))
2391 (widget-apply custom-face-all
2395 (when indent
(insert-char ?\ indent
))
2398 (custom-face-state-set widget
)
2399 (widget-put widget
:children
(list edit
)))
2400 (message "Creating face editor...done"))))))
2402 (defvar custom-face-menu
2403 '(("Set for Current Session" custom-face-set
)
2404 ("Save for Future Sessions" custom-face-save-command
)
2405 ("Reset to Saved" custom-face-reset-saved
2407 (get (widget-value widget
) 'saved-face
)))
2408 ("Reset to Standard Setting" custom-face-reset-standard
2410 (get (widget-value widget
) 'face-defface-spec
)))
2411 ("---" ignore ignore
)
2412 ("Show all display specs" custom-face-edit-all
2414 (not (eq (widget-get widget
:custom-form
) 'all
))))
2415 ("Just current attributes" custom-face-edit-selected
2417 (not (eq (widget-get widget
:custom-form
) 'selected
))))
2418 ("Show as Lisp expression" custom-face-edit-lisp
2420 (not (eq (widget-get widget
:custom-form
) 'lisp
)))))
2421 "Alist of actions for the `custom-face' widget.
2422 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2423 the menu entry, ACTION is the function to call on the widget when the
2424 menu is selected, and FILTER is a predicate which takes a `custom-face'
2425 widget as an argument, and returns non-nil if ACTION is valid on that
2426 widget. If FILTER is nil, ACTION is always valid.")
2428 (defun custom-face-edit-selected (widget)
2429 "Edit selected attributes of the value of WIDGET."
2430 (widget-put widget
:custom-state
'unknown
)
2431 (widget-put widget
:custom-form
'selected
)
2432 (custom-redraw widget
))
2434 (defun custom-face-edit-all (widget)
2435 "Edit all attributes of the value of WIDGET."
2436 (widget-put widget
:custom-state
'unknown
)
2437 (widget-put widget
:custom-form
'all
)
2438 (custom-redraw widget
))
2440 (defun custom-face-edit-lisp (widget)
2441 "Edit the lisp representation of the value of WIDGET."
2442 (widget-put widget
:custom-state
'unknown
)
2443 (widget-put widget
:custom-form
'lisp
)
2444 (custom-redraw widget
))
2446 (defun custom-face-state-set (widget)
2447 "Set the state of WIDGET."
2448 (let ((symbol (widget-value widget
)))
2449 (widget-put widget
:custom-state
(cond ((get symbol
'customized-face
)
2451 ((get symbol
'saved-face
)
2453 ((get symbol
'face-defface-spec
)
2458 (defun custom-face-action (widget &optional event
)
2459 "Show the menu for `custom-face' WIDGET.
2460 Optional EVENT is the location for the menu."
2461 (if (eq (widget-get widget
:custom-state
) 'hidden
)
2462 (custom-toggle-hide widget
)
2463 (let* ((completion-ignore-case t
)
2464 (symbol (widget-get widget
:value
))
2465 (answer (widget-choose (concat "Operation on "
2466 (custom-unlispify-tag-name symbol
))
2467 (custom-menu-filter custom-face-menu
2471 (funcall answer widget
)))))
2473 (defun custom-face-set (widget)
2474 "Make the face attributes in WIDGET take effect."
2475 (let* ((symbol (widget-value widget
))
2476 (child (car (widget-get widget
:children
)))
2477 (value (widget-value child
)))
2478 (put symbol
'customized-face value
)
2479 (face-spec-set symbol value
)
2480 (custom-face-state-set widget
)
2481 (custom-redraw-magic widget
)))
2483 (defun custom-face-save-command (widget)
2484 "Save in `.emacs' the face attributes in WIDGET."
2485 (custom-face-save widget
)
2488 (defun custom-face-save (widget)
2489 "Prepare for saving WIDGET's face attributes, but don't write `.emacs'."
2490 (let* ((symbol (widget-value widget
))
2491 (child (car (widget-get widget
:children
)))
2492 (value (widget-value child
)))
2493 (face-spec-set symbol value
)
2494 (put symbol
'saved-face value
)
2495 (put symbol
'customized-face nil
)
2497 (custom-face-state-set widget
)
2498 (custom-redraw-magic widget
)))
2500 (defun custom-face-reset-saved (widget)
2501 "Restore WIDGET to the face's default attributes."
2502 (let* ((symbol (widget-value widget
))
2503 (child (car (widget-get widget
:children
)))
2504 (value (get symbol
'saved-face
)))
2506 (error "No saved value for this face"))
2507 (put symbol
'customized-face nil
)
2508 (face-spec-set symbol value
)
2509 (widget-value-set child value
)
2510 (custom-face-state-set widget
)
2511 (custom-redraw-magic widget
)))
2513 (defun custom-face-reset-standard (widget)
2514 "Restore WIDGET to the face's standard settings."
2515 (let* ((symbol (widget-value widget
))
2516 (child (car (widget-get widget
:children
)))
2517 (value (get symbol
'face-defface-spec
)))
2519 (error "No standard setting for this face"))
2520 (put symbol
'customized-face nil
)
2521 (when (get symbol
'saved-face
)
2522 (put symbol
'saved-face nil
)
2524 (face-spec-set symbol value
)
2525 (widget-value-set child value
)
2526 (custom-face-state-set widget
)
2527 (custom-redraw-magic widget
)))
2529 ;;; The `face' Widget.
2531 (define-widget 'face
'default
2532 "Select and customize a face."
2533 :convert-widget
'widget-value-convert-widget
2534 :button-prefix
'widget-push-button-prefix
2535 :button-suffix
'widget-push-button-suffix
2536 :format
"%t: %[select face%] %v"
2539 :value-create
'widget-face-value-create
2540 :value-delete
'widget-face-value-delete
2541 :value-get
'widget-value-value-get
2542 :validate
'widget-children-validate
2543 :action
'widget-face-action
2544 :match
'(lambda (widget value
) (symbolp value
)))
2546 (defun widget-face-value-create (widget)
2547 ;; Create a `custom-face' child.
2548 (let* ((symbol (widget-value widget
))
2549 (custom-buffer-style 'face
)
2550 (child (widget-create-child-and-convert
2554 (custom-magic-reset child
)
2555 (setq custom-options
(cons child custom-options
))
2556 (widget-put widget
:children
(list child
))))
2558 (defun widget-face-value-delete (widget)
2559 ;; Remove the child from the options.
2560 (let ((child (car (widget-get widget
:children
))))
2561 (setq custom-options
(delq child custom-options
))
2562 (widget-children-value-delete widget
)))
2564 (defvar face-history nil
2565 "History of entered face names.")
2567 (defun widget-face-action (widget &optional event
)
2568 "Prompt for a face."
2569 (let ((answer (completing-read "Face: "
2570 (mapcar (lambda (face)
2571 (list (symbol-name face
)))
2575 (unless (zerop (length answer
))
2576 (widget-value-set widget
(intern answer
))
2577 (widget-apply widget
:notify widget event
)
2580 ;;; The `hook' Widget.
2582 (define-widget 'hook
'list
2584 :value-to-internal
(lambda (widget value
)
2585 (if (and value
(symbolp value
))
2588 :match
(lambda (widget value
)
2590 (widget-group-match widget value
)))
2591 :convert-widget
'custom-hook-convert-widget
2594 (defun custom-hook-convert-widget (widget)
2595 ;; Handle `:custom-options'.
2596 (let* ((options (widget-get widget
:options
))
2597 (other `(editable-list :inline t
2598 :entry-format
"%i %d%v"
2599 (function :format
" %v")))
2601 (list `(checklist :inline t
2602 ,@(mapcar (lambda (entry)
2603 `(function-item ,entry
))
2607 (widget-put widget
:args args
)
2610 ;;; The `custom-group-link' Widget.
2612 (define-widget 'custom-group-link
'link
2613 "Show parent in other window when activated."
2614 :help-echo
"Create customization buffer for this group."
2615 :action
'custom-group-link-action
)
2617 (defun custom-group-link-action (widget &rest ignore
)
2618 (customize-group (widget-value widget
)))
2620 ;;; The `custom-group' Widget.
2622 (defcustom custom-group-tag-faces nil
2623 ;; In XEmacs, this ought to play games with font size.
2624 "Face used for group tags.
2625 The first member is used for level 1 groups, the second for level 2,
2626 and so forth. The remaining group tags are shown with
2627 `custom-group-tag-face'."
2628 :type
'(repeat face
)
2629 :group
'custom-faces
)
2631 (defface custom-group-tag-face-1
'((((class color
)
2633 (:foreground
"pink" :underline t
))
2636 (:foreground
"red" :underline t
))
2638 "Face used for group tags.")
2640 (defface custom-group-tag-face
'((((class color
)
2642 (:foreground
"light blue" :underline t
))
2645 (:foreground
"blue" :underline t
))
2647 "Face used for low level group tags."
2648 :group
'custom-faces
)
2650 (define-widget 'custom-group
'custom
2653 :sample-face-get
'custom-group-sample-face-get
2654 :documentation-property
'group-documentation
2655 :help-echo
"Set or reset all members of this group."
2656 :value-create
'custom-group-value-create
2657 :action
'custom-group-action
2658 :custom-category
'group
2659 :custom-set
'custom-group-set
2660 :custom-save
'custom-group-save
2661 :custom-reset-current
'custom-group-reset-current
2662 :custom-reset-saved
'custom-group-reset-saved
2663 :custom-reset-standard
'custom-group-reset-standard
2664 :custom-menu
'custom-group-menu-create
)
2666 (defun custom-group-sample-face-get (widget)
2667 ;; Use :sample-face.
2668 (or (nth (1- (widget-get widget
:custom-level
)) custom-group-tag-faces
)
2669 'custom-group-tag-face
))
2671 (define-widget 'custom-group-visibility
'visibility
2672 "An indicator and manipulator for hidden group contents."
2673 :create
'custom-group-visibility-create
)
2675 (defun custom-group-visibility-create (widget)
2676 (let ((visible (widget-value widget
)))
2678 (insert "--------")))
2679 (widget-default-create widget
))
2681 (defun custom-group-members (symbol groups-only
)
2682 "Return SYMBOL's custom group members.
2683 If GROUPS-ONLY non-nil, return only those members that are groups."
2684 (if (not groups-only
)
2685 (get symbol
'custom-group
)
2687 (dolist (entry (get symbol
'custom-group
))
2688 (when (eq (nth 1 entry
) 'custom-group
)
2689 (push entry members
)))
2690 (nreverse members
))))
2692 (defun custom-group-value-create (widget)
2693 "Insert a customize group for WIDGET in the current buffer."
2694 (let* ((state (widget-get widget
:custom-state
))
2695 (level (widget-get widget
:custom-level
))
2696 ;; (indent (widget-get widget :indent))
2697 (prefix (widget-get widget
:custom-prefix
))
2698 (buttons (widget-get widget
:buttons
))
2699 (tag (widget-get widget
:tag
))
2700 (symbol (widget-value widget
))
2701 (members (custom-group-members symbol
2702 (and (eq custom-buffer-style
'tree
)
2703 custom-browse-only-groups
))))
2704 (cond ((and (eq custom-buffer-style
'tree
)
2706 (or members
(custom-unloaded-widget-p widget
)))
2707 (custom-browse-insert-prefix prefix
)
2708 (push (widget-create-child-and-convert
2709 widget
'custom-browse-visibility
2710 ;; :tag-glyph "plus"
2714 ;; (widget-glyph-insert nil "-- " "horizontal")
2715 (push (widget-create-child-and-convert
2716 widget
'custom-browse-group-tag
)
2718 (insert " " tag
"\n")
2719 (widget-put widget
:buttons buttons
))
2720 ((and (eq custom-buffer-style
'tree
)
2721 (zerop (length members
)))
2722 (custom-browse-insert-prefix prefix
)
2724 ;; (widget-glyph-insert nil "[ ]" "empty")
2725 ;; (widget-glyph-insert nil "-- " "horizontal")
2726 (push (widget-create-child-and-convert
2727 widget
'custom-browse-group-tag
)
2729 (insert " " tag
"\n")
2730 (widget-put widget
:buttons buttons
))
2731 ((eq custom-buffer-style
'tree
)
2732 (custom-browse-insert-prefix prefix
)
2733 (custom-load-widget widget
)
2734 (if (zerop (length members
))
2736 (custom-browse-insert-prefix prefix
)
2738 ;; (widget-glyph-insert nil "[ ]" "empty")
2739 ;; (widget-glyph-insert nil "-- " "horizontal")
2740 (push (widget-create-child-and-convert
2741 widget
'custom-browse-group-tag
)
2743 (insert " " tag
"\n")
2744 (widget-put widget
:buttons buttons
))
2745 (push (widget-create-child-and-convert
2746 widget
'custom-browse-visibility
2747 ;; :tag-glyph "minus"
2751 ;; (widget-glyph-insert nil "-\\ " "top")
2752 (push (widget-create-child-and-convert
2753 widget
'custom-browse-group-tag
)
2755 (insert " " tag
"\n")
2756 (widget-put widget
:buttons buttons
)
2757 (message "Creating group...")
2758 (let* ((members (custom-sort-items members
2759 custom-browse-sort-alphabetically
2760 custom-browse-order-groups
))
2761 (prefixes (widget-get widget
:custom-prefixes
))
2762 (custom-prefix-list (custom-prefix-add symbol prefixes
))
2763 (extra-prefix (if (widget-get widget
:custom-last
)
2766 (prefix (concat prefix extra-prefix
))
2769 (setq entry
(car members
)
2770 members
(cdr members
))
2771 (push (widget-create-child-and-convert
2772 widget
(nth 1 entry
)
2774 :tag
(custom-unlispify-tag-name (nth 0 entry
))
2775 :custom-prefixes custom-prefix-list
2776 :custom-level
(1+ level
)
2777 :custom-last
(null members
)
2778 :value
(nth 0 entry
)
2779 :custom-prefix prefix
)
2781 (widget-put widget
:children
(reverse children
)))
2782 (message "Creating group...done")))
2785 ;; Create level indicator.
2786 (unless (eq custom-buffer-style
'links
)
2787 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
2790 (let ((begin (point)))
2792 (widget-specify-sample widget begin
(point)))
2794 ;; Create link/visibility indicator.
2795 (if (eq custom-buffer-style
'links
)
2796 (push (widget-create-child-and-convert
2797 widget
'custom-group-link
2801 (push (widget-create-child-and-convert
2802 widget
'custom-group-visibility
2803 :help-echo
"Show members of this group."
2804 :action
'custom-toggle-parent
2805 (not (eq state
'hidden
)))
2808 ;; Create magic button.
2809 (let ((magic (widget-create-child-and-convert
2810 widget
'custom-magic nil
)))
2811 (widget-put widget
:custom-magic magic
)
2812 (push magic buttons
))
2814 (widget-put widget
:buttons buttons
)
2815 ;; Insert documentation.
2816 (if (and (eq custom-buffer-style
'links
) (> level
1))
2817 (widget-put widget
:documentation-indent
0))
2818 (widget-default-format-handler widget ?h
))
2821 ;; Add parent groups references above the group.
2822 (if t
;;; This should test that the buffer
2823 ;;; was made to display a group.
2825 (if (custom-add-parent-links widget
2826 "Go to parent group:")
2828 ;; Create level indicator.
2829 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
2832 (let ((start (point)))
2834 (widget-specify-sample widget start
(point)))
2836 ;; Create visibility indicator.
2837 (unless (eq custom-buffer-style
'links
)
2839 (push (widget-create-child-and-convert
2841 :help-echo
"Hide members of this group."
2842 :action
'custom-toggle-parent
2843 (not (eq state
'hidden
)))
2846 ;; Create more dashes.
2847 ;; Use 76 instead of 75 to compensate for the temporary "<"
2848 ;; added by `widget-insert'.
2849 (insert-char ?-
(- 76 (current-column)
2850 (* custom-buffer-indent level
)))
2852 ;; Create magic button.
2853 (let ((magic (widget-create-child-and-convert
2854 widget
'custom-magic
2857 (widget-put widget
:custom-magic magic
)
2858 (push magic buttons
))
2860 (widget-put widget
:buttons buttons
)
2861 ;; Insert documentation.
2862 (widget-default-format-handler widget ?h
)
2864 (if nil
;;; This should test that the buffer
2865 ;;; was not made to display a group.
2867 (insert-char ?\ custom-buffer-indent
)
2868 (custom-add-parent-links widget
)))
2869 (custom-add-see-also widget
2870 (make-string (* custom-buffer-indent level
)
2873 (message "Creating group...")
2874 (custom-load-widget widget
)
2875 (let* ((members (custom-sort-items members
2876 custom-buffer-sort-alphabetically
2877 custom-buffer-order-groups
))
2878 (prefixes (widget-get widget
:custom-prefixes
))
2879 (custom-prefix-list (custom-prefix-add symbol prefixes
))
2880 (length (length members
))
2882 (children (mapcar (lambda (entry)
2883 (widget-insert "\n")
2885 Creating group members... %2d%%"
2886 (/ (* 100.0 count
) length
))
2887 (setq count
(1+ count
))
2889 (widget-create-child-and-convert
2890 widget
(nth 1 entry
)
2892 :tag
(custom-unlispify-tag-name
2894 :custom-prefixes custom-prefix-list
2895 :custom-level
(1+ level
)
2896 :value
(nth 0 entry
))
2897 (unless (eq (preceding-char) ?
\n)
2898 (widget-insert "\n"))))
2900 (message "Creating group magic...")
2901 (mapcar 'custom-magic-reset children
)
2902 (message "Creating group state...")
2903 (widget-put widget
:children children
)
2904 (custom-group-state-update widget
)
2905 (message "Creating group... done"))
2908 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
2909 (insert "\\- " (widget-get widget
:tag
) " group end ")
2910 (insert-char ?-
(- 75 (current-column) (* custom-buffer-indent level
)))
2913 (defvar custom-group-menu
2914 '(("Set for Current Session" custom-group-set
2916 (eq (widget-get widget
:custom-state
) 'modified
)))
2917 ("Save for Future Sessions" custom-group-save
2919 (memq (widget-get widget
:custom-state
) '(modified set
))))
2920 ("Reset to Current" custom-group-reset-current
2922 (memq (widget-get widget
:custom-state
) '(modified))))
2923 ("Reset to Saved" custom-group-reset-saved
2925 (memq (widget-get widget
:custom-state
) '(modified set
))))
2926 ("Reset to standard setting" custom-group-reset-standard
2928 (memq (widget-get widget
:custom-state
) '(modified set saved
)))))
2929 "Alist of actions for the `custom-group' widget.
2930 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2931 the menu entry, ACTION is the function to call on the widget when the
2932 menu is selected, and FILTER is a predicate which takes a `custom-group'
2933 widget as an argument, and returns non-nil if ACTION is valid on that
2934 widget. If FILTER is nil, ACTION is always valid.")
2936 (defun custom-group-action (widget &optional event
)
2937 "Show the menu for `custom-group' WIDGET.
2938 Optional EVENT is the location for the menu."
2939 (if (eq (widget-get widget
:custom-state
) 'hidden
)
2940 (custom-toggle-hide widget
)
2941 (let* ((completion-ignore-case t
)
2942 (answer (widget-choose (concat "Operation on "
2943 (custom-unlispify-tag-name
2944 (widget-get widget
:value
)))
2945 (custom-menu-filter custom-group-menu
2949 (funcall answer widget
)))))
2951 (defun custom-group-set (widget)
2952 "Set changes in all modified group members."
2953 (let ((children (widget-get widget
:children
)))
2954 (mapcar (lambda (child)
2955 (when (eq (widget-get child
:custom-state
) 'modified
)
2956 (widget-apply child
:custom-set
)))
2959 (defun custom-group-save (widget)
2960 "Save all modified group members."
2961 (let ((children (widget-get widget
:children
)))
2962 (mapcar (lambda (child)
2963 (when (memq (widget-get child
:custom-state
) '(modified set
))
2964 (widget-apply child
:custom-save
)))
2967 (defun custom-group-reset-current (widget)
2968 "Reset all modified group members."
2969 (let ((children (widget-get widget
:children
)))
2970 (mapcar (lambda (child)
2971 (when (eq (widget-get child
:custom-state
) 'modified
)
2972 (widget-apply child
:custom-reset-current
)))
2975 (defun custom-group-reset-saved (widget)
2976 "Reset all modified or set group members."
2977 (let ((children (widget-get widget
:children
)))
2978 (mapcar (lambda (child)
2979 (when (memq (widget-get child
:custom-state
) '(modified set
))
2980 (widget-apply child
:custom-reset-saved
)))
2983 (defun custom-group-reset-standard (widget)
2984 "Reset all modified, set, or saved group members."
2985 (let ((children (widget-get widget
:children
)))
2986 (mapcar (lambda (child)
2987 (when (memq (widget-get child
:custom-state
)
2988 '(modified set saved
))
2989 (widget-apply child
:custom-reset-standard
)))
2992 (defun custom-group-state-update (widget)
2994 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
2995 (let* ((children (widget-get widget
:children
))
2996 (states (mapcar (lambda (child)
2997 (widget-get child
:custom-state
))
2999 (magics custom-magic-alist
)
3002 (let ((magic (car (car magics
))))
3003 (if (and (not (eq magic
'hidden
))
3004 (memq magic states
))
3007 (setq magics
(cdr magics
)))))
3008 (widget-put widget
:custom-state found
)))
3009 (custom-magic-reset widget
))
3011 ;;; The `custom-save-all' Function.
3013 (defcustom custom-file nil
3014 "File used for storing customization information.
3015 The default is nil, which means to use your init file
3016 as specified by `user-init-file'. If you specify some other file,
3017 you need to explicitly load that file for the settings to take effect."
3018 :type
'(choice (const :tag
"Your Emacs init file" nil
) file
)
3021 (defun custom-file ()
3022 "Return the file name for saving customizations."
3026 (read-file-name "File for customizations: "
3027 "~/" nil nil
".emacs"))))
3029 (defun custom-save-delete (symbol)
3030 "Delete the call to SYMBOL from `custom-file'.
3031 Leave point at the location of the call, or after the last expression."
3032 (let ((default-major-mode))
3033 (set-buffer (find-file-noselect (custom-file))))
3034 (goto-char (point-min))
3037 (let ((sexp (condition-case nil
3038 (read (current-buffer))
3039 (end-of-file (throw 'found nil
)))))
3040 (when (and (listp sexp
)
3041 (eq (car sexp
) symbol
))
3042 (delete-region (save-excursion
3046 (throw 'found nil
))))))
3048 (defun custom-save-variables ()
3049 "Save all customized variables in `custom-file'."
3051 (custom-save-delete 'custom-set-variables
)
3052 (let ((standard-output (current-buffer)))
3055 (princ "(custom-set-variables")
3056 (mapatoms (lambda (symbol)
3057 (let ((value (get symbol
'saved-value
))
3058 (requests (get symbol
'custom-requests
))
3059 (now (not (or (get symbol
'standard-value
)
3060 (and (not (boundp symbol
))
3061 (not (get symbol
'force-value
)))))))
3078 (unless (looking-at "\n")
3081 (defun custom-save-faces ()
3082 "Save all customized faces in `custom-file'."
3084 (custom-save-delete 'custom-set-faces
)
3085 (let ((standard-output (current-buffer)))
3088 (princ "(custom-set-faces")
3089 (let ((value (get 'default
'saved-face
)))
3090 ;; The default face must be first, since it affects the others.
3092 (princ "\n '(default ")
3094 (if (or (get 'default
'face-defface-spec
)
3095 (and (not (custom-facep 'default
))
3096 (not (get 'default
'force-face
))))
3099 (mapatoms (lambda (symbol)
3100 (let ((value (get symbol
'saved-face
)))
3101 (when (and (not (eq symbol
'default
))
3102 ;; Don't print default face here.
3108 (if (or (get symbol
'face-defface-spec
)
3109 (and (not (custom-facep symbol
))
3110 (not (get symbol
'force-face
))))
3114 (unless (looking-at "\n")
3118 (defun customize-save-customized ()
3119 "Save all user options which have been set in this session."
3121 (mapatoms (lambda (symbol)
3122 (let ((face (get symbol
'customized-face
))
3123 (value (get symbol
'customized-value
)))
3125 (put symbol
'saved-face face
)
3126 (put symbol
'customized-face nil
))
3128 (put symbol
'saved-value value
)
3129 (put symbol
'customized-value nil
)))))
3130 ;; We really should update all custom buffers here.
3134 (defun custom-save-all ()
3135 "Save all customizations in `custom-file'."
3136 (let ((inhibit-read-only t
))
3137 (custom-save-variables)
3140 (let ((default-major-mode nil
))
3141 (set-buffer (find-file-noselect (custom-file))))
3144 ;;; The Customize Menu.
3148 (defcustom custom-menu-nesting
2
3149 "Maximum nesting in custom menus."
3151 :group
'custom-menu
)
3153 (defun custom-face-menu-create (widget symbol
)
3154 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
3155 (vector (custom-unlispify-menu-entry symbol
)
3156 `(customize-face ',symbol
)
3159 (defun custom-variable-menu-create (widget symbol
)
3160 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
3161 (let ((type (get symbol
'custom-type
)))
3162 (unless (listp type
)
3163 (setq type
(list type
)))
3164 (if (and type
(widget-get type
:custom-menu
))
3165 (widget-apply type
:custom-menu symbol
)
3166 (vector (custom-unlispify-menu-entry symbol
)
3167 `(customize-variable ',symbol
)
3170 ;; Add checkboxes to boolean variable entries.
3171 (widget-put (get 'boolean
'widget-type
)
3172 :custom-menu
(lambda (widget symbol
)
3173 (vector (custom-unlispify-menu-entry symbol
)
3174 `(customize-variable ',symbol
)
3176 ':selected symbol
)))
3178 (if (string-match "XEmacs" emacs-version
)
3179 ;; XEmacs can create menus dynamically.
3180 (defun custom-group-menu-create (widget symbol
)
3181 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
3182 `( ,(custom-unlispify-menu-entry symbol t
)
3183 :filter
(lambda (&rest junk
)
3184 (cdr (custom-menu-create ',symbol
)))))
3186 (defun custom-group-menu-create (widget symbol
)
3187 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
3188 ;; Limit the nesting.
3189 (let ((custom-menu-nesting (1- custom-menu-nesting
)))
3190 (custom-menu-create symbol
))))
3193 (defun custom-menu-create (symbol)
3194 "Create menu for customization group SYMBOL.
3195 The menu is in a format applicable to `easy-menu-define'."
3196 (let* ((item (vector (custom-unlispify-menu-entry symbol
)
3197 `(customize-group ',symbol
)
3199 (if (and (or (not (boundp 'custom-menu-nesting
))
3200 (>= custom-menu-nesting
0))
3201 (< (length (get symbol
'custom-group
)) widget-menu-max-size
))
3202 (let ((custom-prefix-list (custom-prefix-add symbol
3203 custom-prefix-list
))
3204 (members (custom-sort-items (get symbol
'custom-group
)
3205 custom-menu-sort-alphabetically
3206 custom-menu-order-groups
)))
3207 (custom-load-symbol symbol
)
3208 `(,(custom-unlispify-menu-entry symbol t
)
3211 ,@(mapcar (lambda (entry)
3212 (widget-apply (if (listp (nth 1 entry
))
3214 (list (nth 1 entry
)))
3215 :custom-menu
(nth 0 entry
)))
3220 (defun customize-menu-create (symbol &optional name
)
3221 "Return a customize menu for customization group SYMBOL.
3222 If optional NAME is given, use that as the name of the menu.
3223 Otherwise the menu will be named `Customize'.
3224 The format is suitable for use with `easy-menu-define'."
3226 (setq name
"Customize"))
3227 (if (string-match "XEmacs" emacs-version
)
3228 ;; We can delay it under XEmacs.
3230 :filter
(lambda (&rest junk
)
3231 (cdr (custom-menu-create ',symbol
))))
3232 ;; But we must create it now under Emacs.
3233 (cons name
(cdr (custom-menu-create symbol
)))))
3235 ;;; The Custom Mode.
3237 (defvar custom-mode-map nil
3238 "Keymap for `custom-mode'.")
3240 (unless custom-mode-map
3241 (setq custom-mode-map
(make-sparse-keymap))
3242 (set-keymap-parent custom-mode-map widget-keymap
)
3243 (suppress-keymap custom-mode-map
)
3244 (define-key custom-mode-map
" " 'scroll-up
)
3245 (define-key custom-mode-map
"\177" 'scroll-down
)
3246 (define-key custom-mode-map
"q" 'bury-buffer
)
3247 (define-key custom-mode-map
"u" 'Custom-goto-parent
)
3248 (define-key custom-mode-map
"n" 'widget-forward
)
3249 (define-key custom-mode-map
"p" 'widget-backward
)
3250 (define-key custom-mode-map
[mouse-1
] 'Custom-move-and-invoke
))
3252 (defun Custom-move-and-invoke (event)
3253 "Move to where you click, and if it is an active field, invoke it."
3255 (mouse-set-point event
)
3256 (if (widget-event-point event
)
3257 (let* ((pos (widget-event-point event
))
3258 (button (get-char-property pos
'button
)))
3260 (widget-button-click event
)))))
3262 (easy-menu-define Custom-mode-menu
3264 "Menu used in customization buffers."
3266 ,(customize-menu-create 'customize
)
3267 ["Set" Custom-set t
]
3268 ["Save" Custom-save t
]
3269 ["Reset to Current" Custom-reset-current t
]
3270 ["Reset to Saved" Custom-reset-saved t
]
3271 ["Reset to Standard Settings" Custom-reset-standard t
]
3272 ["Info" (Info-goto-node "(custom)The Customization Buffer") t
]))
3274 (defun Custom-goto-parent ()
3275 "Go to the parent group listed at the top of this buffer.
3276 If several parents are listed, go to the first of them."
3279 (goto-char (point-min))
3280 (if (search-forward "\nGo to parent group: " nil t
)
3281 (let* ((button (get-char-property (point) 'button
))
3282 (parent (downcase (widget-get button
:tag
))))
3283 (customize-group parent
)))))
3285 (defcustom custom-mode-hook nil
3286 "Hook called when entering custom-mode."
3288 :group
'custom-buffer
)
3290 (defun custom-state-buffer-message (widget)
3291 (if (eq (widget-get (widget-get widget
:parent
) :custom-state
) 'modified
)
3292 (message "To install your edits, invoke [State] and choose the Set operation")))
3294 (defun custom-mode ()
3295 "Major mode for editing customization buffers.
3297 The following commands are available:
3299 Move to next button or editable field. \\[widget-forward]
3300 Move to previous button or editable field. \\[widget-backward]
3301 \\<widget-field-keymap>\
3302 Complete content of editable text field. \\[widget-complete]
3303 \\<custom-mode-map>\
3304 Invoke button under the mouse pointer. \\[Custom-move-and-invoke]
3305 Invoke button under point. \\[widget-button-press]
3306 Set all modifications. \\[Custom-set]
3307 Make all modifications default. \\[Custom-save]
3308 Reset all modified options. \\[Custom-reset-current]
3309 Reset all modified or set options. \\[Custom-reset-saved]
3310 Reset all options. \\[Custom-reset-standard]
3312 Entry to this mode calls the value of `custom-mode-hook'
3313 if that value is non-nil."
3314 (kill-all-local-variables)
3315 (setq major-mode
'custom-mode
3317 (use-local-map custom-mode-map
)
3318 (easy-menu-add Custom-mode-menu
)
3319 (make-local-variable 'custom-options
)
3320 (make-local-variable 'widget-documentation-face
)
3321 (setq widget-documentation-face
'custom-documentation-face
)
3322 (make-local-variable 'widget-button-face
)
3323 (setq widget-button-face
'custom-button-face
)
3324 (make-local-hook 'widget-edit-functions
)
3325 (add-hook 'widget-edit-functions
'custom-state-buffer-message nil t
)
3326 (run-hooks 'custom-mode-hook
))
3332 ;; cus-edit.el ends here