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 (defun custom-sort-items (items sort-alphabetically order-groups
)
615 "Return a sorted copy of ITEMS.
616 ITEMS should be a `custom-group' property.
617 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
618 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
619 groups after non-groups, if nil do not order groups at all."
620 (sort (copy-sequence items
)
622 (let ((typea (nth 1 a
)) (typeb (nth 1 b
))
623 (namea (symbol-name (nth 0 a
))) (nameb (symbol-name (nth 0 b
))))
624 (cond ((not order-groups
)
625 ;; Since we don't care about A and B order, maybe sort.
626 (when sort-alphabetically
627 (string-lessp namea nameb
)))
628 ((eq typea
'custom-group
)
629 ;; If B is also a group, maybe sort. Otherwise, order A and B.
630 (if (eq typeb
'custom-group
)
631 (when sort-alphabetically
632 (string-lessp namea nameb
))
633 (eq order-groups
'first
)))
634 ((eq typeb
'custom-group
)
635 ;; Since A cannot be a group, order A and B.
636 (eq order-groups
'last
))
638 ;; Since A and B cannot be groups, sort.
639 (string-lessp namea nameb
)))))))
641 ;;; Custom Mode Commands.
643 (defvar custom-options nil
644 "Customization widgets in the current buffer.")
647 "Set changes in all modified options."
649 (let ((children custom-options
))
650 (mapcar (lambda (child)
651 (when (eq (widget-get child
:custom-state
) 'modified
)
652 (widget-apply child
:custom-set
)))
655 (defun Custom-save ()
656 "Set all modified group members and save them."
658 (let ((children custom-options
))
659 (mapcar (lambda (child)
660 (when (memq (widget-get child
:custom-state
) '(modified set
))
661 (widget-apply child
:custom-save
)))
665 (defvar custom-reset-menu
666 '(("Current" . Custom-reset-current
)
667 ("Saved" . Custom-reset-saved
)
668 ("Standard Settings" . Custom-reset-standard
))
669 "Alist of actions for the `Reset' button.
670 The key is a string containing the name of the action, the value is a
671 lisp function taking the widget as an element which will be called
672 when the action is chosen.")
674 (defun custom-reset (event)
675 "Select item from reset menu."
676 (let* ((completion-ignore-case t
)
677 (answer (widget-choose "Reset to"
683 (defun Custom-reset-current (&rest ignore
)
684 "Reset all modified group members to their current value."
686 (let ((children custom-options
))
687 (mapcar (lambda (child)
688 (when (eq (widget-get child
:custom-state
) 'modified
)
689 (widget-apply child
:custom-reset-current
)))
692 (defun Custom-reset-saved (&rest ignore
)
693 "Reset all modified or set group members to their saved value."
695 (let ((children custom-options
))
696 (mapcar (lambda (child)
697 (when (eq (widget-get child
:custom-state
) 'modified
)
698 (widget-apply child
:custom-reset-saved
)))
701 (defun Custom-reset-standard (&rest ignore
)
702 "Reset all modified, set, or saved group members to their standard settings."
704 (let ((children custom-options
))
705 (mapcar (lambda (child)
706 (when (eq (widget-get child
:custom-state
) 'modified
)
707 (widget-apply child
:custom-reset-standard
)))
710 ;;; The Customize Commands
712 (defun custom-prompt-variable (prompt-var prompt-val
)
713 "Prompt for a variable and a value and return them as a list.
714 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
715 prompt for the value. The %s escape in PROMPT-VAL is replaced with
716 the name of the variable.
718 If the variable has a `variable-interactive' property, that is used as if
719 it were the arg to `interactive' (which see) to interactively read the value.
721 If the variable has a `custom-type' property, it must be a widget and the
722 `:prompt-value' property of that widget will be used for reading the value."
723 (let* ((var (read-variable prompt-var
))
724 (minibuffer-help-form '(describe-variable var
)))
726 (let ((prop (get var
'variable-interactive
))
727 (type (get var
'custom-type
))
728 (prompt (format prompt-val var
)))
730 (setq type
(list type
)))
732 ;; Use VAR's `variable-interactive' property
733 ;; as an interactive spec for prompting.
734 (call-interactively (list 'lambda
'(arg)
735 (list 'interactive prop
)
738 (widget-prompt-value type
744 (eval-minibuffer prompt
)))))))
747 (defun customize-set-value (var val
)
748 "Set VARIABLE to VALUE. VALUE is a Lisp object.
750 If VARIABLE has a `variable-interactive' property, that is used as if
751 it were the arg to `interactive' (which see) to interactively read the value.
753 If VARIABLE has a `custom-type' property, it must be a widget and the
754 `:prompt-value' property of that widget will be used for reading the value."
755 (interactive (custom-prompt-variable "Set variable: "
756 "Set %s to value: "))
761 (defun customize-set-variable (var val
)
762 "Set the default for VARIABLE to VALUE. VALUE is a Lisp object.
764 If VARIABLE has a `custom-set' property, that is used for setting
765 VARIABLE, otherwise `set-default' is used.
767 The `customized-value' property of the VARIABLE will be set to a list
768 with a quoted VALUE as its sole list member.
770 If VARIABLE has a `variable-interactive' property, that is used as if
771 it were the arg to `interactive' (which see) to interactively read the value.
773 If VARIABLE has a `custom-type' property, it must be a widget and the
774 `:prompt-value' property of that widget will be used for reading the value. "
775 (interactive (custom-prompt-variable "Set variable: "
776 "Set customized value for %s to: "))
777 (funcall (or (get var
'custom-set
) 'set-default
) var val
)
778 (put var
'customized-value
(list (custom-quote val
))))
781 (defun customize-save-variable (var val
)
782 "Set the default for VARIABLE to VALUE, and save it for future sessions.
783 If VARIABLE has a `custom-set' property, that is used for setting
784 VARIABLE, otherwise `set-default' is used.
786 The `customized-value' property of the VARIABLE will be set to a list
787 with a quoted VALUE as its sole list member.
789 If VARIABLE has a `variable-interactive' property, that is used as if
790 it were the arg to `interactive' (which see) to interactively read the value.
792 If VARIABLE has a `custom-type' property, it must be a widget and the
793 `:prompt-value' property of that widget will be used for reading the value. "
794 (interactive (custom-prompt-variable "Set and ave variable: "
795 "Set and save value for %s as: "))
796 (funcall (or (get var
'custom-set
) 'set-default
) var val
)
797 (put var
'saved-value
(list (custom-quote val
)))
802 "Select a customization buffer which you can use to set user options.
803 User options are structured into \"groups\".
804 Initially the top-level group `Emacs' and its immediate subgroups
805 are shown; the contents of those subgroups are initially hidden."
807 (customize-group 'emacs
))
810 (defun customize-group (group)
811 "Customize GROUP, which must be a customization group."
812 (interactive (list (let ((completion-ignore-case t
))
813 (completing-read "Customize group: (default emacs) "
816 (or (get symbol
'custom-loads
)
817 (get symbol
'custom-group
)))
819 (when (stringp group
)
820 (if (string-equal "" group
)
822 (setq group
(intern group
))))
823 (or (get group
'custom-group
)
824 (custom-load-symbol group
))
825 (let ((name (format "*Customize Group: %s*"
826 (custom-unlispify-tag-name group
))))
827 (if (get-buffer name
)
828 (switch-to-buffer name
)
829 (custom-buffer-create (list (list group
'custom-group
))
831 (concat " for group "
832 (custom-unlispify-tag-name group
))))))
835 (defun customize-group-other-window (group)
836 "Customize GROUP, which must be a customization group."
837 (interactive (list (let ((completion-ignore-case t
))
838 (completing-read "Customize group: (default emacs) "
841 (or (get symbol
'custom-loads
)
842 (get symbol
'custom-group
)))
844 (when (stringp group
)
845 (if (string-equal "" group
)
847 (setq group
(intern group
))))
848 (or (get group
'custom-group
)
849 (custom-load-symbol group
))
850 (let ((name (format "*Customize Group: %s*"
851 (custom-unlispify-tag-name group
))))
852 (if (get-buffer name
)
853 (let ((window (selected-window)))
854 (switch-to-buffer-other-window name
)
855 (select-window window
))
856 (custom-buffer-create-other-window
857 (list (list group
'custom-group
))
859 (concat " for group "
860 (custom-unlispify-tag-name group
))))))
863 (defalias 'customize-variable
'customize-option
)
866 (defun customize-option (symbol)
867 "Customize SYMBOL, which must be a user option variable."
868 (interactive (custom-variable-prompt))
869 (custom-buffer-create (list (list symbol
'custom-variable
))
870 (format "*Customize Option: %s*"
871 (custom-unlispify-tag-name symbol
))))
874 (defun customize-changed-options (since-version)
875 "Customize all user option variables whose default values changed recently.
876 This means, in other words, variables and groups defined with a `:version'
878 (interactive "sCustomize options changed, since version (default all versions): ")
879 (if (equal since-version
"")
880 (setq since-version nil
))
882 (mapatoms (lambda (symbol)
883 (and (or (boundp symbol
)
884 ;; For groups the previous test fails, this one
885 ;; could be used to determine if symbol is a
886 ;; group. Is there a better way for this?
887 (get symbol
'group-documentation
))
888 (let ((version (get symbol
'custom-version
)))
890 (or (null since-version
)
891 (customize-version-lessp since-version version
))))
893 ;; We have to set the right thing here,
894 ;; depending if we have a group or a
896 (if (get symbol
'group-documentation
)
897 (cons (list symbol
'custom-group
) found
)
898 (cons (list symbol
'custom-variable
) found
))))))
900 (error "No user options have changed defaults in recent Emacs versions")
901 (custom-buffer-create (custom-sort-items found t nil
)
902 "*Customize Changed Options*"))))
904 (defun customize-version-lessp (version1 version2
)
905 (let (major1 major2 minor1 minor2
)
906 (string-match "\\([0-9]+\\)[.]\\([0-9]+\\)" version1
)
907 (setq major1
(read (match-string 1 version1
)))
908 (setq minor1
(read (match-string 2 version1
)))
909 (string-match "\\([0-9]+\\)[.]\\([0-9]+\\)" version2
)
910 (setq major2
(read (match-string 1 version2
)))
911 (setq minor2
(read (match-string 2 version2
)))
912 (or (< major1 major2
)
913 (and (= major1 major2
)
914 (< minor1 minor2
)))))
917 (defalias 'customize-variable-other-window
'customize-option-other-window
)
920 (defun customize-option-other-window (symbol)
921 "Customize SYMBOL, which must be a user option variable.
922 Show the buffer in another window, but don't select it."
923 (interactive (custom-variable-prompt))
924 (custom-buffer-create-other-window
925 (list (list symbol
'custom-variable
))
926 (format "*Customize Option: %s*" (custom-unlispify-tag-name symbol
))))
929 (defun customize-face (&optional symbol
)
930 "Customize SYMBOL, which should be a face name or nil.
931 If SYMBOL is nil, customize all faces."
932 (interactive (list (completing-read "Customize face: (default all) "
933 obarray
'custom-facep
)))
934 (if (or (null symbol
) (and (stringp symbol
) (zerop (length symbol
))))
935 (custom-buffer-create (custom-sort-items
936 (mapcar (lambda (symbol)
937 (list symbol
'custom-face
))
941 (when (stringp symbol
)
942 (setq symbol
(intern symbol
)))
943 (unless (symbolp symbol
)
944 (error "Should be a symbol %S" symbol
))
945 (custom-buffer-create (list (list symbol
'custom-face
))
946 (format "*Customize Face: %s*"
947 (custom-unlispify-tag-name symbol
)))))
950 (defun customize-face-other-window (&optional symbol
)
951 "Show customization buffer for FACE in other window."
952 (interactive (list (completing-read "Customize face: "
953 obarray
'custom-facep
)))
954 (if (or (null symbol
) (and (stringp symbol
) (zerop (length symbol
))))
957 (setq symbol
(intern symbol
)))
958 (unless (symbolp symbol
)
959 (error "Should be a symbol %S" symbol
))
960 (custom-buffer-create-other-window
961 (list (list symbol
'custom-face
))
962 (format "*Customize Face: %s*" (custom-unlispify-tag-name symbol
)))))
965 (defun customize-customized ()
966 "Customize all user options set since the last save in this session."
969 (mapatoms (lambda (symbol)
970 (and (get symbol
'customized-face
)
971 (custom-facep symbol
)
972 (push (list symbol
'custom-face
) found
))
973 (and (get symbol
'customized-value
)
975 (push (list symbol
'custom-variable
) found
))))
977 (error "No customized user options")
978 (custom-buffer-create (custom-sort-items found t nil
)
979 "*Customize Customized*"))))
982 (defun customize-saved ()
983 "Customize all already saved user options."
986 (mapatoms (lambda (symbol)
987 (and (get symbol
'saved-face
)
988 (custom-facep symbol
)
989 (push (list symbol
'custom-face
) found
))
990 (and (get symbol
'saved-value
)
992 (push (list symbol
'custom-variable
) found
))))
994 (error "No saved user options")
995 (custom-buffer-create (custom-sort-items found t nil
)
996 "*Customize Saved*"))))
999 (defun customize-apropos (regexp &optional all
)
1000 "Customize all user options matching REGEXP.
1001 If ALL is `options', include only options.
1002 If ALL is `faces', include only faces.
1003 If ALL is `groups', include only groups.
1004 If ALL is t (interactively, with prefix arg), include options which are not
1005 user-settable, as well as faces and groups."
1006 (interactive "sCustomize regexp: \nP")
1008 (mapatoms (lambda (symbol)
1009 (when (string-match regexp
(symbol-name symbol
))
1010 (when (and (not (memq all
'(faces options
)))
1011 (get symbol
'custom-group
))
1012 (push (list symbol
'custom-group
) found
))
1013 (when (and (not (memq all
'(options groups
)))
1014 (custom-facep symbol
))
1015 (push (list symbol
'custom-face
) found
))
1016 (when (and (not (memq all
'(groups faces
)))
1018 (or (get symbol
'saved-value
)
1019 (get symbol
'standard-value
)
1020 (if (memq all
'(nil options
))
1021 (user-variable-p symbol
)
1022 (get symbol
'variable-documentation
))))
1023 (push (list symbol
'custom-variable
) found
)))))
1025 (error "No matches")
1026 (custom-buffer-create (custom-sort-items found t
1027 custom-buffer-order-groups
)
1028 "*Customize Apropos*"))))
1031 (defun customize-apropos-options (regexp &optional arg
)
1032 "Customize all user options matching REGEXP.
1033 With prefix arg, include options which are not user-settable."
1034 (interactive "sCustomize regexp: \nP")
1035 (customize-apropos regexp
(or arg
'options
)))
1038 (defun customize-apropos-faces (regexp)
1039 "Customize all user faces matching REGEXP."
1040 (interactive "sCustomize regexp: \n")
1041 (customize-apropos regexp
'faces
))
1044 (defun customize-apropos-groups (regexp)
1045 "Customize all user groups matching REGEXP."
1046 (interactive "sCustomize regexp: \n")
1047 (customize-apropos regexp
'groups
))
1051 (defcustom custom-buffer-style
'links
1052 "Control the presentation style for customization buffers.
1053 The value should be a symbol, one of:
1055 brackets: groups nest within each other with big horizontal brackets.
1056 links: groups have links to subgroups."
1057 :type
'(radio (const brackets
)
1059 :group
'custom-buffer
)
1061 (defcustom custom-buffer-indent
3
1062 "Number of spaces to indent nested groups."
1064 :group
'custom-buffer
)
1067 (defun custom-buffer-create (options &optional name description
)
1068 "Create a buffer containing OPTIONS.
1069 Optional NAME is the name of the buffer.
1070 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1071 SYMBOL is a customization option, and WIDGET is a widget for editing
1073 (unless name
(setq name
"*Customization*"))
1074 (kill-buffer (get-buffer-create name
))
1075 (switch-to-buffer (get-buffer-create name
))
1076 (custom-buffer-create-internal options description
))
1079 (defun custom-buffer-create-other-window (options &optional name description
)
1080 "Create a buffer containing OPTIONS.
1081 Optional NAME is the name of the buffer.
1082 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1083 SYMBOL is a customization option, and WIDGET is a widget for editing
1085 (unless name
(setq name
"*Customization*"))
1086 (kill-buffer (get-buffer-create name
))
1087 (let ((window (selected-window)))
1088 (switch-to-buffer-other-window (get-buffer-create name
))
1089 (custom-buffer-create-internal options description
)
1090 (select-window window
)))
1092 (defcustom custom-reset-button-menu nil
1093 "If non-nil, only show a single reset button in customize buffers.
1094 This button will have a menu with all three reset operations."
1096 :group
'custom-buffer
)
1098 (defun custom-buffer-create-internal (options &optional description
)
1099 (message "Creating customization buffer...")
1101 (widget-insert "This is a customization buffer")
1103 (widget-insert description
))
1105 Square brackets show active fields; type RET or click mouse-1
1106 on an active field to invoke its action. Editing an option value
1107 changes the text in the buffer; invoke the State button and
1108 choose the Set operation to set the option value.
1110 (widget-create 'info-link
1112 :help-echo
"Read the online help."
1113 "(emacs)Easy Customization")
1114 (widget-insert " for more information.\n\n")
1115 (message "Creating customization buttons...")
1116 (widget-insert "Operate on everything in this buffer:\n ")
1117 (widget-create 'push-button
1118 :tag
"Set for Current Session"
1120 Make your editing in this buffer take effect for this session."
1121 :action
(lambda (widget &optional event
)
1124 (widget-create 'push-button
1125 :tag
"Save for Future Sessions"
1127 Make your editing in this buffer take effect for future Emacs sessions."
1128 :action
(lambda (widget &optional event
)
1130 (if custom-reset-button-menu
1133 (widget-create 'push-button
1135 :help-echo
"Show a menu with reset operations."
1136 :mouse-down-action
(lambda (&rest junk
) t
)
1137 :action
(lambda (widget &optional event
)
1138 (custom-reset event
))))
1139 (widget-insert "\n ")
1140 (widget-create 'push-button
1143 Reset all edited text in this buffer to reflect current values."
1144 :action
'Custom-reset-current
)
1146 (widget-create 'push-button
1147 :tag
"Reset to Saved"
1149 Reset all values in this buffer to their saved settings."
1150 :action
'Custom-reset-saved
)
1152 (widget-create 'push-button
1153 :tag
"Reset to Standard"
1155 Reset all values in this buffer to their standard settings."
1156 :action
'Custom-reset-standard
))
1158 (widget-create 'push-button
1160 :help-echo
"Bury the buffer."
1161 :action
(lambda (widget &optional event
)
1163 (widget-insert "\n\n")
1164 (message "Creating customization items...")
1165 (setq custom-options
1166 (if (= (length options
) 1)
1167 (mapcar (lambda (entry)
1168 (widget-create (nth 1 entry
)
1169 :documentation-shown t
1170 :custom-state
'unknown
1171 :tag
(custom-unlispify-tag-name
1173 :value
(nth 0 entry
)))
1176 (length (length options
)))
1177 (mapcar (lambda (entry)
1179 (message "Creating customization items %2d%%..."
1180 (/ (* 100.0 count
) length
))
1181 (widget-create (nth 1 entry
)
1182 :tag
(custom-unlispify-tag-name
1184 :value
(nth 0 entry
))
1185 (setq count
(1+ count
))
1186 (unless (eq (preceding-char) ?
\n)
1187 (widget-insert "\n"))
1188 (widget-insert "\n")))
1190 (unless (eq (preceding-char) ?
\n)
1191 (widget-insert "\n"))
1192 (message "Creating customization items %2d%%...done" 100)
1193 (unless (eq custom-buffer-style
'tree
)
1194 (mapcar 'custom-magic-reset custom-options
))
1195 (message "Creating customization setup...")
1197 (goto-char (point-min))
1198 (message "Creating customization buffer...done"))
1200 ;;; The Tree Browser.
1203 (defun customize-browse (&optional group
)
1204 "Create a tree browser for the customize hierarchy."
1207 (setq group
'emacs
))
1208 (let ((name "*Customize Browser*"))
1209 (kill-buffer (get-buffer-create name
))
1210 (switch-to-buffer (get-buffer-create name
)))
1213 Square brackets show active fields; type RET or click mouse-1
1214 on an active field to invoke its action.
1215 Invoke [+] below to expand a group, and [-] to collapse an expanded group.\n")
1216 (if custom-browse-only-groups
1218 Invoke the [Group] button below to edit that item in another window.\n\n")
1219 (widget-insert "Invoke the ")
1220 (widget-create 'item
1223 :tag-glyph
"folder")
1224 (widget-insert ", ")
1225 (widget-create 'item
1229 (widget-insert ", and ")
1230 (widget-create 'item
1233 :tag-glyph
"option")
1234 (widget-insert " buttons below to edit that
1235 item in another window.\n\n"))
1236 (let ((custom-buffer-style 'tree
))
1237 (widget-create 'custom-group
1239 :custom-state
'unknown
1240 :tag
(custom-unlispify-tag-name group
)
1242 (goto-char (point-min)))
1244 (define-widget 'custom-browse-visibility
'item
1245 "Control visibility of items in the customize tree browser."
1247 :action
'custom-browse-visibility-action
)
1249 (defun custom-browse-visibility-action (widget &rest ignore
)
1250 (let ((custom-buffer-style 'tree
))
1251 (custom-toggle-parent widget
)))
1253 (define-widget 'custom-browse-group-tag
'push-button
1254 "Show parent in other window when activated."
1257 :action
'custom-browse-group-tag-action
)
1259 (defun custom-browse-group-tag-action (widget &rest ignore
)
1260 (let ((parent (widget-get widget
:parent
)))
1261 (customize-group-other-window (widget-value parent
))))
1263 (define-widget 'custom-browse-variable-tag
'push-button
1264 "Show parent in other window when activated."
1267 :action
'custom-browse-variable-tag-action
)
1269 (defun custom-browse-variable-tag-action (widget &rest ignore
)
1270 (let ((parent (widget-get widget
:parent
)))
1271 (customize-variable-other-window (widget-value parent
))))
1273 (define-widget 'custom-browse-face-tag
'push-button
1274 "Show parent in other window when activated."
1277 :action
'custom-browse-face-tag-action
)
1279 (defun custom-browse-face-tag-action (widget &rest ignore
)
1280 (let ((parent (widget-get widget
:parent
)))
1281 (customize-face-other-window (widget-value parent
))))
1283 (defconst custom-browse-alist
'((" " "space")
1289 (defun custom-browse-insert-prefix (prefix)
1290 "Insert PREFIX. On XEmacs convert it to line graphics."
1291 (if nil
; (string-match "XEmacs" emacs-version)
1294 (while (not (string-equal prefix
""))
1295 (let ((entry (substring prefix
0 3)))
1296 (setq prefix
(substring prefix
3))
1297 (let ((overlay (make-overlay (1- (point)) (point) nil t nil
))
1298 (name (nth 1 (assoc entry custom-browse-alist
))))
1299 (overlay-put overlay
'end-glyph
(widget-glyph-find name entry
))
1300 (overlay-put overlay
'start-open t
)
1301 (overlay-put overlay
'end-open t
)))))
1304 ;;; Modification of Basic Widgets.
1306 ;; We add extra properties to the basic widgets needed here. This is
1307 ;; fine, as long as we are careful to stay within out own namespace.
1309 ;; We want simple widgets to be displayed by default, but complex
1310 ;; widgets to be hidden.
1312 (widget-put (get 'item
'widget-type
) :custom-show t
)
1313 (widget-put (get 'editable-field
'widget-type
)
1314 :custom-show
(lambda (widget value
)
1315 (let ((pp (pp-to-string value
)))
1316 (cond ((string-match "\n" pp
)
1321 (widget-put (get 'menu-choice
'widget-type
) :custom-show t
)
1323 ;;; The `custom-manual' Widget.
1325 (define-widget 'custom-manual
'info-link
1326 "Link to the manual entry for this customization option."
1327 :help-echo
"Read the manual entry for this option."
1330 ;;; The `custom-magic' Widget.
1332 (defgroup custom-magic-faces nil
1333 "Faces used by the magic button."
1334 :group
'custom-faces
1335 :group
'custom-buffer
)
1337 (defface custom-invalid-face
'((((class color
))
1338 (:foreground
"yellow" :background
"red"))
1340 (:bold t
:italic t
:underline t
)))
1341 "Face used when the customize item is invalid."
1342 :group
'custom-magic-faces
)
1344 (defface custom-rogue-face
'((((class color
))
1345 (:foreground
"pink" :background
"black"))
1348 "Face used when the customize item is not defined for customization."
1349 :group
'custom-magic-faces
)
1351 (defface custom-modified-face
'((((class color
))
1352 (:foreground
"white" :background
"blue"))
1355 "Face used when the customize item has been modified."
1356 :group
'custom-magic-faces
)
1358 (defface custom-set-face
'((((class color
))
1359 (:foreground
"blue" :background
"white"))
1362 "Face used when the customize item has been set."
1363 :group
'custom-magic-faces
)
1365 (defface custom-changed-face
'((((class color
))
1366 (:foreground
"white" :background
"blue"))
1369 "Face used when the customize item has been changed."
1370 :group
'custom-magic-faces
)
1372 (defface custom-saved-face
'((t (:underline t
)))
1373 "Face used when the customize item has been saved."
1374 :group
'custom-magic-faces
)
1376 (defconst custom-magic-alist
'((nil "#" underline
"\
1377 uninitialized, you should not see this.")
1378 (unknown "?" italic
"\
1379 unknown, you should not see this.")
1380 (hidden "-" default
"\
1381 hidden, invoke \"Show\" in the previous line to show." "\
1382 group now hidden, invoke \"Show\", above, to show contents.")
1383 (invalid "x" custom-invalid-face
"\
1384 the value displayed for this %c is invalid and cannot be set.")
1385 (modified "*" custom-modified-face
"\
1386 you have edited the value as text, but you have not set the %c." "\
1387 you have edited something in this group, but not set it.")
1388 (set "+" custom-set-face
"\
1389 you have set this %c, but not saved it for future sessions." "\
1390 something in this group has been set, but not saved.")
1391 (changed ":" custom-changed-face
"\
1392 this %c has been changed outside the customize buffer." "\
1393 something in this group has been changed outside customize.")
1394 (saved "!" custom-saved-face
"\
1395 this %c has been set and saved." "\
1396 something in this group has been set and saved.")
1397 (rogue "@" custom-rogue-face
"\
1398 this %c has not been changed with customize." "\
1399 something in this group is not prepared for customization.")
1400 (standard " " nil
"\
1401 this %c is unchanged from its standard setting." "\
1402 visible group members are all at standard settings."))
1403 "Alist of customize option states.
1404 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1406 STATE is one of the following symbols:
1409 For internal use, should never occur.
1411 For internal use, should never occur.
1413 This item is not being displayed.
1415 This item is modified, but has an invalid form.
1417 This item is modified, and has a valid form.
1419 This item has been set but not saved.
1421 The current value of this item has been changed temporarily.
1423 This item is marked for saving.
1425 This item has no customization information.
1427 This item is unchanged from the standard setting.
1429 MAGIC is a string used to present that state.
1431 FACE is a face used to present the state.
1433 ITEM-DESC is a string describing the state for options.
1435 GROUP-DESC is a string describing the state for groups. If this is
1436 left out, ITEM-DESC will be used.
1438 The string %c in either description will be replaced with the
1439 category of the item. These are `group'. `option', and `face'.
1441 The list should be sorted most significant first.")
1443 (defcustom custom-magic-show
'long
1444 "If non-nil, show textual description of the state.
1445 If `long', show a full-line description, not just one word."
1446 :type
'(choice (const :tag
"no" nil
)
1449 :group
'custom-buffer
)
1451 (defcustom custom-magic-show-hidden
'(option face
)
1452 "Control whether the State button is shown for hidden items.
1453 The value should be a list with the custom categories where the State
1454 button should be visible. Possible categories are `group', `option',
1456 :type
'(set (const group
) (const option
) (const face
))
1457 :group
'custom-buffer
)
1459 (defcustom custom-magic-show-button nil
1460 "Show a \"magic\" button indicating the state of each customization option."
1462 :group
'custom-buffer
)
1464 (define-widget 'custom-magic
'default
1465 "Show and manipulate state for a customization option."
1467 :action
'widget-parent-action
1470 :value-create
'custom-magic-value-create
1471 :value-delete
'widget-children-value-delete
)
1473 (defun widget-magic-mouse-down-action (widget &optional event
)
1474 ;; Non-nil unless hidden.
1475 (not (eq (widget-get (widget-get (widget-get widget
:parent
) :parent
)
1479 (defun custom-magic-value-create (widget)
1480 ;; Create compact status report for WIDGET.
1481 (let* ((parent (widget-get widget
:parent
))
1482 (state (widget-get parent
:custom-state
))
1483 (hidden (eq state
'hidden
))
1484 (entry (assq state custom-magic-alist
))
1485 (magic (nth 1 entry
))
1486 (face (nth 2 entry
))
1487 (category (widget-get parent
:custom-category
))
1488 (text (or (and (eq category
'group
)
1491 (form (widget-get parent
:custom-form
))
1493 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text
)
1494 (setq text
(concat (match-string 1 text
)
1495 (symbol-name category
)
1496 (match-string 2 text
))))
1497 (when (and custom-magic-show
1499 (memq category custom-magic-show-hidden
)))
1501 (when (and (eq category
'group
)
1502 (not (and (eq custom-buffer-style
'links
)
1503 (> (widget-get parent
:custom-level
) 1))))
1504 (insert-char ?\
(* custom-buffer-indent
1505 (widget-get parent
:custom-level
))))
1506 (push (widget-create-child-and-convert
1508 :help-echo
"Change the state of this item."
1509 :format
(if hidden
"%t" "%[%t%]")
1510 :button-prefix
'widget-push-button-prefix
1511 :button-suffix
'widget-push-button-suffix
1512 :mouse-down-action
'widget-magic-mouse-down-action
1516 (let ((start (point)))
1517 (if (eq custom-magic-show
'long
)
1519 (insert (symbol-name state
)))
1520 (cond ((eq form
'lisp
)
1522 ((eq form
'mismatch
)
1523 (insert " (mismatch)")))
1524 (put-text-property start
(point) 'face
'custom-state-face
))
1526 (when (and (eq category
'group
)
1527 (not (and (eq custom-buffer-style
'links
)
1528 (> (widget-get parent
:custom-level
) 1))))
1529 (insert-char ?\
(* custom-buffer-indent
1530 (widget-get parent
:custom-level
))))
1531 (when custom-magic-show-button
1532 (when custom-magic-show
1533 (let ((indent (widget-get parent
:indent
)))
1535 (insert-char ? indent
))))
1536 (push (widget-create-child-and-convert
1538 :mouse-down-action
'widget-magic-mouse-down-action
1542 :help-echo
"Change the state."
1543 :format
(if hidden
"%t" "%[%t%]")
1544 :tag
(if (memq form
'(lisp mismatch
))
1545 (concat "(" magic
")")
1546 (concat "[" magic
"]")))
1549 (widget-put widget
:children children
)))
1551 (defun custom-magic-reset (widget)
1552 "Redraw the :custom-magic property of WIDGET."
1553 (let ((magic (widget-get widget
:custom-magic
)))
1554 (widget-value-set magic
(widget-value magic
))))
1556 ;;; The `custom' Widget.
1558 (defface custom-button-face nil
1559 "Face used for buttons in customization buffers."
1560 :group
'custom-faces
)
1562 (defface custom-documentation-face nil
1563 "Face used for documentation strings in customization buffers."
1564 :group
'custom-faces
)
1566 (defface custom-state-face
'((((class color
)
1568 (:foreground
"lime green"))
1571 (:foreground
"dark green"))
1573 "Face used for State descriptions in the customize buffer."
1574 :group
'custom-faces
)
1576 (define-widget 'custom
'default
1577 "Customize a user option."
1579 :convert-widget
'custom-convert-widget
1580 :notify
'custom-notify
1583 :custom-state
'hidden
1584 :documentation-property
'widget-subclass-responsibility
1585 :value-create
'widget-subclass-responsibility
1586 :value-delete
'widget-children-value-delete
1587 :value-get
'widget-value-value-get
1588 :validate
'widget-children-validate
1589 :match
(lambda (widget value
) (symbolp value
)))
1591 (defun custom-convert-widget (widget)
1592 ;; Initialize :value and :tag from :args in WIDGET.
1593 (let ((args (widget-get widget
:args
)))
1595 (widget-put widget
:value
(widget-apply widget
1596 :value-to-internal
(car args
)))
1597 (widget-put widget
:tag
(custom-unlispify-tag-name (car args
)))
1598 (widget-put widget
:args nil
)))
1601 (defun custom-notify (widget &rest args
)
1602 "Keep track of changes."
1603 (let ((state (widget-get widget
:custom-state
)))
1604 (unless (eq state
'modified
)
1605 (unless (memq state
'(nil unknown hidden
))
1606 (widget-put widget
:custom-state
'modified
))
1607 (custom-magic-reset widget
)
1608 (apply 'widget-default-notify widget args
))))
1610 (defun custom-redraw (widget)
1611 "Redraw WIDGET with current settings."
1612 (let ((line (count-lines (point-min) (point)))
1613 (column (current-column))
1615 (from (marker-position (widget-get widget
:from
)))
1616 (to (marker-position (widget-get widget
:to
))))
1618 (widget-value-set widget
(widget-value widget
))
1619 (custom-redraw-magic widget
))
1620 (when (and (>= pos from
) (<= pos to
))
1625 (goto-line (1+ line
)))
1626 (move-to-column column
))
1629 (defun custom-redraw-magic (widget)
1630 "Redraw WIDGET state with current settings."
1632 (let ((magic (widget-get widget
:custom-magic
)))
1634 (widget-value-set magic
(widget-value magic
))
1635 (when (setq widget
(widget-get widget
:group
))
1636 (custom-group-state-update widget
)))
1638 (setq widget nil
)))))
1641 (defun custom-show (widget value
)
1642 "Non-nil if WIDGET should be shown with VALUE by default."
1643 (let ((show (widget-get widget
:custom-show
)))
1649 (funcall show widget value
)))))
1651 (defvar custom-load-recursion nil
1652 "Hack to avoid recursive dependencies.")
1654 (defun custom-load-symbol (symbol)
1655 "Load all dependencies for SYMBOL."
1656 (unless custom-load-recursion
1657 (let ((custom-load-recursion t
)
1658 (loads (get symbol
'custom-loads
))
1661 (setq load
(car loads
)
1663 (cond ((symbolp load
)
1667 ;; Don't reload a file already loaded.
1668 ((and (boundp 'preloaded-file-list
)
1669 (member load preloaded-file-list
)))
1670 ((assoc load load-history
))
1671 ((assoc (locate-library load
) load-history
))
1674 ;; Without this, we would load cus-edit recursively.
1675 ;; We are still loading it when we call this,
1676 ;; and it is not in load-history yet.
1677 (or (equal load
"cus-edit")
1678 (load-library load
))
1681 (defun custom-load-widget (widget)
1682 "Load all dependencies for WIDGET."
1683 (custom-load-symbol (widget-value widget
)))
1685 (defun custom-unloaded-symbol-p (symbol)
1686 "Return non-nil if the dependencies of SYMBOL has not yet been loaded."
1688 (loads (get symbol
'custom-loads
))
1691 (setq load
(car loads
)
1693 (cond ((symbolp load
)
1694 (unless (featurep load
)
1696 ((assoc load load-history
))
1697 ((assoc (locate-library load
) load-history
)
1703 (defun custom-unloaded-widget-p (widget)
1704 "Return non-nil if the dependencies of WIDGET has not yet been loaded."
1705 (custom-unloaded-symbol-p (widget-value widget
)))
1707 (defun custom-toggle-hide (widget)
1708 "Toggle visibility of WIDGET."
1709 (custom-load-widget widget
)
1710 (let ((state (widget-get widget
:custom-state
)))
1711 (cond ((memq state
'(invalid modified
))
1712 (error "There are unset changes"))
1714 (widget-put widget
:custom-state
'unknown
))
1716 (widget-put widget
:documentation-shown nil
)
1717 (widget-put widget
:custom-state
'hidden
)))
1718 (custom-redraw widget
)
1721 (defun custom-toggle-parent (widget &rest ignore
)
1722 "Toggle visibility of parent of WIDGET."
1723 (custom-toggle-hide (widget-get widget
:parent
)))
1725 (defun custom-add-see-also (widget &optional prefix
)
1726 "Add `See also ...' to WIDGET if there are any links.
1727 Insert PREFIX first if non-nil."
1728 (let* ((symbol (widget-get widget
:value
))
1729 (links (get symbol
'custom-links
))
1730 (many (> (length links
) 2))
1731 (buttons (widget-get widget
:buttons
))
1732 (indent (widget-get widget
:indent
)))
1735 (insert-char ?\ indent
))
1738 (insert "See also ")
1740 (push (widget-create-child-and-convert widget
(car links
))
1742 (setq links
(cdr links
))
1751 (widget-put widget
:buttons buttons
))))
1753 (defun custom-add-parent-links (widget &optional initial-string
)
1754 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
1755 The value if non-nil if any parents were found.
1756 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
1757 (let ((name (widget-value widget
))
1758 (type (widget-type widget
))
1759 (buttons (widget-get widget
:buttons
))
1762 (insert (or initial-string
"Parent groups:"))
1763 (mapatoms (lambda (symbol)
1764 (let ((entry (assq name
(get symbol
'custom-group
))))
1765 (when (eq (nth 1 entry
) type
)
1767 (push (widget-create-child-and-convert
1768 widget
'custom-group-link
1769 :tag
(custom-unlispify-tag-name symbol
)
1773 (widget-put widget
:buttons buttons
)
1776 (delete-region start
(point)))
1779 ;;; The `custom-variable' Widget.
1781 (defface custom-variable-tag-face
'((((class color
)
1783 (:foreground
"light blue" :underline t
))
1786 (:foreground
"blue" :underline t
))
1788 "Face used for unpushable variable tags."
1789 :group
'custom-faces
)
1791 (defface custom-variable-button-face
'((t (:underline t
:bold t
)))
1792 "Face used for pushable variable tags."
1793 :group
'custom-faces
)
1795 (defcustom custom-variable-default-form
'edit
1796 "Default form of displaying variable values."
1797 :type
'(choice (const edit
)
1799 :group
'custom-buffer
1802 (define-widget 'custom-variable
'custom
1803 "Customize variable."
1805 :help-echo
"Set or reset this variable."
1806 :documentation-property
'variable-documentation
1807 :custom-category
'option
1809 :custom-menu
'custom-variable-menu-create
1810 :custom-form nil
; defaults to value of `custom-variable-default-form'
1811 :value-create
'custom-variable-value-create
1812 :action
'custom-variable-action
1813 :custom-set
'custom-variable-set
1814 :custom-save
'custom-variable-save
1815 :custom-reset-current
'custom-redraw
1816 :custom-reset-saved
'custom-variable-reset-saved
1817 :custom-reset-standard
'custom-variable-reset-standard
)
1819 (defun custom-variable-type (symbol)
1820 "Return a widget suitable for editing the value of SYMBOL.
1821 If SYMBOL has a `custom-type' property, use that.
1822 Otherwise, look up symbol in `custom-guess-type-alist'."
1823 (let* ((type (or (get symbol
'custom-type
)
1824 (and (not (get symbol
'standard-value
))
1825 (custom-guess-type symbol
))
1827 (options (get symbol
'custom-options
))
1828 (tmp (if (listp type
)
1829 (copy-sequence type
)
1832 (widget-put tmp
:options options
))
1835 (defun custom-variable-value-create (widget)
1836 "Here is where you edit the variables value."
1837 (custom-load-widget widget
)
1838 (unless (widget-get widget
:custom-form
)
1839 (widget-put widget
:custom-form custom-variable-default-form
))
1840 (let* ((buttons (widget-get widget
:buttons
))
1841 (children (widget-get widget
:children
))
1842 (form (widget-get widget
:custom-form
))
1843 (state (widget-get widget
:custom-state
))
1844 (symbol (widget-get widget
:value
))
1845 (tag (widget-get widget
:tag
))
1846 (type (custom-variable-type symbol
))
1847 (conv (widget-convert type
))
1848 (get (or (get symbol
'custom-get
) 'default-value
))
1849 (prefix (widget-get widget
:custom-prefix
))
1850 (last (widget-get widget
:custom-last
))
1851 (value (if (default-boundp symbol
)
1852 (funcall get symbol
)
1853 (widget-get conv
:value
))))
1854 ;; If the widget is new, the child determine whether it is hidden.
1856 ((custom-show type value
)
1857 (setq state
'unknown
))
1859 (setq state
'hidden
)))
1860 ;; If we don't know the state, see if we need to edit it in lisp form.
1861 (when (eq state
'unknown
)
1862 (unless (widget-apply conv
:match value
)
1863 ;; (widget-apply (widget-convert type) :match value)
1864 (setq form
'mismatch
)))
1865 ;; Now we can create the child widget.
1866 (cond ((eq custom-buffer-style
'tree
)
1867 (insert prefix
(if last
" `--- " " |--- "))
1868 (push (widget-create-child-and-convert
1869 widget
'custom-browse-variable-tag
)
1871 (insert " " tag
"\n")
1872 (widget-put widget
:buttons buttons
))
1874 ;; Indicate hidden value.
1875 (push (widget-create-child-and-convert
1878 :sample-face
'custom-variable-tag-face
1882 (push (widget-create-child-and-convert
1884 :help-echo
"Show the value of this option."
1885 :action
'custom-toggle-parent
1888 ((memq form
'(lisp mismatch
))
1889 ;; In lisp mode edit the saved value when possible.
1890 (let* ((value (cond ((get symbol
'saved-value
)
1891 (car (get symbol
'saved-value
)))
1892 ((get symbol
'standard-value
)
1893 (car (get symbol
'standard-value
)))
1894 ((default-boundp symbol
)
1895 (custom-quote (funcall get symbol
)))
1897 (custom-quote (widget-get conv
:value
))))))
1898 (insert (symbol-name symbol
) ": ")
1899 (push (widget-create-child-and-convert
1901 :help-echo
"Hide the value of this option."
1902 :action
'custom-toggle-parent
1906 (push (widget-create-child-and-convert
1908 :button-face
'custom-variable-button-face
1910 :tag
(symbol-name symbol
)
1916 (let* ((format (widget-get type
:format
))
1917 tag-format value-format
)
1918 (unless (string-match ":" format
)
1919 (error "Bad format"))
1920 (setq tag-format
(substring format
0 (match-end 0)))
1921 (setq value-format
(substring format
(match-end 0)))
1922 (push (widget-create-child-and-convert
1925 :action
'custom-tag-action
1926 :help-echo
"Change value of this option."
1927 :mouse-down-action
'custom-tag-mouse-down-action
1928 :button-face
'custom-variable-button-face
1929 :sample-face
'custom-variable-tag-face
1933 (push (widget-create-child-and-convert
1935 :help-echo
"Hide the value of this option."
1936 :action
'custom-toggle-parent
1939 (push (widget-create-child-and-convert
1941 :format value-format
1944 (unless (eq custom-buffer-style
'tree
)
1945 ;; Now update the state.
1946 (unless (eq (preceding-char) ?
\n)
1947 (widget-insert "\n"))
1948 (if (eq state
'hidden
)
1949 (widget-put widget
:custom-state state
)
1950 (custom-variable-state-set widget
))
1951 ;; Create the magic button.
1952 (let ((magic (widget-create-child-and-convert
1953 widget
'custom-magic nil
)))
1954 (widget-put widget
:custom-magic magic
)
1955 (push magic buttons
))
1956 ;; Update properties.
1957 (widget-put widget
:custom-form form
)
1958 (widget-put widget
:buttons buttons
)
1959 (widget-put widget
:children children
)
1960 ;; Insert documentation.
1961 (widget-default-format-handler widget ?h
)
1963 (unless (eq state
'hidden
)
1964 (when (eq (widget-get widget
:custom-level
) 1)
1965 (custom-add-parent-links widget
))
1966 (custom-add-see-also widget
)))))
1968 (defun custom-tag-action (widget &rest args
)
1969 "Pass :action to first child of WIDGET's parent."
1970 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
1973 (defun custom-tag-mouse-down-action (widget &rest args
)
1974 "Pass :mouse-down-action to first child of WIDGET's parent."
1975 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
1976 :mouse-down-action args
))
1978 (defun custom-variable-state-set (widget)
1979 "Set the state of WIDGET."
1980 (let* ((symbol (widget-value widget
))
1981 (get (or (get symbol
'custom-get
) 'default-value
))
1982 (value (if (default-boundp symbol
)
1983 (funcall get symbol
)
1984 (widget-get widget
:value
)))
1986 (state (cond ((setq tmp
(get symbol
'customized-value
))
1987 (if (condition-case nil
1988 (equal value
(eval (car tmp
)))
1992 ((setq tmp
(get symbol
'saved-value
))
1993 (if (condition-case nil
1994 (equal value
(eval (car tmp
)))
1998 ((setq tmp
(get symbol
'standard-value
))
1999 (if (condition-case nil
2000 (equal value
(eval (car tmp
)))
2005 (widget-put widget
:custom-state state
)))
2007 (defvar custom-variable-menu
2008 '(("Set for Current Session" custom-variable-set
2010 (eq (widget-get widget
:custom-state
) 'modified
)))
2011 ("Save for Future Sessions" custom-variable-save
2013 (memq (widget-get widget
:custom-state
) '(modified set changed rogue
))))
2014 ("Reset to Current" custom-redraw
2016 (and (default-boundp (widget-value widget
))
2017 (memq (widget-get widget
:custom-state
) '(modified changed
)))))
2018 ("Reset to Saved" custom-variable-reset-saved
2020 (and (get (widget-value widget
) 'saved-value
)
2021 (memq (widget-get widget
:custom-state
)
2022 '(modified set changed rogue
)))))
2023 ("Reset to Standard Settings" custom-variable-reset-standard
2025 (and (get (widget-value widget
) 'standard-value
)
2026 (memq (widget-get widget
:custom-state
)
2027 '(modified set changed saved rogue
)))))
2028 ("---" ignore ignore
)
2029 ("Don't show as Lisp expression" custom-variable-edit
2031 (eq (widget-get widget
:custom-form
) 'lisp
)))
2032 ("Show initial Lisp expression" custom-variable-edit-lisp
2034 (eq (widget-get widget
:custom-form
) 'edit
))))
2035 "Alist of actions for the `custom-variable' widget.
2036 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2037 the menu entry, ACTION is the function to call on the widget when the
2038 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2039 widget as an argument, and returns non-nil if ACTION is valid on that
2040 widget. If FILTER is nil, ACTION is always valid.")
2042 (defun custom-variable-action (widget &optional event
)
2043 "Show the menu for `custom-variable' WIDGET.
2044 Optional EVENT is the location for the menu."
2045 (if (eq (widget-get widget
:custom-state
) 'hidden
)
2046 (custom-toggle-hide widget
)
2047 (unless (eq (widget-get widget
:custom-state
) 'modified
)
2048 (custom-variable-state-set widget
))
2049 (custom-redraw-magic widget
)
2050 (let* ((completion-ignore-case t
)
2051 (answer (widget-choose (concat "Operation on "
2052 (custom-unlispify-tag-name
2053 (widget-get widget
:value
)))
2054 (custom-menu-filter custom-variable-menu
2058 (funcall answer widget
)))))
2060 (defun custom-variable-edit (widget)
2061 "Edit value of WIDGET."
2062 (widget-put widget
:custom-state
'unknown
)
2063 (widget-put widget
:custom-form
'edit
)
2064 (custom-redraw widget
))
2066 (defun custom-variable-edit-lisp (widget)
2067 "Edit the lisp representation of the value of WIDGET."
2068 (widget-put widget
:custom-state
'unknown
)
2069 (widget-put widget
:custom-form
'lisp
)
2070 (custom-redraw widget
))
2072 (defun custom-variable-set (widget)
2073 "Set the current value for the variable being edited by WIDGET."
2074 (let* ((form (widget-get widget
:custom-form
))
2075 (state (widget-get widget
:custom-state
))
2076 (child (car (widget-get widget
:children
)))
2077 (symbol (widget-value widget
))
2078 (set (or (get symbol
'custom-set
) 'set-default
))
2080 (cond ((eq state
'hidden
)
2081 (error "Cannot set hidden variable"))
2082 ((setq val
(widget-apply child
:validate
))
2083 (goto-char (widget-get val
:from
))
2084 (error "%s" (widget-get val
:error
)))
2085 ((memq form
'(lisp mismatch
))
2086 (funcall set symbol
(eval (setq val
(widget-value child
))))
2087 (put symbol
'customized-value
(list val
)))
2089 (funcall set symbol
(setq val
(widget-value child
)))
2090 (put symbol
'customized-value
(list (custom-quote val
)))))
2091 (custom-variable-state-set widget
)
2092 (custom-redraw-magic widget
)))
2094 (defun custom-variable-save (widget)
2095 "Set and save the value for the variable being edited by WIDGET."
2096 (let* ((form (widget-get widget
:custom-form
))
2097 (state (widget-get widget
:custom-state
))
2098 (child (car (widget-get widget
:children
)))
2099 (symbol (widget-value widget
))
2100 (set (or (get symbol
'custom-set
) 'set-default
))
2102 (cond ((eq state
'hidden
)
2103 (error "Cannot set hidden variable"))
2104 ((setq val
(widget-apply child
:validate
))
2105 (goto-char (widget-get val
:from
))
2106 (error "%s" (widget-get val
:error
)))
2107 ((memq form
'(lisp mismatch
))
2108 (put symbol
'saved-value
(list (widget-value child
)))
2109 (funcall set symbol
(eval (widget-value child
))))
2112 'saved-value
(list (custom-quote (widget-value
2114 (funcall set symbol
(widget-value child
))))
2115 (put symbol
'customized-value nil
)
2117 (custom-variable-state-set widget
)
2118 (custom-redraw-magic widget
)))
2120 (defun custom-variable-reset-saved (widget)
2121 "Restore the saved value for the variable being edited by WIDGET."
2122 (let* ((symbol (widget-value widget
))
2123 (set (or (get symbol
'custom-set
) 'set-default
)))
2124 (if (get symbol
'saved-value
)
2126 (funcall set symbol
(eval (car (get symbol
'saved-value
))))
2128 (error "No saved value for %s" symbol
))
2129 (put symbol
'customized-value nil
)
2130 (widget-put widget
:custom-state
'unknown
)
2131 (custom-redraw widget
)))
2133 (defun custom-variable-reset-standard (widget)
2134 "Restore the standard setting for the variable being edited by WIDGET."
2135 (let* ((symbol (widget-value widget
))
2136 (set (or (get symbol
'custom-set
) 'set-default
)))
2137 (if (get symbol
'standard-value
)
2138 (funcall set symbol
(eval (car (get symbol
'standard-value
))))
2139 (error "No standard setting known for %S" symbol
))
2140 (put symbol
'customized-value nil
)
2141 (when (get symbol
'saved-value
)
2142 (put symbol
'saved-value nil
)
2144 (widget-put widget
:custom-state
'unknown
)
2145 (custom-redraw widget
)))
2147 ;;; The `custom-face-edit' Widget.
2149 (define-widget 'custom-face-edit
'checklist
2150 "Edit face attributes."
2154 :button-args
'(:help-echo
"Control whether this attribute have any effect.")
2155 :args
(mapcar (lambda (att)
2158 :sibling-args
(widget-get (nth 1 att
) :sibling-args
)
2159 (list 'const
:format
"" :value
(nth 0 att
))
2161 custom-face-attributes
))
2163 ;;; The `custom-display' Widget.
2165 (define-widget 'custom-display
'menu-choice
2166 "Select a display type."
2169 :help-echo
"Specify frames where the face attributes should be used."
2170 :args
'((const :tag
"all" t
)
2174 :args
((group :sibling-args
(:help-echo
"\
2175 Only match the specified window systems.")
2176 (const :format
"Type: "
2178 (checklist :inline t
2181 :sibling-args
(:help-echo
"\
2182 The X11 Window System.")
2184 (const :format
"PM "
2185 :sibling-args
(:help-echo
"\
2186 OS/2 Presentation Manager.")
2188 (const :format
"W32 "
2189 :sibling-args
(:help-echo
"\
2192 (const :format
"DOS "
2193 :sibling-args
(:help-echo
"\
2196 (const :format
"TTY%n"
2197 :sibling-args
(:help-echo
"\
2198 Plain text terminals.")
2200 (group :sibling-args
(:help-echo
"\
2201 Only match the frames with the specified color support.")
2202 (const :format
"Class: "
2204 (checklist :inline t
2206 (const :format
"Color "
2207 :sibling-args
(:help-echo
"\
2208 Match color frames.")
2210 (const :format
"Grayscale "
2211 :sibling-args
(:help-echo
"\
2212 Match grayscale frames.")
2214 (const :format
"Monochrome%n"
2215 :sibling-args
(:help-echo
"\
2216 Match frames with no color support.")
2218 (group :sibling-args
(:help-echo
"\
2219 Only match frames with the specified intensity.")
2221 Background brightness: "
2223 (checklist :inline t
2225 (const :format
"Light "
2226 :sibling-args
(:help-echo
"\
2227 Match frames with light backgrounds.")
2229 (const :format
"Dark\n"
2230 :sibling-args
(:help-echo
"\
2231 Match frames with dark backgrounds.")
2234 ;;; The `custom-face' Widget.
2236 (defface custom-face-tag-face
'((t (:underline t
)))
2237 "Face used for face tags."
2238 :group
'custom-faces
)
2240 (defcustom custom-face-default-form
'selected
2241 "Default form of displaying face definition."
2242 :type
'(choice (const all
)
2245 :group
'custom-buffer
2248 (define-widget 'custom-face
'custom
2250 :sample-face
'custom-face-tag-face
2251 :help-echo
"Set or reset this face."
2252 :documentation-property
'(lambda (face)
2253 (face-doc-string face
))
2254 :value-create
'custom-face-value-create
2255 :action
'custom-face-action
2256 :custom-category
'face
2257 :custom-form nil
; defaults to value of `custom-face-default-form'
2258 :custom-set
'custom-face-set
2259 :custom-save
'custom-face-save
2260 :custom-reset-current
'custom-redraw
2261 :custom-reset-saved
'custom-face-reset-saved
2262 :custom-reset-standard
'custom-face-reset-standard
2263 :custom-menu
'custom-face-menu-create
)
2265 (define-widget 'custom-face-all
'editable-list
2266 "An editable list of display specifications and attributes."
2267 :entry-format
"%i %d %v"
2268 :insert-button-args
'(:help-echo
"Insert new display specification here.")
2269 :append-button-args
'(:help-echo
"Append new display specification here.")
2270 :delete-button-args
'(:help-echo
"Delete this display specification.")
2271 :args
'((group :format
"%v" custom-display custom-face-edit
)))
2273 (defconst custom-face-all
(widget-convert 'custom-face-all
)
2274 "Converted version of the `custom-face-all' widget.")
2276 (define-widget 'custom-display-unselected
'item
2277 "A display specification that doesn't match the selected display."
2278 :match
'custom-display-unselected-match
)
2280 (defun custom-display-unselected-match (widget value
)
2281 "Non-nil if VALUE is an unselected display specification."
2282 (not (face-spec-set-match-display value
(selected-frame))))
2284 (define-widget 'custom-face-selected
'group
2285 "Edit the attributes of the selected display in a face specification."
2286 :args
'((repeat :format
""
2288 (group custom-display-unselected sexp
))
2289 (group (sexp :format
"") custom-face-edit
)
2294 (defconst custom-face-selected
(widget-convert 'custom-face-selected
)
2295 "Converted version of the `custom-face-selected' widget.")
2297 (defun custom-face-value-create (widget)
2298 "Create a list of the display specifications for WIDGET."
2299 (let ((buttons (widget-get widget
:buttons
))
2300 (symbol (widget-get widget
:value
))
2301 (tag (widget-get widget
:tag
))
2302 (state (widget-get widget
:custom-state
))
2304 (is-last (widget-get widget
:custom-last
))
2305 (prefix (widget-get widget
:custom-prefix
)))
2307 (setq tag
(prin1-to-string symbol
)))
2308 (cond ((eq custom-buffer-style
'tree
)
2309 (insert prefix
(if is-last
" `--- " " |--- "))
2310 (push (widget-create-child-and-convert
2311 widget
'custom-browse-face-tag
)
2313 (insert " " tag
"\n")
2314 (widget-put widget
:buttons buttons
))
2318 (if (eq custom-buffer-style
'face
)
2320 (widget-specify-sample widget begin
(point))
2323 (and (string-match "XEmacs" emacs-version
)
2324 ;; XEmacs cannot display uninitialized faces.
2325 (not (custom-facep symbol
))
2326 (copy-face 'custom-face-empty symbol
))
2327 (push (widget-create-child-and-convert widget
'item
2334 (push (widget-create-child-and-convert
2336 :help-echo
"Hide or show this face."
2337 :action
'custom-toggle-parent
2338 (not (eq state
'hidden
)))
2342 (let ((magic (widget-create-child-and-convert
2343 widget
'custom-magic nil
)))
2344 (widget-put widget
:custom-magic magic
)
2345 (push magic buttons
))
2347 (widget-put widget
:buttons buttons
)
2348 ;; Insert documentation.
2349 (widget-default-format-handler widget ?h
)
2351 (unless (eq state
'hidden
)
2352 (when (eq (widget-get widget
:custom-level
) 1)
2353 (custom-add-parent-links widget
))
2354 (custom-add-see-also widget
))
2356 (unless (eq (preceding-char) ?
\n)
2358 (unless (eq state
'hidden
)
2359 (message "Creating face editor...")
2360 (custom-load-widget widget
)
2361 (unless (widget-get widget
:custom-form
)
2362 (widget-put widget
:custom-form custom-face-default-form
))
2363 (let* ((symbol (widget-value widget
))
2364 (spec (or (get symbol
'saved-face
)
2365 (get symbol
'face-defface-spec
)
2366 ;; Attempt to construct it.
2367 (list (list t
(custom-face-attributes-get
2368 symbol
(selected-frame))))))
2369 (form (widget-get widget
:custom-form
))
2370 (indent (widget-get widget
:indent
))
2372 ;; If the user has changed this face in some other way,
2373 ;; edit it as the user has specified it.
2374 (if (not (face-spec-match-p symbol spec
(selected-frame)))
2375 (setq spec
(list (list t
(face-attr-construct symbol
(selected-frame))))))
2376 (setq edit
(widget-create-child-and-convert
2378 (cond ((and (eq form
'selected
)
2379 (widget-apply custom-face-selected
2381 (when indent
(insert-char ?\ indent
))
2382 'custom-face-selected
)
2383 ((and (not (eq form
'lisp
))
2384 (widget-apply custom-face-all
2388 (when indent
(insert-char ?\ indent
))
2391 (custom-face-state-set widget
)
2392 (widget-put widget
:children
(list edit
)))
2393 (message "Creating face editor...done"))))))
2395 (defvar custom-face-menu
2396 '(("Set for Current Session" custom-face-set
)
2397 ("Save for Future Sessions" custom-face-save-command
)
2398 ("Reset to Saved" custom-face-reset-saved
2400 (get (widget-value widget
) 'saved-face
)))
2401 ("Reset to Standard Setting" custom-face-reset-standard
2403 (get (widget-value widget
) 'face-defface-spec
)))
2404 ("---" ignore ignore
)
2405 ("Show all display specs" custom-face-edit-all
2407 (not (eq (widget-get widget
:custom-form
) 'all
))))
2408 ("Just current attributes" custom-face-edit-selected
2410 (not (eq (widget-get widget
:custom-form
) 'selected
))))
2411 ("Show as Lisp expression" custom-face-edit-lisp
2413 (not (eq (widget-get widget
:custom-form
) 'lisp
)))))
2414 "Alist of actions for the `custom-face' widget.
2415 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2416 the menu entry, ACTION is the function to call on the widget when the
2417 menu is selected, and FILTER is a predicate which takes a `custom-face'
2418 widget as an argument, and returns non-nil if ACTION is valid on that
2419 widget. If FILTER is nil, ACTION is always valid.")
2421 (defun custom-face-edit-selected (widget)
2422 "Edit selected attributes of the value of WIDGET."
2423 (widget-put widget
:custom-state
'unknown
)
2424 (widget-put widget
:custom-form
'selected
)
2425 (custom-redraw widget
))
2427 (defun custom-face-edit-all (widget)
2428 "Edit all attributes of the value of WIDGET."
2429 (widget-put widget
:custom-state
'unknown
)
2430 (widget-put widget
:custom-form
'all
)
2431 (custom-redraw widget
))
2433 (defun custom-face-edit-lisp (widget)
2434 "Edit the lisp representation of the value of WIDGET."
2435 (widget-put widget
:custom-state
'unknown
)
2436 (widget-put widget
:custom-form
'lisp
)
2437 (custom-redraw widget
))
2439 (defun custom-face-state-set (widget)
2440 "Set the state of WIDGET."
2441 (let ((symbol (widget-value widget
)))
2442 (widget-put widget
:custom-state
(cond ((get symbol
'customized-face
)
2444 ((get symbol
'saved-face
)
2446 ((get symbol
'face-defface-spec
)
2451 (defun custom-face-action (widget &optional event
)
2452 "Show the menu for `custom-face' WIDGET.
2453 Optional EVENT is the location for the menu."
2454 (if (eq (widget-get widget
:custom-state
) 'hidden
)
2455 (custom-toggle-hide widget
)
2456 (let* ((completion-ignore-case t
)
2457 (symbol (widget-get widget
:value
))
2458 (answer (widget-choose (concat "Operation on "
2459 (custom-unlispify-tag-name symbol
))
2460 (custom-menu-filter custom-face-menu
2464 (funcall answer widget
)))))
2466 (defun custom-face-set (widget)
2467 "Make the face attributes in WIDGET take effect."
2468 (let* ((symbol (widget-value widget
))
2469 (child (car (widget-get widget
:children
)))
2470 (value (widget-value child
)))
2471 (put symbol
'customized-face value
)
2472 (face-spec-set symbol value
)
2473 (custom-face-state-set widget
)
2474 (custom-redraw-magic widget
)))
2476 (defun custom-face-save-command (widget)
2477 "Save in `.emacs' the face attributes in WIDGET."
2478 (custom-face-save widget
)
2481 (defun custom-face-save (widget)
2482 "Prepare for saving WIDGET's face attributes, but don't write `.emacs'."
2483 (let* ((symbol (widget-value widget
))
2484 (child (car (widget-get widget
:children
)))
2485 (value (widget-value child
)))
2486 (face-spec-set symbol value
)
2487 (put symbol
'saved-face value
)
2488 (put symbol
'customized-face nil
)
2490 (custom-face-state-set widget
)
2491 (custom-redraw-magic widget
)))
2493 (defun custom-face-reset-saved (widget)
2494 "Restore WIDGET to the face's default attributes."
2495 (let* ((symbol (widget-value widget
))
2496 (child (car (widget-get widget
:children
)))
2497 (value (get symbol
'saved-face
)))
2499 (error "No saved value for this face"))
2500 (put symbol
'customized-face nil
)
2501 (face-spec-set symbol value
)
2502 (widget-value-set child value
)
2503 (custom-face-state-set widget
)
2504 (custom-redraw-magic widget
)))
2506 (defun custom-face-reset-standard (widget)
2507 "Restore WIDGET to the face's standard settings."
2508 (let* ((symbol (widget-value widget
))
2509 (child (car (widget-get widget
:children
)))
2510 (value (get symbol
'face-defface-spec
)))
2512 (error "No standard setting for this face"))
2513 (put symbol
'customized-face nil
)
2514 (when (get symbol
'saved-face
)
2515 (put symbol
'saved-face nil
)
2517 (face-spec-set symbol value
)
2518 (widget-value-set child value
)
2519 (custom-face-state-set widget
)
2520 (custom-redraw-magic widget
)))
2522 ;;; The `face' Widget.
2524 (define-widget 'face
'default
2525 "Select and customize a face."
2526 :convert-widget
'widget-value-convert-widget
2527 :button-prefix
'widget-push-button-prefix
2528 :button-suffix
'widget-push-button-suffix
2529 :format
"%t: %[select face%] %v"
2532 :value-create
'widget-face-value-create
2533 :value-delete
'widget-face-value-delete
2534 :value-get
'widget-value-value-get
2535 :validate
'widget-children-validate
2536 :action
'widget-face-action
2537 :match
'(lambda (widget value
) (symbolp value
)))
2539 (defun widget-face-value-create (widget)
2540 ;; Create a `custom-face' child.
2541 (let* ((symbol (widget-value widget
))
2542 (custom-buffer-style 'face
)
2543 (child (widget-create-child-and-convert
2547 (custom-magic-reset child
)
2548 (setq custom-options
(cons child custom-options
))
2549 (widget-put widget
:children
(list child
))))
2551 (defun widget-face-value-delete (widget)
2552 ;; Remove the child from the options.
2553 (let ((child (car (widget-get widget
:children
))))
2554 (setq custom-options
(delq child custom-options
))
2555 (widget-children-value-delete widget
)))
2557 (defvar face-history nil
2558 "History of entered face names.")
2560 (defun widget-face-action (widget &optional event
)
2561 "Prompt for a face."
2562 (let ((answer (completing-read "Face: "
2563 (mapcar (lambda (face)
2564 (list (symbol-name face
)))
2568 (unless (zerop (length answer
))
2569 (widget-value-set widget
(intern answer
))
2570 (widget-apply widget
:notify widget event
)
2573 ;;; The `hook' Widget.
2575 (define-widget 'hook
'list
2577 :value-to-internal
(lambda (widget value
)
2578 (if (and value
(symbolp value
))
2581 :match
(lambda (widget value
)
2583 (widget-group-match widget value
)))
2584 :convert-widget
'custom-hook-convert-widget
2587 (defun custom-hook-convert-widget (widget)
2588 ;; Handle `:custom-options'.
2589 (let* ((options (widget-get widget
:options
))
2590 (other `(editable-list :inline t
2591 :entry-format
"%i %d%v"
2592 (function :format
" %v")))
2594 (list `(checklist :inline t
2595 ,@(mapcar (lambda (entry)
2596 `(function-item ,entry
))
2600 (widget-put widget
:args args
)
2603 ;;; The `custom-group-link' Widget.
2605 (define-widget 'custom-group-link
'link
2606 "Show parent in other window when activated."
2607 :help-echo
"Create customization buffer for this group."
2608 :action
'custom-group-link-action
)
2610 (defun custom-group-link-action (widget &rest ignore
)
2611 (customize-group (widget-value widget
)))
2613 ;;; The `custom-group' Widget.
2615 (defcustom custom-group-tag-faces nil
2616 ;; In XEmacs, this ought to play games with font size.
2617 "Face used for group tags.
2618 The first member is used for level 1 groups, the second for level 2,
2619 and so forth. The remaining group tags are shown with
2620 `custom-group-tag-face'."
2621 :type
'(repeat face
)
2622 :group
'custom-faces
)
2624 (defface custom-group-tag-face-1
'((((class color
)
2626 (:foreground
"pink" :underline t
))
2629 (:foreground
"red" :underline t
))
2631 "Face used for group tags.")
2633 (defface custom-group-tag-face
'((((class color
)
2635 (:foreground
"light blue" :underline t
))
2638 (:foreground
"blue" :underline t
))
2640 "Face used for low level group tags."
2641 :group
'custom-faces
)
2643 (define-widget 'custom-group
'custom
2646 :sample-face-get
'custom-group-sample-face-get
2647 :documentation-property
'group-documentation
2648 :help-echo
"Set or reset all members of this group."
2649 :value-create
'custom-group-value-create
2650 :action
'custom-group-action
2651 :custom-category
'group
2652 :custom-set
'custom-group-set
2653 :custom-save
'custom-group-save
2654 :custom-reset-current
'custom-group-reset-current
2655 :custom-reset-saved
'custom-group-reset-saved
2656 :custom-reset-standard
'custom-group-reset-standard
2657 :custom-menu
'custom-group-menu-create
)
2659 (defun custom-group-sample-face-get (widget)
2660 ;; Use :sample-face.
2661 (or (nth (1- (widget-get widget
:custom-level
)) custom-group-tag-faces
)
2662 'custom-group-tag-face
))
2664 (define-widget 'custom-group-visibility
'visibility
2665 "An indicator and manipulator for hidden group contents."
2666 :create
'custom-group-visibility-create
)
2668 (defun custom-group-visibility-create (widget)
2669 (let ((visible (widget-value widget
)))
2671 (insert "--------")))
2672 (widget-default-create widget
))
2674 (defun custom-group-members (symbol groups-only
)
2675 "Return SYMBOL's custom group members.
2676 If GROUPS-ONLY non-nil, return only those members that are groups."
2677 (if (not groups-only
)
2678 (get symbol
'custom-group
)
2680 (dolist (entry (get symbol
'custom-group
))
2681 (when (eq (nth 1 entry
) 'custom-group
)
2682 (push entry members
)))
2683 (nreverse members
))))
2685 (defun custom-group-value-create (widget)
2686 "Insert a customize group for WIDGET in the current buffer."
2687 (let* ((state (widget-get widget
:custom-state
))
2688 (level (widget-get widget
:custom-level
))
2689 ;; (indent (widget-get widget :indent))
2690 (prefix (widget-get widget
:custom-prefix
))
2691 (buttons (widget-get widget
:buttons
))
2692 (tag (widget-get widget
:tag
))
2693 (symbol (widget-value widget
))
2694 (members (custom-group-members symbol
2695 (and (eq custom-buffer-style
'tree
)
2696 custom-browse-only-groups
))))
2697 (cond ((and (eq custom-buffer-style
'tree
)
2699 (or members
(custom-unloaded-widget-p widget
)))
2700 (custom-browse-insert-prefix prefix
)
2701 (push (widget-create-child-and-convert
2702 widget
'custom-browse-visibility
2703 ;; :tag-glyph "plus"
2707 ;; (widget-glyph-insert nil "-- " "horizontal")
2708 (push (widget-create-child-and-convert
2709 widget
'custom-browse-group-tag
)
2711 (insert " " tag
"\n")
2712 (widget-put widget
:buttons buttons
))
2713 ((and (eq custom-buffer-style
'tree
)
2714 (zerop (length members
)))
2715 (custom-browse-insert-prefix prefix
)
2717 ;; (widget-glyph-insert nil "[ ]" "empty")
2718 ;; (widget-glyph-insert nil "-- " "horizontal")
2719 (push (widget-create-child-and-convert
2720 widget
'custom-browse-group-tag
)
2722 (insert " " tag
"\n")
2723 (widget-put widget
:buttons buttons
))
2724 ((eq custom-buffer-style
'tree
)
2725 (custom-browse-insert-prefix prefix
)
2726 (custom-load-widget widget
)
2727 (if (zerop (length members
))
2729 (custom-browse-insert-prefix prefix
)
2731 ;; (widget-glyph-insert nil "[ ]" "empty")
2732 ;; (widget-glyph-insert nil "-- " "horizontal")
2733 (push (widget-create-child-and-convert
2734 widget
'custom-browse-group-tag
)
2736 (insert " " tag
"\n")
2737 (widget-put widget
:buttons buttons
))
2738 (push (widget-create-child-and-convert
2739 widget
'custom-browse-visibility
2740 ;; :tag-glyph "minus"
2744 ;; (widget-glyph-insert nil "-\\ " "top")
2745 (push (widget-create-child-and-convert
2746 widget
'custom-browse-group-tag
)
2748 (insert " " tag
"\n")
2749 (widget-put widget
:buttons buttons
)
2750 (message "Creating group...")
2751 (let* ((members (custom-sort-items members
2752 custom-browse-sort-alphabetically
2753 custom-browse-order-groups
))
2754 (prefixes (widget-get widget
:custom-prefixes
))
2755 (custom-prefix-list (custom-prefix-add symbol prefixes
))
2756 (extra-prefix (if (widget-get widget
:custom-last
)
2759 (prefix (concat prefix extra-prefix
))
2762 (setq entry
(car members
)
2763 members
(cdr members
))
2764 (push (widget-create-child-and-convert
2765 widget
(nth 1 entry
)
2767 :tag
(custom-unlispify-tag-name (nth 0 entry
))
2768 :custom-prefixes custom-prefix-list
2769 :custom-level
(1+ level
)
2770 :custom-last
(null members
)
2771 :value
(nth 0 entry
)
2772 :custom-prefix prefix
)
2774 (widget-put widget
:children
(reverse children
)))
2775 (message "Creating group...done")))
2778 ;; Create level indicator.
2779 (unless (eq custom-buffer-style
'links
)
2780 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
2783 (let ((begin (point)))
2785 (widget-specify-sample widget begin
(point)))
2787 ;; Create link/visibility indicator.
2788 (if (eq custom-buffer-style
'links
)
2789 (push (widget-create-child-and-convert
2790 widget
'custom-group-link
2794 (push (widget-create-child-and-convert
2795 widget
'custom-group-visibility
2796 :help-echo
"Show members of this group."
2797 :action
'custom-toggle-parent
2798 (not (eq state
'hidden
)))
2801 ;; Create magic button.
2802 (let ((magic (widget-create-child-and-convert
2803 widget
'custom-magic nil
)))
2804 (widget-put widget
:custom-magic magic
)
2805 (push magic buttons
))
2807 (widget-put widget
:buttons buttons
)
2808 ;; Insert documentation.
2809 (if (and (eq custom-buffer-style
'links
) (> level
1))
2810 (widget-put widget
:documentation-indent
0))
2811 (widget-default-format-handler widget ?h
))
2814 ;; Add parent groups references above the group.
2815 (if t
;;; This should test that the buffer
2816 ;;; was made to display a group.
2818 (if (custom-add-parent-links widget
2819 "Go to parent group:")
2821 ;; Create level indicator.
2822 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
2825 (let ((start (point)))
2827 (widget-specify-sample widget start
(point)))
2829 ;; Create visibility indicator.
2830 (unless (eq custom-buffer-style
'links
)
2832 (push (widget-create-child-and-convert
2834 :help-echo
"Hide members of this group."
2835 :action
'custom-toggle-parent
2836 (not (eq state
'hidden
)))
2839 ;; Create more dashes.
2840 ;; Use 76 instead of 75 to compensate for the temporary "<"
2841 ;; added by `widget-insert'.
2842 (insert-char ?-
(- 76 (current-column)
2843 (* custom-buffer-indent level
)))
2845 ;; Create magic button.
2846 (let ((magic (widget-create-child-and-convert
2847 widget
'custom-magic
2850 (widget-put widget
:custom-magic magic
)
2851 (push magic buttons
))
2853 (widget-put widget
:buttons buttons
)
2854 ;; Insert documentation.
2855 (widget-default-format-handler widget ?h
)
2857 (if nil
;;; This should test that the buffer
2858 ;;; was not made to display a group.
2860 (insert-char ?\ custom-buffer-indent
)
2861 (custom-add-parent-links widget
)))
2862 (custom-add-see-also widget
2863 (make-string (* custom-buffer-indent level
)
2866 (message "Creating group...")
2867 (custom-load-widget widget
)
2868 (let* ((members (custom-sort-items members
2869 custom-buffer-sort-alphabetically
2870 custom-buffer-order-groups
))
2871 (prefixes (widget-get widget
:custom-prefixes
))
2872 (custom-prefix-list (custom-prefix-add symbol prefixes
))
2873 (length (length members
))
2875 (children (mapcar (lambda (entry)
2876 (widget-insert "\n")
2878 Creating group members... %2d%%"
2879 (/ (* 100.0 count
) length
))
2880 (setq count
(1+ count
))
2882 (widget-create-child-and-convert
2883 widget
(nth 1 entry
)
2885 :tag
(custom-unlispify-tag-name
2887 :custom-prefixes custom-prefix-list
2888 :custom-level
(1+ level
)
2889 :value
(nth 0 entry
))
2890 (unless (eq (preceding-char) ?
\n)
2891 (widget-insert "\n"))))
2893 (message "Creating group magic...")
2894 (mapcar 'custom-magic-reset children
)
2895 (message "Creating group state...")
2896 (widget-put widget
:children children
)
2897 (custom-group-state-update widget
)
2898 (message "Creating group... done"))
2901 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
2902 (insert "\\- " (widget-get widget
:tag
) " group end ")
2903 (insert-char ?-
(- 75 (current-column) (* custom-buffer-indent level
)))
2906 (defvar custom-group-menu
2907 '(("Set for Current Session" custom-group-set
2909 (eq (widget-get widget
:custom-state
) 'modified
)))
2910 ("Save for Future Sessions" custom-group-save
2912 (memq (widget-get widget
:custom-state
) '(modified set
))))
2913 ("Reset to Current" custom-group-reset-current
2915 (memq (widget-get widget
:custom-state
) '(modified))))
2916 ("Reset to Saved" custom-group-reset-saved
2918 (memq (widget-get widget
:custom-state
) '(modified set
))))
2919 ("Reset to standard setting" custom-group-reset-standard
2921 (memq (widget-get widget
:custom-state
) '(modified set saved
)))))
2922 "Alist of actions for the `custom-group' widget.
2923 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2924 the menu entry, ACTION is the function to call on the widget when the
2925 menu is selected, and FILTER is a predicate which takes a `custom-group'
2926 widget as an argument, and returns non-nil if ACTION is valid on that
2927 widget. If FILTER is nil, ACTION is always valid.")
2929 (defun custom-group-action (widget &optional event
)
2930 "Show the menu for `custom-group' WIDGET.
2931 Optional EVENT is the location for the menu."
2932 (if (eq (widget-get widget
:custom-state
) 'hidden
)
2933 (custom-toggle-hide widget
)
2934 (let* ((completion-ignore-case t
)
2935 (answer (widget-choose (concat "Operation on "
2936 (custom-unlispify-tag-name
2937 (widget-get widget
:value
)))
2938 (custom-menu-filter custom-group-menu
2942 (funcall answer widget
)))))
2944 (defun custom-group-set (widget)
2945 "Set changes in all modified group members."
2946 (let ((children (widget-get widget
:children
)))
2947 (mapcar (lambda (child)
2948 (when (eq (widget-get child
:custom-state
) 'modified
)
2949 (widget-apply child
:custom-set
)))
2952 (defun custom-group-save (widget)
2953 "Save all modified group members."
2954 (let ((children (widget-get widget
:children
)))
2955 (mapcar (lambda (child)
2956 (when (memq (widget-get child
:custom-state
) '(modified set
))
2957 (widget-apply child
:custom-save
)))
2960 (defun custom-group-reset-current (widget)
2961 "Reset all modified group members."
2962 (let ((children (widget-get widget
:children
)))
2963 (mapcar (lambda (child)
2964 (when (eq (widget-get child
:custom-state
) 'modified
)
2965 (widget-apply child
:custom-reset-current
)))
2968 (defun custom-group-reset-saved (widget)
2969 "Reset all modified or set group members."
2970 (let ((children (widget-get widget
:children
)))
2971 (mapcar (lambda (child)
2972 (when (memq (widget-get child
:custom-state
) '(modified set
))
2973 (widget-apply child
:custom-reset-saved
)))
2976 (defun custom-group-reset-standard (widget)
2977 "Reset all modified, set, or saved group members."
2978 (let ((children (widget-get widget
:children
)))
2979 (mapcar (lambda (child)
2980 (when (memq (widget-get child
:custom-state
)
2981 '(modified set saved
))
2982 (widget-apply child
:custom-reset-standard
)))
2985 (defun custom-group-state-update (widget)
2987 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
2988 (let* ((children (widget-get widget
:children
))
2989 (states (mapcar (lambda (child)
2990 (widget-get child
:custom-state
))
2992 (magics custom-magic-alist
)
2995 (let ((magic (car (car magics
))))
2996 (if (and (not (eq magic
'hidden
))
2997 (memq magic states
))
3000 (setq magics
(cdr magics
)))))
3001 (widget-put widget
:custom-state found
)))
3002 (custom-magic-reset widget
))
3004 ;;; The `custom-save-all' Function.
3006 (defcustom custom-file nil
3007 "File used for storing customization information.
3008 The default is nil, which means to use your init file
3009 as specified by `user-init-file'. If you specify some other file,
3010 you need to explicitly load that file for the settings to take effect."
3011 :type
'(choice (const :tag
"Your Emacs init file" nil
) file
)
3014 (defun custom-file ()
3015 "Return the file name for saving customizations."
3019 (read-file-name "File for customizations: "
3020 "~/" nil nil
".emacs"))))
3022 (defun custom-save-delete (symbol)
3023 "Delete the call to SYMBOL from `custom-file'.
3024 Leave point at the location of the call, or after the last expression."
3025 (let ((default-major-mode))
3026 (set-buffer (find-file-noselect (custom-file))))
3027 (goto-char (point-min))
3030 (let ((sexp (condition-case nil
3031 (read (current-buffer))
3032 (end-of-file (throw 'found nil
)))))
3033 (when (and (listp sexp
)
3034 (eq (car sexp
) symbol
))
3035 (delete-region (save-excursion
3039 (throw 'found nil
))))))
3041 (defun custom-save-variables ()
3042 "Save all customized variables in `custom-file'."
3044 (custom-save-delete 'custom-set-variables
)
3045 (let ((standard-output (current-buffer)))
3048 (princ "(custom-set-variables")
3049 (mapatoms (lambda (symbol)
3050 (let ((value (get symbol
'saved-value
))
3051 (requests (get symbol
'custom-requests
))
3052 (now (not (or (get symbol
'standard-value
)
3053 (and (not (boundp symbol
))
3054 (not (get symbol
'force-value
)))))))
3071 (unless (looking-at "\n")
3074 (defun custom-save-faces ()
3075 "Save all customized faces in `custom-file'."
3077 (custom-save-delete 'custom-set-faces
)
3078 (let ((standard-output (current-buffer)))
3081 (princ "(custom-set-faces")
3082 (let ((value (get 'default
'saved-face
)))
3083 ;; The default face must be first, since it affects the others.
3085 (princ "\n '(default ")
3087 (if (or (get 'default
'face-defface-spec
)
3088 (and (not (custom-facep 'default
))
3089 (not (get 'default
'force-face
))))
3092 (mapatoms (lambda (symbol)
3093 (let ((value (get symbol
'saved-face
)))
3094 (when (and (not (eq symbol
'default
))
3095 ;; Don't print default face here.
3101 (if (or (get symbol
'face-defface-spec
)
3102 (and (not (custom-facep symbol
))
3103 (not (get symbol
'force-face
))))
3107 (unless (looking-at "\n")
3111 (defun customize-save-customized ()
3112 "Save all user options which have been set in this session."
3114 (mapatoms (lambda (symbol)
3115 (let ((face (get symbol
'customized-face
))
3116 (value (get symbol
'customized-value
)))
3118 (put symbol
'saved-face face
)
3119 (put symbol
'customized-face nil
))
3121 (put symbol
'saved-value value
)
3122 (put symbol
'customized-value nil
)))))
3123 ;; We really should update all custom buffers here.
3127 (defun custom-save-all ()
3128 "Save all customizations in `custom-file'."
3129 (let ((inhibit-read-only t
))
3130 (custom-save-variables)
3133 (let ((default-major-mode nil
))
3134 (set-buffer (find-file-noselect (custom-file))))
3137 ;;; The Customize Menu.
3141 (defcustom custom-menu-nesting
2
3142 "Maximum nesting in custom menus."
3144 :group
'custom-menu
)
3146 (defun custom-face-menu-create (widget symbol
)
3147 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
3148 (vector (custom-unlispify-menu-entry symbol
)
3149 `(customize-face ',symbol
)
3152 (defun custom-variable-menu-create (widget symbol
)
3153 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
3154 (let ((type (get symbol
'custom-type
)))
3155 (unless (listp type
)
3156 (setq type
(list type
)))
3157 (if (and type
(widget-get type
:custom-menu
))
3158 (widget-apply type
:custom-menu symbol
)
3159 (vector (custom-unlispify-menu-entry symbol
)
3160 `(customize-variable ',symbol
)
3163 ;; Add checkboxes to boolean variable entries.
3164 (widget-put (get 'boolean
'widget-type
)
3165 :custom-menu
(lambda (widget symbol
)
3166 (vector (custom-unlispify-menu-entry symbol
)
3167 `(customize-variable ',symbol
)
3169 ':selected symbol
)))
3171 (if (string-match "XEmacs" emacs-version
)
3172 ;; XEmacs can create menus dynamically.
3173 (defun custom-group-menu-create (widget symbol
)
3174 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
3175 `( ,(custom-unlispify-menu-entry symbol t
)
3176 :filter
(lambda (&rest junk
)
3177 (cdr (custom-menu-create ',symbol
)))))
3179 (defun custom-group-menu-create (widget symbol
)
3180 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
3181 ;; Limit the nesting.
3182 (let ((custom-menu-nesting (1- custom-menu-nesting
)))
3183 (custom-menu-create symbol
))))
3186 (defun custom-menu-create (symbol)
3187 "Create menu for customization group SYMBOL.
3188 The menu is in a format applicable to `easy-menu-define'."
3189 (let* ((item (vector (custom-unlispify-menu-entry symbol
)
3190 `(customize-group ',symbol
)
3192 (if (and (or (not (boundp 'custom-menu-nesting
))
3193 (>= custom-menu-nesting
0))
3194 (< (length (get symbol
'custom-group
)) widget-menu-max-size
))
3195 (let ((custom-prefix-list (custom-prefix-add symbol
3196 custom-prefix-list
))
3197 (members (custom-sort-items (get symbol
'custom-group
)
3198 custom-menu-sort-alphabetically
3199 custom-menu-order-groups
)))
3200 (custom-load-symbol symbol
)
3201 `(,(custom-unlispify-menu-entry symbol t
)
3204 ,@(mapcar (lambda (entry)
3205 (widget-apply (if (listp (nth 1 entry
))
3207 (list (nth 1 entry
)))
3208 :custom-menu
(nth 0 entry
)))
3213 (defun customize-menu-create (symbol &optional name
)
3214 "Return a customize menu for customization group SYMBOL.
3215 If optional NAME is given, use that as the name of the menu.
3216 Otherwise the menu will be named `Customize'.
3217 The format is suitable for use with `easy-menu-define'."
3219 (setq name
"Customize"))
3220 (if (string-match "XEmacs" emacs-version
)
3221 ;; We can delay it under XEmacs.
3223 :filter
(lambda (&rest junk
)
3224 (cdr (custom-menu-create ',symbol
))))
3225 ;; But we must create it now under Emacs.
3226 (cons name
(cdr (custom-menu-create symbol
)))))
3228 ;;; The Custom Mode.
3230 (defvar custom-mode-map nil
3231 "Keymap for `custom-mode'.")
3233 (unless custom-mode-map
3234 (setq custom-mode-map
(make-sparse-keymap))
3235 (set-keymap-parent custom-mode-map widget-keymap
)
3236 (suppress-keymap custom-mode-map
)
3237 (define-key custom-mode-map
" " 'scroll-up
)
3238 (define-key custom-mode-map
"\177" 'scroll-down
)
3239 (define-key custom-mode-map
"q" 'bury-buffer
)
3240 (define-key custom-mode-map
"u" 'Custom-goto-parent
)
3241 (define-key custom-mode-map
"n" 'widget-forward
)
3242 (define-key custom-mode-map
"p" 'widget-backward
)
3243 (define-key custom-mode-map
[mouse-1
] 'Custom-move-and-invoke
))
3245 (defun Custom-move-and-invoke (event)
3246 "Move to where you click, and if it is an active field, invoke it."
3248 (mouse-set-point event
)
3249 (if (widget-event-point event
)
3250 (let* ((pos (widget-event-point event
))
3251 (button (get-char-property pos
'button
)))
3253 (widget-button-click event
)))))
3255 (easy-menu-define Custom-mode-menu
3257 "Menu used in customization buffers."
3259 ,(customize-menu-create 'customize
)
3260 ["Set" Custom-set t
]
3261 ["Save" Custom-save t
]
3262 ["Reset to Current" Custom-reset-current t
]
3263 ["Reset to Saved" Custom-reset-saved t
]
3264 ["Reset to Standard Settings" Custom-reset-standard t
]
3265 ["Info" (Info-goto-node "(custom)The Customization Buffer") t
]))
3267 (defun Custom-goto-parent ()
3268 "Go to the parent group listed at the top of this buffer.
3269 If several parents are listed, go to the first of them."
3272 (goto-char (point-min))
3273 (if (search-forward "\nGo to parent group: " nil t
)
3274 (let* ((button (get-char-property (point) 'button
))
3275 (parent (downcase (widget-get button
:tag
))))
3276 (customize-group parent
)))))
3278 (defcustom custom-mode-hook nil
3279 "Hook called when entering custom-mode."
3281 :group
'custom-buffer
)
3283 (defun custom-state-buffer-message (widget)
3284 (if (eq (widget-get (widget-get widget
:parent
) :custom-state
) 'modified
)
3285 (message "To install your edits, invoke [State] and choose the Set operation")))
3287 (defun custom-mode ()
3288 "Major mode for editing customization buffers.
3290 The following commands are available:
3292 Move to next button or editable field. \\[widget-forward]
3293 Move to previous button or editable field. \\[widget-backward]
3294 \\<widget-field-keymap>\
3295 Complete content of editable text field. \\[widget-complete]
3296 \\<custom-mode-map>\
3297 Invoke button under the mouse pointer. \\[Custom-move-and-invoke]
3298 Invoke button under point. \\[widget-button-press]
3299 Set all modifications. \\[Custom-set]
3300 Make all modifications default. \\[Custom-save]
3301 Reset all modified options. \\[Custom-reset-current]
3302 Reset all modified or set options. \\[Custom-reset-saved]
3303 Reset all options. \\[Custom-reset-standard]
3305 Entry to this mode calls the value of `custom-mode-hook'
3306 if that value is non-nil."
3307 (kill-all-local-variables)
3308 (setq major-mode
'custom-mode
3310 (use-local-map custom-mode-map
)
3311 (easy-menu-add Custom-mode-menu
)
3312 (make-local-variable 'custom-options
)
3313 (make-local-variable 'widget-documentation-face
)
3314 (setq widget-documentation-face
'custom-documentation-face
)
3315 (make-local-variable 'widget-button-face
)
3316 (setq widget-button-face
'custom-button-face
)
3317 (make-local-hook 'widget-edit-functions
)
3318 (add-hook 'widget-edit-functions
'custom-state-buffer-message nil t
)
3319 (run-hooks 'custom-mode-hook
))
3325 ;; cus-edit.el ends here