1 ;;; cus-edit.el --- tools for customizing Emacs and Lisp packages
3 ;; Copyright (C) 1996, 1997, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
7 ;; Keywords: help, faces
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
28 ;; This file implements the code to create and edit customize buffers.
32 ;; No commands should have names starting with `custom-' because
33 ;; that interferes with completion. Use `customize-' for commands
34 ;; that the user will run with M-x, and `Custom-' for interactive commands.
41 (defvar custom-versions-load-alist
)) ; from cus-load
51 (put 'custom-define-hook
'custom-type
'hook
)
52 (put 'custom-define-hook
'standard-value
'(nil))
53 (custom-add-to-group 'customize
'custom-define-hook
'custom-variable
)
55 ;;; Customization Groups.
58 "Customization of the One True Editor."
59 :link
'(custom-manual "(emacs)Top"))
61 ;; Most of these groups are stolen from `finder.el',
63 "Basic text editing facilities."
67 "Abbreviation handling, typing shortcuts, macros."
71 (defgroup matching nil
72 "Various sorts of searching and matching."
75 (defgroup emulations nil
76 "Emulations of other editors."
83 (defgroup outlines nil
84 "Support for hierarchical outlining."
87 (defgroup external nil
88 "Interfacing to external utilities."
92 "Code related to the `bib' bibliography processor."
96 (defgroup processes nil
97 "Process, subshell, compilation, and job control support."
101 (defgroup convenience nil
102 "Convenience features for faster editing."
105 (defgroup programming nil
106 "Support for programming in other languages."
109 (defgroup languages nil
110 "Specialized modes for editing programming languages."
114 "Lisp support, including Emacs Lisp."
119 "Support for the C language and related languages."
127 "Support for object-oriented programming."
130 (defgroup applications nil
131 "Applications written in Emacs."
134 (defgroup calendar nil
135 "Calendar and time management support."
136 :group
'applications
)
139 "Modes for electronic-mail handling."
140 :group
'applications
)
143 "Support for netnews reading and posting."
144 :group
'applications
)
147 "Games, jokes and amusements."
148 :group
'applications
)
150 (defgroup development nil
151 "Support for further development of Emacs."
155 "Support for Emacs documentation."
158 (defgroup extensions nil
159 "Emacs Lisp language extensions."
162 (defgroup internal nil
163 "Code for Emacs internals, build process, defaults."
167 "Maintenance aids for the Emacs development group."
171 (defgroup environment nil
172 "Fitting Emacs with its environment."
176 "Communications, networking, remote access to files."
180 (defgroup hardware nil
181 "Support for interfacing with exotic hardware."
184 (defgroup terminals nil
185 "Support for terminal types."
189 "Front-ends/assistants for, or emulators of, UNIX features."
193 "Support code for vms."
197 "Internationalization and alternate character-set support."
202 "The X Window system."
206 "Support for Emacs frames and window systems."
210 "Support editing files of data."
214 "Support editing files."
222 "Code related to the TeX formatter."
226 "Support for multiple fonts."
229 (defgroup hypermedia nil
230 "Support for links between text or other media types."
234 "Support for on-line help systems."
237 (defgroup multimedia nil
238 "Non-textual support, specifically images and sound."
242 "Code local to your site."
245 (defgroup customize
'((widgets custom-group
))
246 "Customization of the Customization support."
247 :link
'(custom-manual "(elisp)Customization")
248 :link
'(url-link :tag
"(Old?) Development Page"
249 "http://www.dina.kvl.dk/~abraham/custom/")
253 (defgroup custom-faces nil
254 "Faces used by customize."
258 (defgroup custom-browse nil
259 "Control customize browser."
263 (defgroup custom-buffer nil
264 "Control customize buffers."
268 (defgroup custom-menu nil
269 "Control customize menus."
273 (defgroup abbrev-mode nil
274 "Word abbreviations mode."
278 "Storage allocation and gc for GNU Emacs Lisp interpreter."
279 :tag
"Storage Allocation"
283 "Undoing changes in buffers."
286 (defgroup modeline nil
287 "Content of the modeline."
291 "Indenting and filling text."
294 (defgroup editing-basics nil
295 "Most basic editing facilities."
298 (defgroup display nil
299 "How characters are displayed in buffers."
302 (defgroup execute nil
303 "Executing external commands."
306 (defgroup installation nil
307 "The Emacs installation."
315 "Internal Emacs limits."
319 "Debugging Emacs itself."
322 (defgroup minibuffer nil
323 "Controling the behaviour of the minibuffer."
326 (defgroup keyboard nil
327 "Input from the keyboard."
331 "Input from the mouse."
335 "Input from the menus."
338 (defgroup auto-save nil
339 "Preventing accidential loss of data."
342 (defgroup processes-basics nil
343 "Basic stuff dealing with processes."
347 "MULE Emacs internationalization."
350 (defgroup windows nil
351 "Windows within a frame."
356 (defun custom-quote (sexp)
357 "Quote SEXP iff it is not self quoting."
358 (if (or (memq sexp
'(t nil
))
361 (memq (car sexp
) '(lambda)))
365 ;;; (and (fboundp 'characterp)
366 ;;; (characterp sexp))
371 (defun custom-split-regexp-maybe (regexp)
372 "If REGEXP is a string, split it to a list at `\\|'.
373 You can get the original back with from the result with:
374 (mapconcat 'identity result \"\\|\")
376 IF REGEXP is not a string, return it unchanged."
380 (while (string-match "\\\\|" regexp start
)
381 (setq all
(cons (substring regexp start
(match-beginning 0)) all
)
382 start
(match-end 0)))
383 (nreverse (cons (substring regexp start
) all
)))
386 (defun custom-variable-prompt ()
387 "Prompt for a custom variable, defaulting to the variable at point.
388 Return a list suitable for use in `interactive'."
389 (let ((v (variable-at-point))
390 (enable-recursive-minibuffers t
)
392 (setq val
(completing-read
393 (if (and (symbolp v
) (custom-variable-p v
))
394 (format "Customize option: (default %s) " v
)
395 "Customize option: ")
396 obarray
'custom-variable-p t
))
397 (list (if (equal val
"")
398 (if (symbolp v
) v nil
)
401 (defun custom-menu-filter (menu widget
)
402 "Convert MENU to the form used by `widget-choose'.
403 MENU should be in the same format as `custom-variable-menu'.
404 WIDGET is the widget to apply the filter entries of MENU on."
406 current name action filter
)
408 (setq current
(car menu
)
410 action
(nth 1 current
)
411 filter
(nth 2 current
)
413 (if (or (null filter
) (funcall filter widget
))
414 (push (cons name action
) result
)
420 (defvar custom-prefix-list nil
421 "List of prefixes that should be ignored by `custom-unlispify'.")
423 (defcustom custom-unlispify-menu-entries t
424 "Display menu entries as words instead of symbols if non nil."
428 (defcustom custom-unlispify-remove-prefixes nil
429 "Non-nil means remove group prefixes from option names in buffer."
431 :group
'custom-buffer
434 (defun custom-unlispify-menu-entry (symbol &optional no-suffix
)
435 "Convert SYMBOL into a menu entry."
436 (cond ((not custom-unlispify-menu-entries
)
437 (symbol-name symbol
))
438 ((get symbol
'custom-tag
)
440 (get symbol
'custom-tag
)
441 (concat (get symbol
'custom-tag
) "...")))
444 (set-buffer (get-buffer-create " *Custom-Work*"))
446 (princ symbol
(current-buffer))
447 (goto-char (point-min))
448 ;; FIXME: Boolean variables are not predicates, so they shouldn't
449 ;; end with `-p'. -stef
450 ;; (when (and (eq (get symbol 'custom-type) 'boolean)
451 ;; (re-search-forward "-p\\'" nil t))
452 ;; (replace-match "" t t)
453 ;; (goto-char (point-min)))
454 (if custom-unlispify-remove-prefixes
455 (let ((prefixes custom-prefix-list
)
458 (setq prefix
(car prefixes
))
459 (if (search-forward prefix
(+ (point) (length prefix
)) t
)
462 (delete-region (point-min) (point)))
463 (setq prefixes
(cdr prefixes
))))))
464 (subst-char-in-region (point-min) (point-max) ?- ?\ t
)
465 (capitalize-region (point-min) (point-max))
467 (goto-char (point-max))
471 (defcustom custom-unlispify-tag-names t
472 "Display tag names as words instead of symbols if non nil."
473 :group
'custom-buffer
476 (defun custom-unlispify-tag-name (symbol)
477 "Convert SYMBOL into a menu entry."
478 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names
))
479 (custom-unlispify-menu-entry symbol t
)))
481 (defun custom-prefix-add (symbol prefixes
)
482 "Add SYMBOL to list of ignored PREFIXES."
483 (cons (or (get symbol
'custom-prefix
)
484 (concat (symbol-name symbol
) "-"))
489 (defcustom custom-guess-name-alist
494 ("-function\\'" function
)
495 ("-functions\\'" (repeat function
))
496 ("-list\\'" (repeat sexp
))
497 ("-alist\\'" (repeat (cons sexp sexp
))))
498 "Alist of (MATCH TYPE).
500 MATCH should be a regexp matching the name of a symbol, and TYPE should
501 be a widget suitable for editing the value of that symbol. The TYPE
502 of the first entry where MATCH matches the name of the symbol will be
505 This is used for guessing the type of variables not declared with
507 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
510 (defcustom custom-guess-doc-alist
511 '(("\\`\\*?Non-nil " boolean
))
512 "Alist of (MATCH TYPE).
514 MATCH should be a regexp matching a documentation string, and TYPE
515 should be a widget suitable for editing the value of a variable with
516 that documentation string. The TYPE of the first entry where MATCH
517 matches the name of the symbol will be used.
519 This is used for guessing the type of variables not declared with
521 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
524 (defun custom-guess-type (symbol)
525 "Guess a widget suitable for editing the value of SYMBOL.
526 This is done by matching SYMBOL with `custom-guess-name-alist' and
527 if that fails, the doc string with `custom-guess-doc-alist'."
528 (let ((name (symbol-name symbol
))
529 (names custom-guess-name-alist
)
532 (setq current
(car names
)
534 (when (string-match (nth 0 current
) name
)
535 (setq found
(nth 1 current
)
538 (let ((doc (documentation-property symbol
'variable-documentation
))
539 (docs custom-guess-doc-alist
))
542 (setq current
(car docs
)
544 (when (string-match (nth 0 current
) doc
)
545 (setq found
(nth 1 current
)
551 (defcustom custom-browse-sort-alphabetically nil
552 "If non-nil, sort members of each customization group alphabetically."
554 :group
'custom-browse
)
556 (defcustom custom-browse-order-groups nil
557 "If non-nil, order group members within each customization group.
558 If `first', order groups before non-groups.
559 If `last', order groups after non-groups."
560 :type
'(choice (const first
)
562 (const :tag
"none" nil
))
563 :group
'custom-browse
)
565 (defcustom custom-browse-only-groups nil
566 "If non-nil, show group members only within each customization group."
568 :group
'custom-browse
)
570 (defcustom custom-buffer-sort-alphabetically nil
571 "If non-nil, sort members of each customization group alphabetically."
573 :group
'custom-buffer
)
575 (defcustom custom-buffer-order-groups
'last
576 "If non-nil, order group members within each customization group.
577 If `first', order groups before non-groups.
578 If `last', order groups after non-groups."
579 :type
'(choice (const first
)
581 (const :tag
"none" nil
))
582 :group
'custom-buffer
)
584 (defcustom custom-menu-sort-alphabetically nil
585 "If non-nil, sort members of each customization group alphabetically."
589 (defcustom custom-menu-order-groups
'first
590 "If non-nil, order group members within each customization group.
591 If `first', order groups before non-groups.
592 If `last', order groups after non-groups."
593 :type
'(choice (const first
)
595 (const :tag
"none" nil
))
598 ;;;###autoload (add-hook 'same-window-regexps "\\`\\*Customiz.*\\*\\'")
600 (defun custom-sort-items (items sort-alphabetically order-groups
)
601 "Return a sorted copy of ITEMS.
602 ITEMS should be a `custom-group' property.
603 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
604 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
605 groups after non-groups, if nil do not order groups at all."
606 (sort (copy-sequence items
)
608 (let ((typea (nth 1 a
)) (typeb (nth 1 b
))
609 (namea (nth 0 a
)) (nameb (nth 0 b
)))
610 (cond ((not order-groups
)
611 ;; Since we don't care about A and B order, maybe sort.
612 (when sort-alphabetically
613 (string-lessp namea nameb
)))
614 ((eq typea
'custom-group
)
615 ;; If B is also a group, maybe sort. Otherwise, order A and B.
616 (if (eq typeb
'custom-group
)
617 (when sort-alphabetically
618 (string-lessp namea nameb
))
619 (eq order-groups
'first
)))
620 ((eq typeb
'custom-group
)
621 ;; Since A cannot be a group, order A and B.
622 (eq order-groups
'last
))
624 ;; Since A and B cannot be groups, sort.
625 (string-lessp namea nameb
)))))))
627 ;;; Custom Mode Commands.
629 (defvar custom-options nil
630 "Customization widgets in the current buffer.")
633 "Set changes in all modified options."
635 (let ((children custom-options
))
636 (mapc (lambda (child)
637 (when (eq (widget-get child
:custom-state
) 'modified
)
638 (widget-apply child
:custom-set
)))
641 (defun Custom-save ()
642 "Set all modified group members and save them."
644 (let ((children custom-options
))
645 (mapc (lambda (child)
646 (when (memq (widget-get child
:custom-state
)
647 '(modified set changed rogue
))
648 (widget-apply child
:custom-save
)))
652 (defvar custom-reset-menu
653 '(("Current" . Custom-reset-current
)
654 ("Saved" . Custom-reset-saved
)
655 ("Erase Customization (use standard settings)" . Custom-reset-standard
))
656 "Alist of actions for the `Reset' button.
657 The key is a string containing the name of the action, the value is a
658 Lisp function taking the widget as an element which will be called
659 when the action is chosen.")
661 (defun custom-reset (event)
662 "Select item from reset menu."
663 (let* ((completion-ignore-case t
)
664 (answer (widget-choose "Reset to"
670 (defun Custom-reset-current (&rest ignore
)
671 "Reset all modified group members to their current value."
673 (let ((children custom-options
))
674 (mapc (lambda (widget)
675 (if (memq (widget-get widget
:custom-state
)
677 (widget-apply widget
:custom-reset-current
)))
680 (defun Custom-reset-saved (&rest ignore
)
681 "Reset all modified or set group members to their saved value."
683 (let ((children custom-options
))
684 (mapc (lambda (widget)
685 (if (memq (widget-get widget
:custom-state
)
686 '(modified set changed rogue
))
687 (widget-apply widget
:custom-reset-saved
)))
690 (defun Custom-reset-standard (&rest ignore
)
691 "Erase all customization (either current or saved) for the group members.
692 The immediate result is to restore them to their standard settings.
693 This operation eliminates any saved settings for the group members,
694 making them as if they had never been customized at all."
696 (let ((children custom-options
))
697 (mapc (lambda (widget)
698 (and (widget-apply widget
:custom-standard-value
)
699 (if (memq (widget-get widget
:custom-state
)
700 '(modified set changed saved rogue
))
701 (widget-apply widget
:custom-reset-standard
))))
704 ;;; The Customize Commands
706 (defun custom-prompt-variable (prompt-var prompt-val
&optional comment
)
707 "Prompt for a variable and a value and return them as a list.
708 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
709 prompt for the value. The %s escape in PROMPT-VAL is replaced with
710 the name of the variable.
712 If the variable has a `variable-interactive' property, that is used as if
713 it were the arg to `interactive' (which see) to interactively read the value.
715 If the variable has a `custom-type' property, it must be a widget and the
716 `:prompt-value' property of that widget will be used for reading the value.
718 If optional COMMENT argument is non nil, also prompt for a comment and return
719 it as the third element in the list."
720 (let* ((var (read-variable prompt-var
))
721 (minibuffer-help-form '(describe-variable var
))
723 (let ((prop (get var
'variable-interactive
))
724 (type (get var
'custom-type
))
725 (prompt (format prompt-val var
)))
727 (setq type
(list type
)))
729 ;; Use VAR's `variable-interactive' property
730 ;; as an interactive spec for prompting.
731 (call-interactively (list 'lambda
'(arg)
732 (list 'interactive prop
)
735 (widget-prompt-value type
741 (eval-minibuffer prompt
))))))
744 (read-string "Comment: " (get var
'variable-comment
)))
748 (defun customize-set-value (variable value
&optional comment
)
749 "Set VARIABLE to VALUE, and return VALUE. VALUE is a Lisp object.
751 If VARIABLE has a `variable-interactive' property, that is used as if
752 it were the arg to `interactive' (which see) to interactively read the value.
754 If VARIABLE has a `custom-type' property, it must be a widget and the
755 `:prompt-value' property of that widget will be used for reading the value.
757 If given a prefix (or a COMMENT argument), also prompt for a comment."
758 (interactive (custom-prompt-variable "Set variable: "
762 (cond ((string= comment
"")
763 (put variable
'variable-comment nil
))
765 (put variable
'variable-comment comment
)))
766 (set variable value
))
769 (defun customize-set-variable (variable value
&optional comment
)
770 "Set the default for VARIABLE to VALUE, and return VALUE.
771 VALUE is a Lisp object.
773 If VARIABLE has a `custom-set' property, that is used for setting
774 VARIABLE, otherwise `set-default' is used.
776 The `customized-value' property of the VARIABLE will be set to a list
777 with a quoted VALUE as its sole list member.
779 If VARIABLE has a `variable-interactive' property, that is used as if
780 it were the arg to `interactive' (which see) to interactively read the value.
782 If VARIABLE has a `custom-type' property, it must be a widget and the
783 `:prompt-value' property of that widget will be used for reading the value.
785 If given a prefix (or a COMMENT argument), also prompt for a comment."
786 (interactive (custom-prompt-variable "Set variable: "
787 "Set customized value for %s to: "
789 (custom-load-symbol variable
)
790 (funcall (or (get variable
'custom-set
) 'set-default
) variable value
)
791 (put variable
'customized-value
(list (custom-quote value
)))
792 (cond ((string= comment
"")
793 (put variable
'variable-comment nil
)
794 (put variable
'customized-variable-comment nil
))
796 (put variable
'variable-comment comment
)
797 (put variable
'customized-variable-comment comment
)))
801 (defun customize-save-variable (variable value
&optional comment
)
802 "Set the default for VARIABLE to VALUE, and save it for future sessions.
805 If VARIABLE has a `custom-set' property, that is used for setting
806 VARIABLE, otherwise `set-default' is used.
808 The `customized-value' property of the VARIABLE will be set to a list
809 with a quoted VALUE as its sole list member.
811 If VARIABLE has a `variable-interactive' property, that is used as if
812 it were the arg to `interactive' (which see) to interactively read the value.
814 If VARIABLE has a `custom-type' property, it must be a widget and the
815 `:prompt-value' property of that widget will be used for reading the value.
817 If given a prefix (or a COMMENT argument), also prompt for a comment."
818 (interactive (custom-prompt-variable "Set and save variable: "
819 "Set and save value for %s as: "
821 (funcall (or (get variable
'custom-set
) 'set-default
) variable value
)
822 (put variable
'saved-value
(list (custom-quote value
)))
823 (custom-push-theme 'theme-value variable
'user
'set
(list (custom-quote value
)))
824 (cond ((string= comment
"")
825 (put variable
'variable-comment nil
)
826 (put variable
'saved-variable-comment nil
))
828 (put variable
'variable-comment comment
)
829 (put variable
'saved-variable-comment comment
)))
835 "Select a customization buffer which you can use to set user options.
836 User options are structured into \"groups\".
837 Initially the top-level group `Emacs' and its immediate subgroups
838 are shown; the contents of those subgroups are initially hidden."
840 (customize-group 'emacs
))
843 (defun customize-mode (mode)
844 "Customize options related to the current major mode.
845 If a prefix \\[universal-argument] was given (or if the current major mode has no known group),
846 then prompt for the MODE to customize."
849 (let ((completion-regexp-list '("-mode\\'"))
850 (group (custom-group-of-mode major-mode
)))
851 (if (and group
(not current-prefix-arg
))
854 (completing-read (if group
855 (format "Major mode (default %s): " major-mode
)
858 'custom-group-of-mode
859 t nil nil
(if group
(symbol-name major-mode
))))))))
860 (customize-group (custom-group-of-mode mode
)))
864 (defun customize-group (group)
865 "Customize GROUP, which must be a customization group."
866 (interactive (list (let ((completion-ignore-case t
))
867 (completing-read "Customize group: (default emacs) "
870 (or (get symbol
'custom-loads
)
871 (get symbol
'custom-group
)))
873 (when (stringp group
)
874 (if (string-equal "" group
)
876 (setq group
(intern group
))))
877 (let ((name (format "*Customize Group: %s*"
878 (custom-unlispify-tag-name group
))))
879 (if (get-buffer name
)
881 (custom-buffer-create (list (list group
'custom-group
))
883 (concat " for group "
884 (custom-unlispify-tag-name group
))))))
887 (defun customize-group-other-window (group)
888 "Customize GROUP, which must be a customization group."
889 (interactive (list (let ((completion-ignore-case t
))
890 (completing-read "Customize group: (default emacs) "
893 (or (get symbol
'custom-loads
)
894 (get symbol
'custom-group
)))
896 (when (stringp group
)
897 (if (string-equal "" group
)
899 (setq group
(intern group
))))
900 (let ((name (format "*Customize Group: %s*"
901 (custom-unlispify-tag-name group
))))
902 (if (get-buffer name
)
903 (let ((window (selected-window))
904 ;; Copied from `custom-buffer-create-other-window'.
906 (special-display-buffer-names nil
)
907 (special-display-regexps nil
)
908 (same-window-buffer-names nil
)
909 (same-window-regexps nil
))
911 (select-window window
))
912 (custom-buffer-create-other-window
913 (list (list group
'custom-group
))
915 (concat " for group "
916 (custom-unlispify-tag-name group
))))))
919 (defalias 'customize-variable
'customize-option
)
922 (defun customize-option (symbol)
923 "Customize SYMBOL, which must be a user option variable."
924 (interactive (custom-variable-prompt))
925 (custom-buffer-create (list (list symbol
'custom-variable
))
926 (format "*Customize Option: %s*"
927 (custom-unlispify-tag-name symbol
))))
930 (defalias 'customize-variable-other-window
'customize-option-other-window
)
933 (defun customize-option-other-window (symbol)
934 "Customize SYMBOL, which must be a user option variable.
935 Show the buffer in another window, but don't select it."
936 (interactive (custom-variable-prompt))
937 (custom-buffer-create-other-window
938 (list (list symbol
'custom-variable
))
939 (format "*Customize Option: %s*" (custom-unlispify-tag-name symbol
))))
941 (defvar customize-changed-options-previous-release
"20.2"
942 "Version for `customize-changed-options' to refer back to by default.")
945 (defun customize-changed-options (since-version)
946 "Customize all user option variables changed in Emacs itself.
947 This includes new user option variables and faces, and new
948 customization groups, as well as older options and faces whose default
949 values have changed since the previous major Emacs release.
951 With argument SINCE-VERSION (a string), customize all user option
952 variables that were added (or their meanings were changed) since that
955 (interactive "sCustomize options changed, since version (default all versions): ")
956 (if (equal since-version
"")
957 (setq since-version nil
)
958 (unless (condition-case nil
959 (numberp (read since-version
))
961 (signal 'wrong-type-argument
(list 'numberp since-version
))))
962 (unless since-version
963 (setq since-version customize-changed-options-previous-release
))
965 ;; Load the information for versions since since-version. We use
966 ;; custom-load-symbol for this.
967 (put 'custom-versions-load-alist
'custom-loads nil
)
968 (dolist (elt custom-versions-load-alist
)
969 (if (customize-version-lessp since-version
(car elt
))
970 (dolist (load (cdr elt
))
971 (custom-add-load 'custom-versions-load-alist load
))))
972 (custom-load-symbol 'custom-versions-load-alist
)
973 (put 'custom-versions-load-alist
'custom-loads nil
)
978 (let ((version (get symbol
'custom-version
)))
980 (when (customize-version-lessp since-version version
)
981 (if (or (get symbol
'custom-group
)
982 (get symbol
'group-documentation
))
983 (push (list symbol
'custom-group
) found
))
984 (if (custom-variable-p symbol
)
985 (push (list symbol
'custom-variable
) found
))
986 (if (custom-facep symbol
)
987 (push (list symbol
'custom-face
) found
)))))))
989 (custom-buffer-create (custom-sort-items found t
'first
)
990 "*Customize Changed Options*")
991 (error "No user option defaults have been changed since Emacs %s"
994 (defun customize-version-lessp (version1 version2
)
995 ;; Why are the versions strings, and given that they are, why aren't
996 ;; they converted to numbers and compared as such here? -- fx
998 ;; In case someone made a mistake and left out the quotes
999 ;; in the :version value.
1000 (if (numberp version2
)
1001 (setq version2
(prin1-to-string version2
)))
1002 (let (major1 major2 minor1 minor2
)
1003 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version1
)
1004 (setq major1
(read (or (match-string 1 version1
)
1006 (setq minor1
(read (or (match-string 3 version1
)
1008 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version2
)
1009 (setq major2
(read (or (match-string 1 version2
)
1011 (setq minor2
(read (or (match-string 3 version2
)
1013 (or (< major1 major2
)
1014 (and (= major1 major2
)
1015 (< minor1 minor2
)))))
1018 (defun customize-face (&optional face
)
1019 "Customize SYMBOL, which should be a face name or nil.
1020 If SYMBOL is nil, customize all faces.
1022 Interactively, when point is on text which has a face specified,
1023 suggest to customized that face, if it's customizable."
1025 (list (read-face-name "Customize face" "all faces" t
)))
1026 (if (member face
'(nil ""))
1027 (setq face
(face-list)))
1028 (if (and (listp face
) (null (cdr face
)))
1029 (setq face
(car face
)))
1031 (custom-buffer-create (custom-sort-items
1033 (list s
'custom-face
))
1036 "*Customize Faces*")
1037 (unless (facep face
)
1038 (error "Invalid face %S" face
))
1039 (custom-buffer-create (list (list face
'custom-face
))
1040 (format "*Customize Face: %s*"
1041 (custom-unlispify-tag-name face
)))))
1044 (defun customize-face-other-window (&optional face
)
1045 "Show customization buffer for face SYMBOL in other window.
1047 Interactively, when point is on text which has a face specified,
1048 suggest to customized that face, if it's customizable."
1050 (list (read-face-name "Customize face" "all faces" t
)))
1051 (if (member face
'(nil ""))
1052 (setq face
(face-list)))
1053 (if (and (listp face
) (null (cdr face
)))
1054 (setq face
(car face
)))
1056 (custom-buffer-create-other-window
1059 (list s
'custom-face
))
1062 "*Customize Faces*")
1063 (unless (facep face
)
1064 (error "Invalid face %S" face
))
1065 (custom-buffer-create-other-window
1066 (list (list face
'custom-face
))
1067 (format "*Customize Face: %s*"
1068 (custom-unlispify-tag-name face
)))))
1071 (defun customize-customized ()
1072 "Customize all user options set since the last save in this session."
1075 (mapatoms (lambda (symbol)
1076 (and (or (get symbol
'customized-face
)
1077 (get symbol
'customized-face-comment
))
1078 (custom-facep symbol
)
1079 (push (list symbol
'custom-face
) found
))
1080 (and (or (get symbol
'customized-value
)
1081 (get symbol
'customized-variable-comment
))
1083 (push (list symbol
'custom-variable
) found
))))
1085 (error "No customized user options")
1086 (custom-buffer-create (custom-sort-items found t nil
)
1087 "*Customize Customized*"))))
1090 (defun customize-saved ()
1091 "Customize all already saved user options."
1094 (mapatoms (lambda (symbol)
1095 (and (or (get symbol
'saved-face
)
1096 (get symbol
'saved-face-comment
))
1097 (custom-facep symbol
)
1098 (push (list symbol
'custom-face
) found
))
1099 (and (or (get symbol
'saved-value
)
1100 (get symbol
'saved-variable-comment
))
1102 (push (list symbol
'custom-variable
) found
))))
1104 (error "No saved user options")
1105 (custom-buffer-create (custom-sort-items found t nil
)
1106 "*Customize Saved*"))))
1109 (defun customize-apropos (regexp &optional all
)
1110 "Customize all user options matching REGEXP.
1111 If ALL is `options', include only options.
1112 If ALL is `faces', include only faces.
1113 If ALL is `groups', include only groups.
1114 If ALL is t (interactively, with prefix arg), include options which are not
1115 user-settable, as well as faces and groups."
1116 (interactive "sCustomize regexp: \nP")
1118 (mapatoms (lambda (symbol)
1119 (when (string-match regexp
(symbol-name symbol
))
1120 (when (and (not (memq all
'(faces options
)))
1121 (get symbol
'custom-group
))
1122 (push (list symbol
'custom-group
) found
))
1123 (when (and (not (memq all
'(options groups
)))
1124 (custom-facep symbol
))
1125 (push (list symbol
'custom-face
) found
))
1126 (when (and (not (memq all
'(groups faces
)))
1128 (or (get symbol
'saved-value
)
1129 (custom-variable-p symbol
)
1130 (if (memq all
'(nil options
))
1131 (user-variable-p symbol
)
1132 (get symbol
'variable-documentation
))))
1133 (push (list symbol
'custom-variable
) found
)))))
1135 (error "No matches")
1136 (custom-buffer-create (custom-sort-items found t
1137 custom-buffer-order-groups
)
1138 "*Customize Apropos*"))))
1141 (defun customize-apropos-options (regexp &optional arg
)
1142 "Customize all user options matching REGEXP.
1143 With prefix arg, include options which are not user-settable."
1144 (interactive "sCustomize regexp: \nP")
1145 (customize-apropos regexp
(or arg
'options
)))
1148 (defun customize-apropos-faces (regexp)
1149 "Customize all user faces matching REGEXP."
1150 (interactive "sCustomize regexp: \n")
1151 (customize-apropos regexp
'faces
))
1154 (defun customize-apropos-groups (regexp)
1155 "Customize all user groups matching REGEXP."
1156 (interactive "sCustomize regexp: \n")
1157 (customize-apropos regexp
'groups
))
1161 (defcustom custom-buffer-style
'links
1162 "Control the presentation style for customization buffers.
1163 The value should be a symbol, one of:
1165 brackets: groups nest within each other with big horizontal brackets.
1166 links: groups have links to subgroups."
1167 :type
'(radio (const brackets
)
1169 :group
'custom-buffer
)
1171 ;; If we pass BUFFER to `bury-buffer', the buffer isn't removed from
1173 (defun custom-bury-buffer (buffer)
1176 (defcustom custom-buffer-done-function
'custom-bury-buffer
1177 "*Function called to remove a Custom buffer when the user is done with it.
1178 Called with one argument, the buffer to remove."
1179 :type
'(choice (function-item :tag
"Bury buffer" custom-bury-buffer
)
1180 (function-item :tag
"Kill buffer" kill-buffer
)
1181 (function :tag
"Other"))
1183 :group
'custom-buffer
)
1185 (defcustom custom-buffer-indent
3
1186 "Number of spaces to indent nested groups."
1188 :group
'custom-buffer
)
1191 (defun custom-buffer-create (options &optional name description
)
1192 "Create a buffer containing OPTIONS.
1193 Optional NAME is the name of the buffer.
1194 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1195 SYMBOL is a customization option, and WIDGET is a widget for editing
1197 (unless name
(setq name
"*Customization*"))
1198 (kill-buffer (get-buffer-create name
))
1199 (pop-to-buffer (get-buffer-create name
))
1200 (custom-buffer-create-internal options description
))
1203 (defun custom-buffer-create-other-window (options &optional name description
)
1204 "Create a buffer containing OPTIONS.
1205 Optional NAME is the name of the buffer.
1206 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1207 SYMBOL is a customization option, and WIDGET is a widget for editing
1209 (unless name
(setq name
"*Customization*"))
1210 (kill-buffer (get-buffer-create name
))
1211 (let ((window (selected-window))
1213 (special-display-buffer-names nil
)
1214 (special-display-regexps nil
)
1215 (same-window-buffer-names nil
)
1216 (same-window-regexps nil
))
1217 (pop-to-buffer (get-buffer-create name
))
1218 (custom-buffer-create-internal options description
)
1219 (select-window window
)))
1221 (defcustom custom-reset-button-menu nil
1222 "If non-nil, only show a single reset button in customize buffers.
1223 This button will have a menu with all three reset operations."
1225 :group
'custom-buffer
)
1227 (defcustom custom-buffer-verbose-help t
1228 "If non-nil, include explanatory text in the customization buffer."
1230 :group
'custom-buffer
)
1232 (defun Custom-buffer-done (&rest ignore
)
1233 "Remove current buffer by calling `custom-buffer-done-function'."
1235 (funcall custom-buffer-done-function
(current-buffer)))
1237 (defcustom custom-raised-buttons
(not (equal (face-valid-attribute-values :box
)
1238 '(("unspecified" . unspecified
))))
1239 "If non-nil, indicate active buttons in a `raised-button' style.
1240 Otherwise use brackets."
1243 :group
'custom-buffer
)
1245 (defun custom-buffer-create-internal (options &optional description
)
1246 (message "Creating customization buffer...")
1248 (if custom-buffer-verbose-help
1250 (widget-insert "This is a customization buffer")
1252 (widget-insert description
))
1253 (widget-insert (format ".
1254 %s show active fields; type RET or click mouse-1
1255 on an active field to invoke its action. Editing an option value
1256 changes the text in the buffer; invoke the State button and
1257 choose the Set operation to set the option value.
1258 Invoke " (if custom-raised-buttons
1260 "Square brackets")))
1261 (widget-create 'info-link
1263 :help-echo
"Read the online help."
1264 "(emacs)Easy Customization")
1265 (widget-insert " for more information.\n\n")
1266 (message "Creating customization buttons...")
1267 (widget-insert "Operate on everything in this buffer:\n "))
1268 (widget-insert " "))
1269 (widget-create 'push-button
1270 :tag
"Set for Current Session"
1272 Make your editing in this buffer take effect for this session."
1273 :action
(lambda (widget &optional event
)
1276 (widget-create 'push-button
1277 :tag
"Save for Future Sessions"
1279 Make your editing in this buffer take effect for future Emacs sessions."
1280 :action
(lambda (widget &optional event
)
1282 (if custom-reset-button-menu
1285 (widget-create 'push-button
1287 :help-echo
"Show a menu with reset operations."
1288 :mouse-down-action
(lambda (&rest junk
) t
)
1289 :action
(lambda (widget &optional event
)
1290 (custom-reset event
))))
1291 (widget-insert "\n ")
1292 (widget-create 'push-button
1295 Reset all edited text in this buffer to reflect current values."
1296 :action
'Custom-reset-current
)
1298 (widget-create 'push-button
1299 :tag
"Reset to Saved"
1301 Reset all values in this buffer to their saved settings."
1302 :action
'Custom-reset-saved
)
1304 (widget-create 'push-button
1305 :tag
"Erase Customization"
1307 Un-customize all values in this buffer. They get their standard settings."
1308 :action
'Custom-reset-standard
))
1309 (if (not custom-buffer-verbose-help
)
1312 (widget-create 'info-link
1314 :help-echo
"Read the online help."
1315 "(emacs)Easy Customization")))
1317 (widget-create 'push-button
1320 (lambda (&rest ignore
)
1322 ((eq custom-buffer-done-function
1323 'custom-bury-buffer
)
1325 ((eq custom-buffer-done-function
'kill-buffer
)
1327 (t "Finish with this buffer")))
1328 :action
#'Custom-buffer-done
)
1329 (widget-insert "\n\n")
1330 (message "Creating customization items...")
1331 (buffer-disable-undo)
1332 (setq custom-options
1333 (if (= (length options
) 1)
1334 (mapcar (lambda (entry)
1335 (widget-create (nth 1 entry
)
1336 :documentation-shown t
1337 :custom-state
'unknown
1338 :tag
(custom-unlispify-tag-name
1340 :value
(nth 0 entry
)))
1343 (length (length options
)))
1344 (mapcar (lambda (entry)
1346 (message "Creating customization items ...%2d%%"
1347 (/ (* 100.0 count
) length
))
1348 (widget-create (nth 1 entry
)
1349 :tag
(custom-unlispify-tag-name
1351 :value
(nth 0 entry
))
1352 (setq count
(1+ count
))
1353 (unless (eq (preceding-char) ?
\n)
1354 (widget-insert "\n"))
1355 (widget-insert "\n")))
1357 (unless (eq (preceding-char) ?
\n)
1358 (widget-insert "\n"))
1359 (message "Creating customization items ...done")
1360 (unless (eq custom-buffer-style
'tree
)
1361 (mapc 'custom-magic-reset custom-options
))
1362 (message "Creating customization setup...")
1364 (buffer-enable-undo)
1365 (goto-char (point-min))
1366 (message "Creating customization buffer...done"))
1368 ;;; The Tree Browser.
1371 (defun customize-browse (&optional group
)
1372 "Create a tree browser for the customize hierarchy."
1375 (setq group
'emacs
))
1376 (let ((name "*Customize Browser*"))
1377 (kill-buffer (get-buffer-create name
))
1378 (pop-to-buffer (get-buffer-create name
)))
1381 Square brackets show active fields; type RET or click mouse-1
1382 on an active field to invoke its action.
1383 Invoke [+] below to expand a group, and [-] to collapse an expanded group.\n")
1384 (if custom-browse-only-groups
1386 Invoke the [Group] button below to edit that item in another window.\n\n")
1387 (widget-insert "Invoke the ")
1388 (widget-create 'item
1391 :tag-glyph
"folder")
1392 (widget-insert ", ")
1393 (widget-create 'item
1397 (widget-insert ", and ")
1398 (widget-create 'item
1401 :tag-glyph
"option")
1402 (widget-insert " buttons below to edit that
1403 item in another window.\n\n"))
1404 (let ((custom-buffer-style 'tree
))
1405 (widget-create 'custom-group
1407 :custom-state
'unknown
1408 :tag
(custom-unlispify-tag-name group
)
1411 (goto-char (point-min)))
1413 (define-widget 'custom-browse-visibility
'item
1414 "Control visibility of items in the customize tree browser."
1416 :action
'custom-browse-visibility-action
)
1418 (defun custom-browse-visibility-action (widget &rest ignore
)
1419 (let ((custom-buffer-style 'tree
))
1420 (custom-toggle-parent widget
)))
1422 (define-widget 'custom-browse-group-tag
'push-button
1423 "Show parent in other window when activated."
1426 :action
'custom-browse-group-tag-action
)
1428 (defun custom-browse-group-tag-action (widget &rest ignore
)
1429 (let ((parent (widget-get widget
:parent
)))
1430 (customize-group-other-window (widget-value parent
))))
1432 (define-widget 'custom-browse-variable-tag
'push-button
1433 "Show parent in other window when activated."
1436 :action
'custom-browse-variable-tag-action
)
1438 (defun custom-browse-variable-tag-action (widget &rest ignore
)
1439 (let ((parent (widget-get widget
:parent
)))
1440 (customize-variable-other-window (widget-value parent
))))
1442 (define-widget 'custom-browse-face-tag
'push-button
1443 "Show parent in other window when activated."
1446 :action
'custom-browse-face-tag-action
)
1448 (defun custom-browse-face-tag-action (widget &rest ignore
)
1449 (let ((parent (widget-get widget
:parent
)))
1450 (customize-face-other-window (widget-value parent
))))
1452 (defconst custom-browse-alist
'((" " "space")
1458 (defun custom-browse-insert-prefix (prefix)
1459 "Insert PREFIX. On XEmacs convert it to line graphics."
1460 ;; Fixme: do graphics.
1461 (if nil
; (string-match "XEmacs" emacs-version)
1464 (while (not (string-equal prefix
""))
1465 (let ((entry (substring prefix
0 3)))
1466 (setq prefix
(substring prefix
3))
1467 (let ((overlay (make-overlay (1- (point)) (point) nil t nil
))
1468 (name (nth 1 (assoc entry custom-browse-alist
))))
1469 (overlay-put overlay
'end-glyph
(widget-glyph-find name entry
))
1470 (overlay-put overlay
'start-open t
)
1471 (overlay-put overlay
'end-open t
)))))
1474 ;;; Modification of Basic Widgets.
1476 ;; We add extra properties to the basic widgets needed here. This is
1477 ;; fine, as long as we are careful to stay within out own namespace.
1479 ;; We want simple widgets to be displayed by default, but complex
1480 ;; widgets to be hidden.
1482 (widget-put (get 'item
'widget-type
) :custom-show t
)
1483 (widget-put (get 'editable-field
'widget-type
)
1484 :custom-show
(lambda (widget value
)
1485 (let ((pp (pp-to-string value
)))
1486 (cond ((string-match "\n" pp
)
1491 (widget-put (get 'menu-choice
'widget-type
) :custom-show t
)
1493 ;;; The `custom-manual' Widget.
1495 (define-widget 'custom-manual
'info-link
1496 "Link to the manual entry for this customization option."
1497 :help-echo
"Read the manual entry for this option."
1500 ;;; The `custom-magic' Widget.
1502 (defgroup custom-magic-faces nil
1503 "Faces used by the magic button."
1504 :group
'custom-faces
1505 :group
'custom-buffer
)
1507 (defface custom-invalid-face
'((((class color
))
1508 (:foreground
"yellow" :background
"red"))
1510 (:weight bold
:slant italic
:underline t
)))
1511 "Face used when the customize item is invalid."
1512 :group
'custom-magic-faces
)
1514 (defface custom-rogue-face
'((((class color
))
1515 (:foreground
"pink" :background
"black"))
1518 "Face used when the customize item is not defined for customization."
1519 :group
'custom-magic-faces
)
1521 (defface custom-modified-face
'((((class color
))
1522 (:foreground
"white" :background
"blue"))
1524 (:slant italic
:bold
)))
1525 "Face used when the customize item has been modified."
1526 :group
'custom-magic-faces
)
1528 (defface custom-set-face
'((((class color
))
1529 (:foreground
"blue" :background
"white"))
1532 "Face used when the customize item has been set."
1533 :group
'custom-magic-faces
)
1535 (defface custom-changed-face
'((((class color
))
1536 (:foreground
"white" :background
"blue"))
1539 "Face used when the customize item has been changed."
1540 :group
'custom-magic-faces
)
1542 (defface custom-saved-face
'((t (:underline t
)))
1543 "Face used when the customize item has been saved."
1544 :group
'custom-magic-faces
)
1546 (defconst custom-magic-alist
'((nil "#" underline
"\
1547 uninitialized, you should not see this.")
1548 (unknown "?" italic
"\
1549 unknown, you should not see this.")
1550 (hidden "-" default
"\
1551 hidden, invoke \"Show\" in the previous line to show." "\
1552 group now hidden, invoke \"Show\", above, to show contents.")
1553 (invalid "x" custom-invalid-face
"\
1554 the value displayed for this %c is invalid and cannot be set.")
1555 (modified "*" custom-modified-face
"\
1556 you have edited the value as text, but you have not set the %c." "\
1557 you have edited something in this group, but not set it.")
1558 (set "+" custom-set-face
"\
1559 you have set this %c, but not saved it for future sessions." "\
1560 something in this group has been set, but not saved.")
1561 (changed ":" custom-changed-face
"\
1562 this %c has been changed outside the customize buffer." "\
1563 something in this group has been changed outside customize.")
1564 (saved "!" custom-saved-face
"\
1565 this %c has been set and saved." "\
1566 something in this group has been set and saved.")
1567 (rogue "@" custom-rogue-face
"\
1568 this %c has not been changed with customize." "\
1569 something in this group is not prepared for customization.")
1570 (standard " " nil
"\
1571 this %c is unchanged from its standard setting." "\
1572 visible group members are all at standard settings."))
1573 "Alist of customize option states.
1574 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1576 STATE is one of the following symbols:
1579 For internal use, should never occur.
1581 For internal use, should never occur.
1583 This item is not being displayed.
1585 This item is modified, but has an invalid form.
1587 This item is modified, and has a valid form.
1589 This item has been set but not saved.
1591 The current value of this item has been changed temporarily.
1593 This item is marked for saving.
1595 This item has no customization information.
1597 This item is unchanged from the standard setting.
1599 MAGIC is a string used to present that state.
1601 FACE is a face used to present the state.
1603 ITEM-DESC is a string describing the state for options.
1605 GROUP-DESC is a string describing the state for groups. If this is
1606 left out, ITEM-DESC will be used.
1608 The string %c in either description will be replaced with the
1609 category of the item. These are `group'. `option', and `face'.
1611 The list should be sorted most significant first.")
1613 (defcustom custom-magic-show
'long
1614 "If non-nil, show textual description of the state.
1615 If `long', show a full-line description, not just one word."
1616 :type
'(choice (const :tag
"no" nil
)
1618 (other :tag
"short" short
))
1619 :group
'custom-buffer
)
1621 (defcustom custom-magic-show-hidden
'(option face
)
1622 "Control whether the State button is shown for hidden items.
1623 The value should be a list with the custom categories where the State
1624 button should be visible. Possible categories are `group', `option',
1626 :type
'(set (const group
) (const option
) (const face
))
1627 :group
'custom-buffer
)
1629 (defcustom custom-magic-show-button nil
1630 "Show a \"magic\" button indicating the state of each customization option."
1632 :group
'custom-buffer
)
1634 (define-widget 'custom-magic
'default
1635 "Show and manipulate state for a customization option."
1637 :action
'widget-parent-action
1640 :value-create
'custom-magic-value-create
1641 :value-delete
'widget-children-value-delete
)
1643 (defun widget-magic-mouse-down-action (widget &optional event
)
1644 ;; Non-nil unless hidden.
1645 (not (eq (widget-get (widget-get (widget-get widget
:parent
) :parent
)
1649 (defun custom-magic-value-create (widget)
1650 "Create compact status report for WIDGET."
1651 (let* ((parent (widget-get widget
:parent
))
1652 (state (widget-get parent
:custom-state
))
1653 (hidden (eq state
'hidden
))
1654 (entry (assq state custom-magic-alist
))
1655 (magic (nth 1 entry
))
1656 (face (nth 2 entry
))
1657 (category (widget-get parent
:custom-category
))
1658 (text (or (and (eq category
'group
)
1661 (form (widget-get parent
:custom-form
))
1663 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text
)
1664 (setq text
(concat (match-string 1 text
)
1665 (symbol-name category
)
1666 (match-string 2 text
))))
1667 (when (and custom-magic-show
1669 (memq category custom-magic-show-hidden
)))
1671 (when (and (eq category
'group
)
1672 (not (and (eq custom-buffer-style
'links
)
1673 (> (widget-get parent
:custom-level
) 1))))
1674 (insert-char ?\
(* custom-buffer-indent
1675 (widget-get parent
:custom-level
))))
1676 (push (widget-create-child-and-convert
1678 :help-echo
"Change the state of this item."
1679 :format
(if hidden
"%t" "%[%t%]")
1680 :button-prefix
'widget-push-button-prefix
1681 :button-suffix
'widget-push-button-suffix
1682 :mouse-down-action
'widget-magic-mouse-down-action
1686 (let ((start (point)))
1687 (if (eq custom-magic-show
'long
)
1689 (insert (symbol-name state
)))
1690 (cond ((eq form
'lisp
)
1692 ((eq form
'mismatch
)
1693 (insert " (mismatch)")))
1694 (put-text-property start
(point) 'face
'custom-state-face
))
1696 (when (and (eq category
'group
)
1697 (not (and (eq custom-buffer-style
'links
)
1698 (> (widget-get parent
:custom-level
) 1))))
1699 (insert-char ?\
(* custom-buffer-indent
1700 (widget-get parent
:custom-level
))))
1701 (when custom-magic-show-button
1702 (when custom-magic-show
1703 (let ((indent (widget-get parent
:indent
)))
1705 (insert-char ? indent
))))
1706 (push (widget-create-child-and-convert
1708 :mouse-down-action
'widget-magic-mouse-down-action
1712 :help-echo
"Change the state."
1713 :format
(if hidden
"%t" "%[%t%]")
1714 :tag
(if (memq form
'(lisp mismatch
))
1715 (concat "(" magic
")")
1716 (concat "[" magic
"]")))
1719 (widget-put widget
:children children
)))
1721 (defun custom-magic-reset (widget)
1722 "Redraw the :custom-magic property of WIDGET."
1723 (let ((magic (widget-get widget
:custom-magic
)))
1724 (widget-value-set magic
(widget-value magic
))))
1726 ;;; The `custom' Widget.
1728 (defface custom-button-face
1729 '((((type x w32 mac
) (class color
)) ; Like default modeline
1730 (:box
(:line-width
2 :style released-button
)
1731 :background
"lightgrey" :foreground
"black"))
1734 "Face used for buttons in customization buffers."
1736 :group
'custom-faces
)
1738 (defface custom-button-pressed-face
1739 '((((type x w32 mac
) (class color
))
1740 (:box
(:line-width
2 :style pressed-button
)
1741 :background
"lightgrey" :foreground
"black"))
1743 (:inverse-video t
)))
1744 "Face used for buttons in customization buffers."
1746 :group
'custom-faces
)
1748 (defface custom-documentation-face nil
1749 "Face used for documentation strings in customization buffers."
1750 :group
'custom-faces
)
1752 (defface custom-state-face
'((((class color
)
1754 (:foreground
"lime green"))
1757 (:foreground
"dark green"))
1759 "Face used for State descriptions in the customize buffer."
1760 :group
'custom-faces
)
1762 (define-widget 'custom
'default
1763 "Customize a user option."
1765 :convert-widget
'custom-convert-widget
1766 :notify
'custom-notify
1769 :custom-state
'hidden
1770 :documentation-property
'widget-subclass-responsibility
1771 :value-create
'widget-subclass-responsibility
1772 :value-delete
'widget-children-value-delete
1773 :value-get
'widget-value-value-get
1774 :validate
'widget-children-validate
1775 :match
(lambda (widget value
) (symbolp value
)))
1777 (defun custom-convert-widget (widget)
1778 "Initialize :value and :tag from :args in WIDGET."
1779 (let ((args (widget-get widget
:args
)))
1781 (widget-put widget
:value
(widget-apply widget
1782 :value-to-internal
(car args
)))
1783 (widget-put widget
:tag
(custom-unlispify-tag-name (car args
)))
1784 (widget-put widget
:args nil
)))
1787 (defun custom-notify (widget &rest args
)
1788 "Keep track of changes."
1789 (let ((state (widget-get widget
:custom-state
)))
1790 (unless (eq state
'modified
)
1791 (unless (memq state
'(nil unknown hidden
))
1792 (widget-put widget
:custom-state
'modified
))
1793 (custom-magic-reset widget
)
1794 (apply 'widget-default-notify widget args
))))
1796 (defun custom-redraw (widget)
1797 "Redraw WIDGET with current settings."
1798 (let ((line (count-lines (point-min) (point)))
1799 (column (current-column))
1801 (from (marker-position (widget-get widget
:from
)))
1802 (to (marker-position (widget-get widget
:to
))))
1804 (widget-value-set widget
(widget-value widget
))
1805 (custom-redraw-magic widget
))
1806 (when (and (>= pos from
) (<= pos to
))
1811 (goto-line (1+ line
)))
1812 (move-to-column column
))
1815 (defun custom-redraw-magic (widget)
1816 "Redraw WIDGET state with current settings."
1818 (let ((magic (widget-get widget
:custom-magic
)))
1820 (widget-value-set magic
(widget-value magic
))
1821 (when (setq widget
(widget-get widget
:group
))
1822 (custom-group-state-update widget
)))
1824 (setq widget nil
)))))
1827 (defun custom-show (widget value
)
1828 "Non-nil if WIDGET should be shown with VALUE by default."
1829 (let ((show (widget-get widget
:custom-show
)))
1835 (funcall show widget value
)))))
1837 (defun custom-load-widget (widget)
1838 "Load all dependencies for WIDGET."
1839 (custom-load-symbol (widget-value widget
)))
1841 (defun custom-unloaded-symbol-p (symbol)
1842 "Return non-nil if the dependencies of SYMBOL has not yet been loaded."
1844 (loads (get symbol
'custom-loads
))
1847 (setq load
(car loads
)
1849 (cond ((symbolp load
)
1850 (unless (featurep load
)
1852 ((assoc load load-history
))
1853 ((assoc (locate-library load
) load-history
)
1859 (defun custom-unloaded-widget-p (widget)
1860 "Return non-nil if the dependencies of WIDGET has not yet been loaded."
1861 (custom-unloaded-symbol-p (widget-value widget
)))
1863 (defun custom-toggle-hide (widget)
1864 "Toggle visibility of WIDGET."
1865 (custom-load-widget widget
)
1866 (let ((state (widget-get widget
:custom-state
)))
1867 (cond ((memq state
'(invalid modified
))
1868 (error "There are unset changes"))
1870 (widget-put widget
:custom-state
'unknown
))
1872 (widget-put widget
:documentation-shown nil
)
1873 (widget-put widget
:custom-state
'hidden
)))
1874 (custom-redraw widget
)
1877 (defun custom-toggle-parent (widget &rest ignore
)
1878 "Toggle visibility of parent of WIDGET."
1879 (custom-toggle-hide (widget-get widget
:parent
)))
1881 (defun custom-add-see-also (widget &optional prefix
)
1882 "Add `See also ...' to WIDGET if there are any links.
1883 Insert PREFIX first if non-nil."
1884 (let* ((symbol (widget-get widget
:value
))
1885 (links (get symbol
'custom-links
))
1886 (many (> (length links
) 2))
1887 (buttons (widget-get widget
:buttons
))
1888 (indent (widget-get widget
:indent
)))
1891 (insert-char ?\ indent
))
1894 (insert "See also ")
1896 (push (widget-create-child-and-convert widget
(car links
))
1898 (setq links
(cdr links
))
1907 (widget-put widget
:buttons buttons
))))
1909 (defun custom-add-parent-links (widget &optional initial-string
)
1910 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
1911 The value if non-nil if any parents were found.
1912 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
1913 (let ((name (widget-value widget
))
1914 (type (widget-type widget
))
1915 (buttons (widget-get widget
:buttons
))
1918 (insert (or initial-string
"Parent groups:"))
1919 (mapatoms (lambda (symbol)
1920 (let ((entry (assq name
(get symbol
'custom-group
))))
1921 (when (eq (nth 1 entry
) type
)
1923 (push (widget-create-child-and-convert
1924 widget
'custom-group-link
1925 :tag
(custom-unlispify-tag-name symbol
)
1929 (widget-put widget
:buttons buttons
)
1932 (delete-region start
(point)))
1935 ;;; The `custom-comment' Widget.
1937 ;; like the editable field
1938 (defface custom-comment-face
'((((class grayscale color
)
1940 (:background
"gray85"))
1941 (((class grayscale color
)
1943 (:background
"dim gray"))
1946 "Face used for comments on variables or faces"
1948 :group
'custom-faces
)
1950 ;; like font-lock-comment-face
1951 (defface custom-comment-tag-face
1952 '((((class color
) (background dark
)) (:foreground
"gray80"))
1953 (((class color
) (background light
)) (:foreground
"blue4"))
1954 (((class grayscale
) (background light
))
1955 (:foreground
"DimGray" :weight bold
:slant italic
))
1956 (((class grayscale
) (background dark
))
1957 (:foreground
"LightGray" :weight bold
:slant italic
))
1959 "Face used for variables or faces comment tags"
1960 :group
'custom-faces
)
1962 (define-widget 'custom-comment
'string
1965 :help-echo
"Edit a comment here."
1966 :sample-face
'custom-comment-tag-face
1967 :value-face
'custom-comment-face
1969 :create
'custom-comment-create
)
1971 (defun custom-comment-create (widget)
1972 (let* ((null-comment (equal "" (widget-value widget
))))
1973 (if (or (widget-get (widget-get widget
:parent
) :comment-shown
)
1975 (widget-default-create widget
)
1976 ;; `widget-default-delete' expects markers in these slots --
1977 ;; maybe it shouldn't.
1978 (widget-put widget
:from
(point-marker))
1979 (widget-put widget
:to
(point-marker)))))
1981 (defun custom-comment-hide (widget)
1982 (widget-put (widget-get widget
:parent
) :comment-shown nil
))
1984 ;; Those functions are for the menu. WIDGET is NOT the comment widget. It's
1985 ;; the global custom one
1986 (defun custom-comment-show (widget)
1987 (widget-put widget
:comment-shown t
)
1988 (custom-redraw widget
)
1991 (defun custom-comment-invisible-p (widget)
1992 (let ((val (widget-value (widget-get widget
:comment-widget
))))
1994 (not (widget-get widget
:comment-shown
)))))
1996 ;;; The `custom-variable' Widget.
1998 ;; When this was underlined blue, users confused it with a
1999 ;; Mosaic-style hyperlink...
2000 (defface custom-variable-tag-face
2003 (:foreground
"light blue" :weight bold
:height
1.2 :inherit variable-pitch
))
2006 (:foreground
"blue" :weight bold
:height
1.2 :inherit variable-pitch
))
2008 "Face used for unpushable variable tags."
2009 :group
'custom-faces
)
2011 (defface custom-variable-button-face
'((t (:underline t
:weight bold
)))
2012 "Face used for pushable variable tags."
2013 :group
'custom-faces
)
2015 (defcustom custom-variable-default-form
'edit
2016 "Default form of displaying variable values."
2017 :type
'(choice (const edit
)
2019 :group
'custom-buffer
2022 (define-widget 'custom-variable
'custom
2023 "Customize variable."
2025 :help-echo
"Set or reset this variable."
2026 :documentation-property
'variable-documentation
2027 :custom-category
'option
2029 :custom-menu
'custom-variable-menu-create
2030 :custom-form nil
; defaults to value of `custom-variable-default-form'
2031 :value-create
'custom-variable-value-create
2032 :action
'custom-variable-action
2033 :custom-set
'custom-variable-set
2034 :custom-save
'custom-variable-save
2035 :custom-reset-current
'custom-redraw
2036 :custom-reset-saved
'custom-variable-reset-saved
2037 :custom-reset-standard
'custom-variable-reset-standard
2038 :custom-standard-value
'custom-variable-standard-value
)
2040 (defun custom-variable-type (symbol)
2041 "Return a widget suitable for editing the value of SYMBOL.
2042 If SYMBOL has a `custom-type' property, use that.
2043 Otherwise, look up symbol in `custom-guess-type-alist'."
2044 (let* ((type (or (get symbol
'custom-type
)
2045 (and (not (get symbol
'standard-value
))
2046 (custom-guess-type symbol
))
2048 (options (get symbol
'custom-options
))
2049 (tmp (if (listp type
)
2050 (copy-sequence type
)
2053 (widget-put tmp
:options options
))
2056 (defun custom-variable-value-create (widget)
2057 "Here is where you edit the variable's value."
2058 (custom-load-widget widget
)
2059 (unless (widget-get widget
:custom-form
)
2060 (widget-put widget
:custom-form custom-variable-default-form
))
2061 (let* ((buttons (widget-get widget
:buttons
))
2062 (children (widget-get widget
:children
))
2063 (form (widget-get widget
:custom-form
))
2064 (state (widget-get widget
:custom-state
))
2065 (symbol (widget-get widget
:value
))
2066 (tag (widget-get widget
:tag
))
2067 (type (custom-variable-type symbol
))
2068 (conv (widget-convert type
))
2069 (get (or (get symbol
'custom-get
) 'default-value
))
2070 (prefix (widget-get widget
:custom-prefix
))
2071 (last (widget-get widget
:custom-last
))
2072 (value (if (default-boundp symbol
)
2073 (funcall get symbol
)
2074 (widget-get conv
:value
))))
2075 ;; If the widget is new, the child determines whether it is hidden.
2077 ((custom-show type value
)
2078 (setq state
'unknown
))
2080 (setq state
'hidden
)))
2081 ;; If we don't know the state, see if we need to edit it in lisp form.
2082 (when (eq state
'unknown
)
2083 (unless (widget-apply conv
:match value
)
2084 ;; (widget-apply (widget-convert type) :match value)
2085 (setq form
'mismatch
)))
2086 ;; Now we can create the child widget.
2087 (cond ((eq custom-buffer-style
'tree
)
2088 (insert prefix
(if last
" `--- " " |--- "))
2089 (push (widget-create-child-and-convert
2090 widget
'custom-browse-variable-tag
)
2092 (insert " " tag
"\n")
2093 (widget-put widget
:buttons buttons
))
2095 ;; Indicate hidden value.
2096 (push (widget-create-child-and-convert
2099 :sample-face
'custom-variable-tag-face
2103 (push (widget-create-child-and-convert
2105 :help-echo
"Show the value of this option."
2107 :action
'custom-toggle-parent
2110 ((memq form
'(lisp mismatch
))
2111 ;; In lisp mode edit the saved value when possible.
2112 (let* ((value (cond ((get symbol
'saved-value
)
2113 (car (get symbol
'saved-value
)))
2114 ((get symbol
'standard-value
)
2115 (car (get symbol
'standard-value
)))
2116 ((default-boundp symbol
)
2117 (custom-quote (funcall get symbol
)))
2119 (custom-quote (widget-get conv
:value
))))))
2120 (insert (symbol-name symbol
) ": ")
2121 (push (widget-create-child-and-convert
2123 :help-echo
"Hide the value of this option."
2126 :action
'custom-toggle-parent
2130 (push (widget-create-child-and-convert
2132 :button-face
'custom-variable-button-face
2134 :tag
(symbol-name symbol
)
2140 (let* ((format (widget-get type
:format
))
2141 tag-format value-format
)
2142 (unless (string-match ":" format
)
2143 (error "Bad format"))
2144 (setq tag-format
(substring format
0 (match-end 0)))
2145 (setq value-format
(substring format
(match-end 0)))
2146 (push (widget-create-child-and-convert
2149 :action
'custom-tag-action
2150 :help-echo
"Change value of this option."
2151 :mouse-down-action
'custom-tag-mouse-down-action
2152 :button-face
'custom-variable-button-face
2153 :sample-face
'custom-variable-tag-face
2157 (push (widget-create-child-and-convert
2159 :help-echo
"Hide the value of this option."
2162 :action
'custom-toggle-parent
2165 (push (widget-create-child-and-convert
2167 :format value-format
2170 (unless (eq custom-buffer-style
'tree
)
2171 (unless (eq (preceding-char) ?
\n)
2172 (widget-insert "\n"))
2173 ;; Create the magic button.
2174 (let ((magic (widget-create-child-and-convert
2175 widget
'custom-magic nil
)))
2176 (widget-put widget
:custom-magic magic
)
2177 (push magic buttons
))
2178 ;; ### NOTE: this is ugly!!!! I need to update the :buttons property
2179 ;; before the call to `widget-default-format-handler'. Otherwise, I
2180 ;; loose my current `buttons'. This function shouldn't be called like
2181 ;; this anyway. The doc string widget should be added like the others.
2183 (widget-put widget
:buttons buttons
)
2185 ;; Insert documentation.
2186 (widget-default-format-handler widget ?h
)
2188 ;; The comment field
2189 (unless (eq state
'hidden
)
2190 (let* ((comment (get symbol
'variable-comment
))
2192 (widget-create-child-and-convert
2193 widget
'custom-comment
2195 :value
(or comment
""))))
2196 (widget-put widget
:comment-widget comment-widget
)
2197 ;; Don't push it !!! Custom assumes that the first child is the
2199 (setq children
(append children
(list comment-widget
)))))
2200 ;; Update the rest of the properties properties.
2201 (widget-put widget
:custom-form form
)
2202 (widget-put widget
:children children
)
2203 ;; Now update the state.
2204 (if (eq state
'hidden
)
2205 (widget-put widget
:custom-state state
)
2206 (custom-variable-state-set widget
))
2208 (unless (eq state
'hidden
)
2209 (when (eq (widget-get widget
:custom-level
) 1)
2210 (custom-add-parent-links widget
))
2211 (custom-add-see-also widget
)))))
2213 (defun custom-tag-action (widget &rest args
)
2214 "Pass :action to first child of WIDGET's parent."
2215 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2218 (defun custom-tag-mouse-down-action (widget &rest args
)
2219 "Pass :mouse-down-action to first child of WIDGET's parent."
2220 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2221 :mouse-down-action args
))
2223 (defun custom-variable-state-set (widget)
2224 "Set the state of WIDGET."
2225 (let* ((symbol (widget-value widget
))
2226 (get (or (get symbol
'custom-get
) 'default-value
))
2227 (value (if (default-boundp symbol
)
2228 (funcall get symbol
)
2229 (widget-get widget
:value
)))
2230 (comment (get symbol
'variable-comment
))
2233 (state (cond ((progn (setq tmp
(get symbol
'customized-value
))
2235 (get symbol
'customized-variable-comment
))
2237 (if (condition-case nil
2238 (and (equal value
(eval (car tmp
)))
2239 (equal comment temp
))
2243 ((progn (setq tmp
(get symbol
'saved-value
))
2244 (setq temp
(get symbol
'saved-variable-comment
))
2246 (if (condition-case nil
2247 (and (equal value
(eval (car tmp
)))
2248 (equal comment temp
))
2252 ((setq tmp
(get symbol
'standard-value
))
2253 (if (condition-case nil
2254 (and (equal value
(eval (car tmp
)))
2255 (equal comment nil
))
2260 (widget-put widget
:custom-state state
)))
2262 (defun custom-variable-standard-value (widget)
2263 (get (widget-value widget
) 'standard-value
))
2265 (defvar custom-variable-menu
2266 '(("Set for Current Session" custom-variable-set
2268 (eq (widget-get widget
:custom-state
) 'modified
)))
2269 ("Save for Future Sessions" custom-variable-save
2271 (memq (widget-get widget
:custom-state
) '(modified set changed rogue
))))
2272 ("Reset to Current" custom-redraw
2274 (and (default-boundp (widget-value widget
))
2275 (memq (widget-get widget
:custom-state
) '(modified changed
)))))
2276 ("Reset to Saved" custom-variable-reset-saved
2278 (and (or (get (widget-value widget
) 'saved-value
)
2279 (get (widget-value widget
) 'saved-variable-comment
))
2280 (memq (widget-get widget
:custom-state
)
2281 '(modified set changed rogue
)))))
2282 ("Erase Customization" custom-variable-reset-standard
2284 (and (get (widget-value widget
) 'standard-value
)
2285 (memq (widget-get widget
:custom-state
)
2286 '(modified set changed saved rogue
)))))
2287 ("Use Backup Value" custom-variable-reset-backup
2289 (get (widget-value widget
) 'backup-value
)))
2290 ("---" ignore ignore
)
2291 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
2292 ("---" ignore ignore
)
2293 ("Don't show as Lisp expression" custom-variable-edit
2295 (eq (widget-get widget
:custom-form
) 'lisp
)))
2296 ("Show initial Lisp expression" custom-variable-edit-lisp
2298 (eq (widget-get widget
:custom-form
) 'edit
))))
2299 "Alist of actions for the `custom-variable' widget.
2300 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2301 the menu entry, ACTION is the function to call on the widget when the
2302 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2303 widget as an argument, and returns non-nil if ACTION is valid on that
2304 widget. If FILTER is nil, ACTION is always valid.")
2306 (defun custom-variable-action (widget &optional event
)
2307 "Show the menu for `custom-variable' WIDGET.
2308 Optional EVENT is the location for the menu."
2309 (if (eq (widget-get widget
:custom-state
) 'hidden
)
2310 (custom-toggle-hide widget
)
2311 (unless (eq (widget-get widget
:custom-state
) 'modified
)
2312 (custom-variable-state-set widget
))
2313 (custom-redraw-magic widget
)
2314 (let* ((completion-ignore-case t
)
2315 (answer (widget-choose (concat "Operation on "
2316 (custom-unlispify-tag-name
2317 (widget-get widget
:value
)))
2318 (custom-menu-filter custom-variable-menu
2322 (funcall answer widget
)))))
2324 (defun custom-variable-edit (widget)
2325 "Edit value of WIDGET."
2326 (widget-put widget
:custom-state
'unknown
)
2327 (widget-put widget
:custom-form
'edit
)
2328 (custom-redraw widget
))
2330 (defun custom-variable-edit-lisp (widget)
2331 "Edit the Lisp representation of the value of WIDGET."
2332 (widget-put widget
:custom-state
'unknown
)
2333 (widget-put widget
:custom-form
'lisp
)
2334 (custom-redraw widget
))
2336 (defun custom-variable-set (widget)
2337 "Set the current value for the variable being edited by WIDGET."
2338 (let* ((form (widget-get widget
:custom-form
))
2339 (state (widget-get widget
:custom-state
))
2340 (child (car (widget-get widget
:children
)))
2341 (symbol (widget-value widget
))
2342 (set (or (get symbol
'custom-set
) 'set-default
))
2343 (comment-widget (widget-get widget
:comment-widget
))
2344 (comment (widget-value comment-widget
))
2346 (cond ((eq state
'hidden
)
2347 (error "Cannot set hidden variable"))
2348 ((setq val
(widget-apply child
:validate
))
2349 (goto-char (widget-get val
:from
))
2350 (error "%s" (widget-get val
:error
)))
2351 ((memq form
'(lisp mismatch
))
2352 (when (equal comment
"")
2354 ;; Make the comment invisible by hand if it's empty
2355 (custom-comment-hide comment-widget
))
2356 (custom-variable-backup-value widget
)
2357 (funcall set symbol
(eval (setq val
(widget-value child
))))
2358 (put symbol
'customized-value
(list val
))
2359 (put symbol
'variable-comment comment
)
2360 (put symbol
'customized-variable-comment comment
))
2362 (when (equal comment
"")
2364 ;; Make the comment invisible by hand if it's empty
2365 (custom-comment-hide comment-widget
))
2366 (custom-variable-backup-value widget
)
2367 (funcall set symbol
(setq val
(widget-value child
)))
2368 (put symbol
'customized-value
(list (custom-quote val
)))
2369 (put symbol
'variable-comment comment
)
2370 (put symbol
'customized-variable-comment comment
)))
2371 (custom-variable-state-set widget
)
2372 (custom-redraw-magic widget
)))
2374 (defun custom-variable-save (widget)
2375 "Set and save the value for the variable being edited by WIDGET."
2376 (let* ((form (widget-get widget
:custom-form
))
2377 (state (widget-get widget
:custom-state
))
2378 (child (car (widget-get widget
:children
)))
2379 (symbol (widget-value widget
))
2380 (set (or (get symbol
'custom-set
) 'set-default
))
2381 (comment-widget (widget-get widget
:comment-widget
))
2382 (comment (widget-value comment-widget
))
2384 (cond ((eq state
'hidden
)
2385 (error "Cannot set hidden variable"))
2386 ((setq val
(widget-apply child
:validate
))
2387 (goto-char (widget-get val
:from
))
2388 (error "Saving %s: %s" symbol
(widget-get val
:error
)))
2389 ((memq form
'(lisp mismatch
))
2390 (when (equal comment
"")
2392 ;; Make the comment invisible by hand if it's empty
2393 (custom-comment-hide comment-widget
))
2394 (put symbol
'saved-value
(list (widget-value child
)))
2395 (custom-push-theme 'theme-value symbol
'user
2396 'set
(list (widget-value child
)))
2397 (funcall set symbol
(eval (widget-value child
)))
2398 (put symbol
'variable-comment comment
)
2399 (put symbol
'saved-variable-comment comment
))
2401 (when (equal comment
"")
2403 ;; Make the comment invisible by hand if it's empty
2404 (custom-comment-hide comment-widget
))
2405 (put symbol
'saved-value
2406 (list (custom-quote (widget-value child
))))
2407 (custom-push-theme 'theme-value symbol
'user
2408 'set
(list (custom-quote (widget-value
2410 (funcall set symbol
(widget-value child
))
2411 (put symbol
'variable-comment comment
)
2412 (put symbol
'saved-variable-comment comment
)))
2413 (put symbol
'customized-value nil
)
2414 (put symbol
'customized-variable-comment nil
)
2416 (custom-variable-state-set widget
)
2417 (custom-redraw-magic widget
)))
2419 (defun custom-variable-reset-saved (widget)
2420 "Restore the saved value for the variable being edited by WIDGET.
2421 The value that was current before this operation
2422 becomes the backup value, so you can get it again."
2423 (let* ((symbol (widget-value widget
))
2424 (set (or (get symbol
'custom-set
) 'set-default
))
2425 (comment-widget (widget-get widget
:comment-widget
))
2426 (value (get symbol
'saved-value
))
2427 (comment (get symbol
'saved-variable-comment
)))
2428 (cond ((or value comment
)
2429 (put symbol
'variable-comment comment
)
2430 (custom-variable-backup-value widget
)
2432 (funcall set symbol
(eval (car value
)))
2435 (error "No saved value for %s" symbol
)))
2436 (put symbol
'customized-value nil
)
2437 (put symbol
'customized-variable-comment nil
)
2438 (widget-put widget
:custom-state
'unknown
)
2439 ;; This call will possibly make the comment invisible
2440 (custom-redraw widget
)))
2442 (defun custom-variable-reset-standard (widget)
2443 "Restore the standard setting for the variable being edited by WIDGET.
2444 This operation eliminates any saved setting for the variable,
2445 restoring it to the state of a variable that has never been customized.
2446 The value that was current before this operation
2447 becomes the backup value, so you can get it again."
2448 (let* ((symbol (widget-value widget
))
2449 (set (or (get symbol
'custom-set
) 'set-default
))
2450 (comment-widget (widget-get widget
:comment-widget
)))
2451 (if (get symbol
'standard-value
)
2453 (custom-variable-backup-value widget
)
2454 (funcall set symbol
(eval (car (get symbol
'standard-value
)))))
2455 (error "No standard setting known for %S" symbol
))
2456 (put symbol
'variable-comment nil
)
2457 (put symbol
'customized-value nil
)
2458 (put symbol
'customized-variable-comment nil
)
2459 (when (or (get symbol
'saved-value
) (get symbol
'saved-variable-comment
))
2460 (put symbol
'saved-value nil
)
2461 (custom-push-theme 'theme-value symbol
'user
'reset
'standard
)
2462 ;; As a special optimizations we do not (explictly)
2463 ;; save resets to standard when no theme set the value.
2464 (if (null (cdr (get symbol
'theme-value
)))
2465 (put symbol
'theme-value nil
))
2466 (put symbol
'saved-variable-comment nil
)
2468 (widget-put widget
:custom-state
'unknown
)
2469 ;; This call will possibly make the comment invisible
2470 (custom-redraw widget
)))
2472 (defun custom-variable-backup-value (widget)
2473 "Back up the current value for WIDGET's variable.
2474 The backup value is kept in the car of the `backup-value' property."
2475 (let* ((symbol (widget-value widget
))
2476 (get (or (get symbol
'custom-get
) 'default-value
))
2477 (type (custom-variable-type symbol
))
2478 (conv (widget-convert type
))
2479 (value (if (default-boundp symbol
)
2480 (funcall get symbol
)
2481 (widget-get conv
:value
))))
2482 (put symbol
'backup-value
(list value
))))
2484 (defun custom-variable-reset-backup (widget)
2485 "Restore the backup value for the variable being edited by WIDGET.
2486 The value that was current before this operation
2487 becomes the backup value, so you can use this operation repeatedly
2488 to switch between two values."
2489 (let* ((symbol (widget-value widget
))
2490 (set (or (get symbol
'custom-set
) 'set-default
))
2491 (value (get symbol
'backup-value
))
2492 (comment-widget (widget-get widget
:comment-widget
))
2493 (comment (widget-value comment-widget
)))
2496 (custom-variable-backup-value widget
)
2498 (funcall set symbol
(car value
))
2500 (error "No backup value for %s" symbol
))
2501 (put symbol
'customized-value
(list (car value
)))
2502 (put symbol
'variable-comment comment
)
2503 (put symbol
'customized-variable-comment comment
)
2504 (custom-variable-state-set widget
)
2505 ;; This call will possibly make the comment invisible
2506 (custom-redraw widget
)))
2508 ;;; The `custom-face-edit' Widget.
2510 (define-widget 'custom-face-edit
'checklist
2511 "Edit face attributes."
2515 :button-args
'(:help-echo
"Control whether this attribute has any effect.")
2516 :value-to-internal
'custom-face-edit-fix-value
2517 :match
(lambda (widget value
)
2518 (widget-checklist-match widget
2519 (custom-face-edit-fix-value widget value
)))
2520 :convert-widget
'custom-face-edit-convert-widget
2521 :args
(mapcar (lambda (att)
2524 :sibling-args
(widget-get (nth 1 att
) :sibling-args
)
2525 (list 'const
:format
"" :value
(nth 0 att
))
2527 custom-face-attributes
))
2529 (defun custom-face-edit-fix-value (widget value
)
2530 "Ignoring WIDGET, convert :bold and :italic in VALUE to new form.
2531 Also change :reverse-video to :inverse-video."
2535 (let ((key (car value
))
2536 (val (car (cdr value
))))
2537 (cond ((eq key
:italic
)
2538 (push :slant result
)
2539 (push (if val
'italic
'normal
) result
))
2541 (push :weight result
)
2542 (push (if val
'bold
'normal
) result
))
2543 ((eq key
:reverse-video
)
2544 (push :inverse-video result
)
2548 (push val result
))))
2549 (setq value
(cdr (cdr value
))))
2550 (setq result
(nreverse result
))
2554 (defun custom-face-edit-convert-widget (widget)
2555 "Convert :args as widget types in WIDGET."
2558 :args
(mapcar (lambda (arg)
2560 :deactivate
'custom-face-edit-deactivate
2561 :activate
'custom-face-edit-activate
2562 :delete
'custom-face-edit-delete
))
2563 (widget-get widget
:args
)))
2566 (defun custom-face-edit-deactivate (widget)
2567 "Make face widget WIDGET inactive for user modifications."
2568 (unless (widget-get widget
:inactive
)
2569 (let ((tag (custom-face-edit-attribute-tag widget
))
2570 (from (copy-marker (widget-get widget
:from
)))
2571 (to (widget-get widget
:to
))
2572 (value (widget-value widget
))
2573 (inhibit-read-only t
)
2574 (inhibit-modification-hooks t
))
2577 (widget-default-delete widget
)
2578 (insert tag
": *\n")
2579 (widget-put widget
:inactive
2580 (cons value
(cons from
(- (point) from
))))))))
2582 (defun custom-face-edit-activate (widget)
2583 "Make face widget WIDGET inactive for user modifications."
2584 (let ((inactive (widget-get widget
:inactive
))
2585 (inhibit-read-only t
)
2586 (inhibit-modification-hooks t
))
2587 (when (consp inactive
)
2589 (goto-char (car (cdr inactive
)))
2590 (delete-region (point) (+ (point) (cdr (cdr inactive
))))
2591 (widget-put widget
:inactive nil
)
2592 (widget-apply widget
:create
)
2593 (widget-value-set widget
(car inactive
))
2596 (defun custom-face-edit-delete (widget)
2597 "Remove widget from the buffer."
2598 (let ((inactive (widget-get widget
:inactive
))
2599 (inhibit-read-only t
)
2600 (inhibit-modification-hooks t
))
2602 ;; Widget is alive, we don't have to do anything special
2603 (widget-default-delete widget
)
2604 ;; WIDGET is already deleted because we did so to inactivate it;
2605 ;; now just get rid of the label we put in its place.
2606 (delete-region (car (cdr inactive
))
2607 (+ (car (cdr inactive
)) (cdr (cdr inactive
))))
2608 (widget-put widget
:inactive nil
))))
2611 (defun custom-face-edit-attribute-tag (widget)
2612 "Returns the first :tag property in WIDGET or one of its children."
2613 (let ((tag (widget-get widget
:tag
)))
2614 (or (and (not (equal tag
"")) tag
)
2615 (let ((children (widget-get widget
:children
)))
2616 (while (and (null tag
) children
)
2617 (setq tag
(custom-face-edit-attribute-tag (pop children
))))
2620 ;;; The `custom-display' Widget.
2622 (define-widget 'custom-display
'menu-choice
2623 "Select a display type."
2626 :help-echo
"Specify frames where the face attributes should be used."
2627 :args
'((const :tag
"all" t
)
2631 :args
((group :sibling-args
(:help-echo
"\
2632 Only match the specified window systems.")
2633 (const :format
"Type: "
2635 (checklist :inline t
2638 :sibling-args
(:help-echo
"\
2639 The X11 Window System.")
2641 (const :format
"PM "
2642 :sibling-args
(:help-echo
"\
2643 OS/2 Presentation Manager.")
2645 (const :format
"W32 "
2646 :sibling-args
(:help-echo
"\
2649 (const :format
"MAC "
2650 :sibling-args
(:help-echo
"\
2653 (const :format
"DOS "
2654 :sibling-args
(:help-echo
"\
2657 (const :format
"TTY%n"
2658 :sibling-args
(:help-echo
"\
2659 Plain text terminals.")
2661 (group :sibling-args
(:help-echo
"\
2662 Only match the frames with the specified color support.")
2663 (const :format
"Class: "
2665 (checklist :inline t
2667 (const :format
"Color "
2668 :sibling-args
(:help-echo
"\
2669 Match color frames.")
2671 (const :format
"Grayscale "
2672 :sibling-args
(:help-echo
"\
2673 Match grayscale frames.")
2675 (const :format
"Monochrome%n"
2676 :sibling-args
(:help-echo
"\
2677 Match frames with no color support.")
2679 (group :sibling-args
(:help-echo
"\
2680 Only match frames with the specified intensity.")
2682 Background brightness: "
2684 (checklist :inline t
2686 (const :format
"Light "
2687 :sibling-args
(:help-echo
"\
2688 Match frames with light backgrounds.")
2690 (const :format
"Dark\n"
2691 :sibling-args
(:help-echo
"\
2692 Match frames with dark backgrounds.")
2694 (group :sibling-args
(:help-echo
"\
2695 Only match frames that support the specified face attributes.")
2696 (const :format
"Supports attributes:" supports
)
2697 (custom-face-edit :inline t
:format
"%n%v"))))))
2699 ;;; The `custom-face' Widget.
2701 (defface custom-face-tag-face
2702 `((t (:weight bold
:height
1.2 :inherit variable-pitch
)))
2703 "Face used for face tags."
2704 :group
'custom-faces
)
2706 (defcustom custom-face-default-form
'selected
2707 "Default form of displaying face definition."
2708 :type
'(choice (const all
)
2711 :group
'custom-buffer
2714 (define-widget 'custom-face
'custom
2716 :sample-face
'custom-face-tag-face
2717 :help-echo
"Set or reset this face."
2718 :documentation-property
#'face-doc-string
2719 :value-create
'custom-face-value-create
2720 :action
'custom-face-action
2721 :custom-category
'face
2722 :custom-form nil
; defaults to value of `custom-face-default-form'
2723 :custom-set
'custom-face-set
2724 :custom-save
'custom-face-save
2725 :custom-reset-current
'custom-redraw
2726 :custom-reset-saved
'custom-face-reset-saved
2727 :custom-reset-standard
'custom-face-reset-standard
2728 :custom-standard-value
'custom-face-standard-value
2729 :custom-menu
'custom-face-menu-create
)
2731 (define-widget 'custom-face-all
'editable-list
2732 "An editable list of display specifications and attributes."
2733 :entry-format
"%i %d %v"
2734 :insert-button-args
'(:help-echo
"Insert new display specification here.")
2735 :append-button-args
'(:help-echo
"Append new display specification here.")
2736 :delete-button-args
'(:help-echo
"Delete this display specification.")
2737 :args
'((group :format
"%v" custom-display custom-face-edit
)))
2739 (defconst custom-face-all
(widget-convert 'custom-face-all
)
2740 "Converted version of the `custom-face-all' widget.")
2742 (define-widget 'custom-display-unselected
'item
2743 "A display specification that doesn't match the selected display."
2744 :match
'custom-display-unselected-match
)
2746 (defun custom-display-unselected-match (widget value
)
2747 "Non-nil if VALUE is an unselected display specification."
2748 (not (face-spec-set-match-display value
(selected-frame))))
2750 (define-widget 'custom-face-selected
'group
2751 "Edit the attributes of the selected display in a face specification."
2752 :args
'((repeat :format
""
2754 (group custom-display-unselected sexp
))
2755 (group (sexp :format
"") custom-face-edit
)
2760 (defconst custom-face-selected
(widget-convert 'custom-face-selected
)
2761 "Converted version of the `custom-face-selected' widget.")
2763 (defun custom-filter-face-spec (spec filter-index
&optional default-filter
)
2764 "Return a canonicalized version of SPEC using.
2765 FILTER-INDEX is the index in the entry for each attribute in
2766 `custom-face-attributes' at which the appropriate filter function can be
2767 found, and DEFAULT-FILTER is the filter to apply for attributes that
2769 (mapcar (lambda (entry)
2770 ;; Filter a single face-spec entry
2771 (let ((tests (car entry
))
2773 ;; Handle both old- and new-style attribute syntax
2774 (if (listp (car (cdr entry
)))
2777 (filtered-attrs nil
))
2778 ;; Filter each face attribute
2779 (while unfiltered-attrs
2780 (let* ((attr (pop unfiltered-attrs
))
2781 (pre-filtered-value (pop unfiltered-attrs
))
2783 (or (nth filter-index
(assq attr custom-face-attributes
))
2787 (funcall filter pre-filtered-value
)
2788 pre-filtered-value
)))
2789 (push filtered-value filtered-attrs
)
2790 (push attr filtered-attrs
)))
2792 (list tests filtered-attrs
)))
2795 (defun custom-pre-filter-face-spec (spec)
2796 "Return SPEC changed as necessary for editing by the face customization widget.
2797 SPEC must be a full face spec."
2798 (custom-filter-face-spec spec
2))
2800 (defun custom-post-filter-face-spec (spec)
2801 "Return the customized SPEC in a form suitable for setting the face."
2802 (custom-filter-face-spec spec
3))
2804 (defun custom-face-value-create (widget)
2805 "Create a list of the display specifications for WIDGET."
2806 (let ((buttons (widget-get widget
:buttons
))
2808 (symbol (widget-get widget
:value
))
2809 (tag (widget-get widget
:tag
))
2810 (state (widget-get widget
:custom-state
))
2812 (is-last (widget-get widget
:custom-last
))
2813 (prefix (widget-get widget
:custom-prefix
)))
2815 (setq tag
(prin1-to-string symbol
)))
2816 (cond ((eq custom-buffer-style
'tree
)
2817 (insert prefix
(if is-last
" `--- " " |--- "))
2818 (push (widget-create-child-and-convert
2819 widget
'custom-browse-face-tag
)
2821 (insert " " tag
"\n")
2822 (widget-put widget
:buttons buttons
))
2826 (widget-specify-sample widget begin
(point))
2827 (if (eq custom-buffer-style
'face
)
2829 (if (string-match "face\\'" tag
)
2831 (insert " face: ")))
2833 (push (widget-create-child-and-convert widget
'item
2840 (push (widget-create-child-and-convert
2842 :help-echo
"Hide or show this face."
2845 :action
'custom-toggle-parent
2846 (not (eq state
'hidden
)))
2850 (let ((magic (widget-create-child-and-convert
2851 widget
'custom-magic nil
)))
2852 (widget-put widget
:custom-magic magic
)
2853 (push magic buttons
))
2855 (widget-put widget
:buttons buttons
)
2856 ;; Insert documentation.
2857 (widget-default-format-handler widget ?h
)
2858 ;; The comment field
2859 (unless (eq state
'hidden
)
2860 (let* ((comment (get symbol
'face-comment
))
2862 (widget-create-child-and-convert
2863 widget
'custom-comment
2865 :value
(or comment
""))))
2866 (widget-put widget
:comment-widget comment-widget
)
2867 (push comment-widget children
)))
2869 (unless (eq state
'hidden
)
2870 (when (eq (widget-get widget
:custom-level
) 1)
2871 (custom-add-parent-links widget
))
2872 (custom-add-see-also widget
))
2874 (unless (eq (preceding-char) ?
\n)
2876 (unless (eq state
'hidden
)
2877 (message "Creating face editor...")
2878 (custom-load-widget widget
)
2879 (unless (widget-get widget
:custom-form
)
2880 (widget-put widget
:custom-form custom-face-default-form
))
2881 (let* ((symbol (widget-value widget
))
2882 (spec (or (get symbol
'customized-face
)
2883 (get symbol
'saved-face
)
2884 (get symbol
'face-defface-spec
)
2885 ;; Attempt to construct it.
2886 (list (list t
(custom-face-attributes-get
2887 symbol
(selected-frame))))))
2888 (form (widget-get widget
:custom-form
))
2889 (indent (widget-get widget
:indent
))
2891 ;; If the user has changed this face in some other way,
2892 ;; edit it as the user has specified it.
2893 (if (not (face-spec-match-p symbol spec
(selected-frame)))
2894 (setq spec
(list (list t
(face-attr-construct symbol
(selected-frame))))))
2895 (setq spec
(custom-pre-filter-face-spec spec
))
2896 (setq edit
(widget-create-child-and-convert
2898 (cond ((and (eq form
'selected
)
2899 (widget-apply custom-face-selected
2901 (when indent
(insert-char ?\ indent
))
2902 'custom-face-selected
)
2903 ((and (not (eq form
'lisp
))
2904 (widget-apply custom-face-all
2908 (when indent
(insert-char ?\ indent
))
2911 (custom-face-state-set widget
)
2912 (push edit children
)
2913 (widget-put widget
:children children
))
2914 (message "Creating face editor...done"))))))
2916 (defvar custom-face-menu
2917 '(("Set for Current Session" custom-face-set
)
2918 ("Save for Future Sessions" custom-face-save-command
)
2919 ("Reset to Saved" custom-face-reset-saved
2921 (or (get (widget-value widget
) 'saved-face
)
2922 (get (widget-value widget
) 'saved-face-comment
))))
2923 ("Erase Customization" custom-face-reset-standard
2925 (get (widget-value widget
) 'face-defface-spec
)))
2926 ("---" ignore ignore
)
2927 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
2928 ("---" ignore ignore
)
2929 ("Show all display specs" custom-face-edit-all
2931 (not (eq (widget-get widget
:custom-form
) 'all
))))
2932 ("Just current attributes" custom-face-edit-selected
2934 (not (eq (widget-get widget
:custom-form
) 'selected
))))
2935 ("Show as Lisp expression" custom-face-edit-lisp
2937 (not (eq (widget-get widget
:custom-form
) 'lisp
)))))
2938 "Alist of actions for the `custom-face' widget.
2939 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2940 the menu entry, ACTION is the function to call on the widget when the
2941 menu is selected, and FILTER is a predicate which takes a `custom-face'
2942 widget as an argument, and returns non-nil if ACTION is valid on that
2943 widget. If FILTER is nil, ACTION is always valid.")
2945 (defun custom-face-edit-selected (widget)
2946 "Edit selected attributes of the value of WIDGET."
2947 (widget-put widget
:custom-state
'unknown
)
2948 (widget-put widget
:custom-form
'selected
)
2949 (custom-redraw widget
))
2951 (defun custom-face-edit-all (widget)
2952 "Edit all attributes of the value of WIDGET."
2953 (widget-put widget
:custom-state
'unknown
)
2954 (widget-put widget
:custom-form
'all
)
2955 (custom-redraw widget
))
2957 (defun custom-face-edit-lisp (widget)
2958 "Edit the Lisp representation of the value of WIDGET."
2959 (widget-put widget
:custom-state
'unknown
)
2960 (widget-put widget
:custom-form
'lisp
)
2961 (custom-redraw widget
))
2963 (defun custom-face-state-set (widget)
2964 "Set the state of WIDGET."
2965 (let* ((symbol (widget-value widget
))
2966 (comment (get symbol
'face-comment
))
2968 (widget-put widget
:custom-state
2970 (setq tmp
(get symbol
'customized-face
))
2971 (setq temp
(get symbol
'customized-face-comment
))
2973 (if (equal temp comment
)
2977 (setq tmp
(get symbol
'saved-face
))
2978 (setq temp
(get symbol
'saved-face-comment
))
2980 (if (equal temp comment
)
2983 ((get symbol
'face-defface-spec
)
2984 (if (equal comment nil
)
2990 (defun custom-face-action (widget &optional event
)
2991 "Show the menu for `custom-face' WIDGET.
2992 Optional EVENT is the location for the menu."
2993 (if (eq (widget-get widget
:custom-state
) 'hidden
)
2994 (custom-toggle-hide widget
)
2995 (let* ((completion-ignore-case t
)
2996 (symbol (widget-get widget
:value
))
2997 (answer (widget-choose (concat "Operation on "
2998 (custom-unlispify-tag-name symbol
))
2999 (custom-menu-filter custom-face-menu
3003 (funcall answer widget
)))))
3005 (defun custom-face-set (widget)
3006 "Make the face attributes in WIDGET take effect."
3007 (let* ((symbol (widget-value widget
))
3008 (child (car (widget-get widget
:children
)))
3009 (value (custom-post-filter-face-spec (widget-value child
)))
3010 (comment-widget (widget-get widget
:comment-widget
))
3011 (comment (widget-value comment-widget
)))
3012 (when (equal comment
"")
3014 ;; Make the comment invisible by hand if it's empty
3015 (custom-comment-hide comment-widget
))
3016 (put symbol
'customized-face value
)
3017 (if (face-spec-choose value
)
3018 (face-spec-set symbol value
)
3019 ;; face-set-spec ignores empty attribute lists, so just give it
3020 ;; something harmless instead.
3021 (face-spec-set symbol
'((t :foreground unspecified
))))
3022 (put symbol
'customized-face-comment comment
)
3023 (put symbol
'face-comment comment
)
3024 (custom-face-state-set widget
)
3025 (custom-redraw-magic widget
)))
3027 (defun custom-face-save-command (widget)
3028 "Save in `.emacs' the face attributes in WIDGET."
3029 (custom-face-save widget
)
3032 (defun custom-face-save (widget)
3033 "Prepare for saving WIDGET's face attributes, but don't write `.emacs'."
3034 (let* ((symbol (widget-value widget
))
3035 (child (car (widget-get widget
:children
)))
3036 (value (custom-post-filter-face-spec (widget-value child
)))
3037 (comment-widget (widget-get widget
:comment-widget
))
3038 (comment (widget-value comment-widget
)))
3039 (when (equal comment
"")
3041 ;; Make the comment invisible by hand if it's empty
3042 (custom-comment-hide comment-widget
))
3043 (if (face-spec-choose value
)
3044 (face-spec-set symbol value
)
3045 ;; face-set-spec ignores empty attribute lists, so just give it
3046 ;; something harmless instead.
3047 (face-spec-set symbol
'((t :foreground unspecified
))))
3048 (unless (eq (widget-get widget
:custom-state
) 'standard
)
3049 (put symbol
'saved-face value
))
3050 (custom-push-theme 'theme-face symbol
'user
'set value
)
3051 (put symbol
'customized-face nil
)
3052 (put symbol
'face-comment comment
)
3053 (put symbol
'customized-face-comment nil
)
3054 (put symbol
'saved-face-comment comment
)
3056 (custom-face-state-set widget
)
3057 (custom-redraw-magic widget
)))
3059 (defun custom-face-reset-saved (widget)
3060 "Restore WIDGET to the face's default attributes."
3061 (let* ((symbol (widget-value widget
))
3062 (child (car (widget-get widget
:children
)))
3063 (value (get symbol
'saved-face
))
3064 (comment (get symbol
'saved-face-comment
))
3065 (comment-widget (widget-get widget
:comment-widget
)))
3066 (unless (or value comment
)
3067 (error "No saved value for this face"))
3068 (put symbol
'customized-face nil
)
3069 (put symbol
'customized-face-comment nil
)
3070 (face-spec-set symbol value
)
3071 (put symbol
'face-comment comment
)
3072 (widget-value-set child value
)
3073 ;; This call manages the comment visibility
3074 (widget-value-set comment-widget
(or comment
""))
3075 (custom-face-state-set widget
)
3076 (custom-redraw-magic widget
)))
3078 (defun custom-face-standard-value (widget)
3079 (get (widget-value widget
) 'face-defface-spec
))
3081 (defun custom-face-reset-standard (widget)
3082 "Restore WIDGET to the face's standard settings.
3083 This operation eliminates any saved setting for the face,
3084 restoring it to the state of a face that has never been customized."
3085 (let* ((symbol (widget-value widget
))
3086 (child (car (widget-get widget
:children
)))
3087 (value (get symbol
'face-defface-spec
))
3088 (comment-widget (widget-get widget
:comment-widget
)))
3090 (error "No standard setting for this face"))
3091 (put symbol
'customized-face nil
)
3092 (put symbol
'customized-face-comment nil
)
3093 (when (or (get symbol
'saved-face
) (get symbol
'saved-face-comment
))
3094 (put symbol
'saved-face nil
)
3095 (custom-push-theme 'theme-face symbol
'user
'reset
'standard
)
3096 ;; Do not explictly save resets to standards without themes.
3097 (if (null (cdr (get symbol
'theme-face
)))
3098 (put symbol
'theme-face nil
))
3099 (put symbol
'saved-face-comment nil
)
3101 (face-spec-set symbol value
)
3102 (put symbol
'face-comment nil
)
3103 (widget-value-set child value
)
3104 ;; This call manages the comment visibility
3105 (widget-value-set comment-widget
"")
3106 (custom-face-state-set widget
)
3107 (custom-redraw-magic widget
)))
3109 ;;; The `face' Widget.
3111 (define-widget 'face
'default
3112 "Select and customize a face."
3113 :convert-widget
'widget-value-convert-widget
3114 :button-prefix
'widget-push-button-prefix
3115 :button-suffix
'widget-push-button-suffix
3116 :format
"%{%t%}: %[select face%] %v"
3119 :value-create
'widget-face-value-create
3120 :value-delete
'widget-face-value-delete
3121 :value-get
'widget-value-value-get
3122 :validate
'widget-children-validate
3123 :action
'widget-face-action
3124 :match
(lambda (widget value
) (symbolp value
)))
3126 (defun widget-face-value-create (widget)
3127 "Create a `custom-face' child."
3128 (let* ((symbol (widget-value widget
))
3129 (custom-buffer-style 'face
)
3130 (child (widget-create-child-and-convert
3134 (custom-magic-reset child
)
3135 (setq custom-options
(cons child custom-options
))
3136 (widget-put widget
:children
(list child
))))
3138 (defun widget-face-value-delete (widget)
3139 "Remove the child from the options."
3140 (let ((child (car (widget-get widget
:children
))))
3141 (setq custom-options
(delq child custom-options
))
3142 (widget-children-value-delete widget
)))
3144 (defvar face-history nil
3145 "History of entered face names.")
3147 (defun widget-face-action (widget &optional event
)
3148 "Prompt for a face."
3149 (let ((answer (completing-read "Face: "
3150 (mapcar (lambda (face)
3151 (list (symbol-name face
)))
3155 (unless (zerop (length answer
))
3156 (widget-value-set widget
(intern answer
))
3157 (widget-apply widget
:notify widget event
)
3160 ;;; The `hook' Widget.
3162 (define-widget 'hook
'list
3164 :value-to-internal
(lambda (widget value
)
3165 (if (and value
(symbolp value
))
3168 :match
(lambda (widget value
)
3170 (widget-group-match widget value
)))
3171 ;; Avoid adding undefined functions to the hook, especially for
3172 ;; things like `find-file-hook' or even more basic ones, to avoid
3174 :set
(lambda (symbol value
)
3177 (add-hook symbol elt
))))
3178 :convert-widget
'custom-hook-convert-widget
3181 (defun custom-hook-convert-widget (widget)
3182 ;; Handle `:options'.
3183 (let* ((options (widget-get widget
:options
))
3184 (other `(editable-list :inline t
3185 :entry-format
"%i %d%v"
3186 (function :format
" %v")))
3188 (list `(checklist :inline t
3189 ,@(mapcar (lambda (entry)
3190 `(function-item ,entry
))
3194 (widget-put widget
:args args
)
3197 ;;; The `custom-group-link' Widget.
3199 (define-widget 'custom-group-link
'link
3200 "Show parent in other window when activated."
3201 :help-echo
"Create customization buffer for this group."
3202 :action
'custom-group-link-action
)
3204 (defun custom-group-link-action (widget &rest ignore
)
3205 (customize-group (widget-value widget
)))
3207 ;;; The `custom-group' Widget.
3209 (defcustom custom-group-tag-faces nil
3210 ;; In XEmacs, this ought to play games with font size.
3211 ;; Fixme: make it do so in Emacs.
3212 "Face used for group tags.
3213 The first member is used for level 1 groups, the second for level 2,
3214 and so forth. The remaining group tags are shown with
3215 `custom-group-tag-face'."
3216 :type
'(repeat face
)
3217 :group
'custom-faces
)
3219 (defface custom-group-tag-face-1
3222 (:foreground
"pink" :weight bold
:height
1.2 :inherit variable-pitch
))
3225 (:foreground
"red" :weight bold
:height
1.2 :inherit variable-pitch
))
3227 "Face used for group tags."
3228 :group
'custom-faces
)
3230 (defface custom-group-tag-face
3233 (:foreground
"light blue" :weight bold
:height
1.2))
3236 (:foreground
"blue" :weight bold
:height
1.2))
3238 "Face used for low level group tags."
3239 :group
'custom-faces
)
3241 (define-widget 'custom-group
'custom
3244 :sample-face-get
'custom-group-sample-face-get
3245 :documentation-property
'group-documentation
3246 :help-echo
"Set or reset all members of this group."
3247 :value-create
'custom-group-value-create
3248 :action
'custom-group-action
3249 :custom-category
'group
3250 :custom-set
'custom-group-set
3251 :custom-save
'custom-group-save
3252 :custom-reset-current
'custom-group-reset-current
3253 :custom-reset-saved
'custom-group-reset-saved
3254 :custom-reset-standard
'custom-group-reset-standard
3255 :custom-menu
'custom-group-menu-create
)
3257 (defun custom-group-sample-face-get (widget)
3258 ;; Use :sample-face.
3259 (or (nth (1- (widget-get widget
:custom-level
)) custom-group-tag-faces
)
3260 'custom-group-tag-face
))
3262 (define-widget 'custom-group-visibility
'visibility
3263 "An indicator and manipulator for hidden group contents."
3264 :create
'custom-group-visibility-create
)
3266 (defun custom-group-visibility-create (widget)
3267 (let ((visible (widget-value widget
)))
3269 (insert "--------")))
3270 (widget-default-create widget
))
3272 (defun custom-group-members (symbol groups-only
)
3273 "Return SYMBOL's custom group members.
3274 If GROUPS-ONLY non-nil, return only those members that are groups."
3275 (if (not groups-only
)
3276 (get symbol
'custom-group
)
3278 (dolist (entry (get symbol
'custom-group
))
3279 (when (eq (nth 1 entry
) 'custom-group
)
3280 (push entry members
)))
3281 (nreverse members
))))
3283 (defun custom-group-value-create (widget)
3284 "Insert a customize group for WIDGET in the current buffer."
3285 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
3286 (custom-load-widget widget
))
3287 (let* ((state (widget-get widget
:custom-state
))
3288 (level (widget-get widget
:custom-level
))
3289 ;; (indent (widget-get widget :indent))
3290 (prefix (widget-get widget
:custom-prefix
))
3291 (buttons (widget-get widget
:buttons
))
3292 (tag (widget-get widget
:tag
))
3293 (symbol (widget-value widget
))
3294 (members (custom-group-members symbol
3295 (and (eq custom-buffer-style
'tree
)
3296 custom-browse-only-groups
))))
3297 (cond ((and (eq custom-buffer-style
'tree
)
3299 (or members
(custom-unloaded-widget-p widget
)))
3300 (custom-browse-insert-prefix prefix
)
3301 (push (widget-create-child-and-convert
3302 widget
'custom-browse-visibility
3303 ;; :tag-glyph "plus"
3307 ;; (widget-glyph-insert nil "-- " "horizontal")
3308 (push (widget-create-child-and-convert
3309 widget
'custom-browse-group-tag
)
3311 (insert " " tag
"\n")
3312 (widget-put widget
:buttons buttons
))
3313 ((and (eq custom-buffer-style
'tree
)
3314 (zerop (length members
)))
3315 (custom-browse-insert-prefix prefix
)
3317 ;; (widget-glyph-insert nil "[ ]" "empty")
3318 ;; (widget-glyph-insert nil "-- " "horizontal")
3319 (push (widget-create-child-and-convert
3320 widget
'custom-browse-group-tag
)
3322 (insert " " tag
"\n")
3323 (widget-put widget
:buttons buttons
))
3324 ((eq custom-buffer-style
'tree
)
3325 (custom-browse-insert-prefix prefix
)
3326 (if (zerop (length members
))
3328 (custom-browse-insert-prefix prefix
)
3330 ;; (widget-glyph-insert nil "[ ]" "empty")
3331 ;; (widget-glyph-insert nil "-- " "horizontal")
3332 (push (widget-create-child-and-convert
3333 widget
'custom-browse-group-tag
)
3335 (insert " " tag
"\n")
3336 (widget-put widget
:buttons buttons
))
3337 (push (widget-create-child-and-convert
3338 widget
'custom-browse-visibility
3339 ;; :tag-glyph "minus"
3343 ;; (widget-glyph-insert nil "-\\ " "top")
3344 (push (widget-create-child-and-convert
3345 widget
'custom-browse-group-tag
)
3347 (insert " " tag
"\n")
3348 (widget-put widget
:buttons buttons
)
3349 (message "Creating group...")
3350 (let* ((members (custom-sort-items members
3351 custom-browse-sort-alphabetically
3352 custom-browse-order-groups
))
3353 (prefixes (widget-get widget
:custom-prefixes
))
3354 (custom-prefix-list (custom-prefix-add symbol prefixes
))
3355 (extra-prefix (if (widget-get widget
:custom-last
)
3358 (prefix (concat prefix extra-prefix
))
3361 (setq entry
(car members
)
3362 members
(cdr members
))
3363 (push (widget-create-child-and-convert
3364 widget
(nth 1 entry
)
3366 :tag
(custom-unlispify-tag-name (nth 0 entry
))
3367 :custom-prefixes custom-prefix-list
3368 :custom-level
(1+ level
)
3369 :custom-last
(null members
)
3370 :value
(nth 0 entry
)
3371 :custom-prefix prefix
)
3373 (widget-put widget
:children
(reverse children
)))
3374 (message "Creating group...done")))
3377 ;; Create level indicator.
3378 (unless (eq custom-buffer-style
'links
)
3379 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3382 (let ((begin (point)))
3384 (widget-specify-sample widget begin
(point)))
3386 ;; Create link/visibility indicator.
3387 (if (eq custom-buffer-style
'links
)
3388 (push (widget-create-child-and-convert
3389 widget
'custom-group-link
3393 (push (widget-create-child-and-convert
3394 widget
'custom-group-visibility
3395 :help-echo
"Show members of this group."
3396 :action
'custom-toggle-parent
3397 (not (eq state
'hidden
)))
3400 ;; Create magic button.
3401 (let ((magic (widget-create-child-and-convert
3402 widget
'custom-magic nil
)))
3403 (widget-put widget
:custom-magic magic
)
3404 (push magic buttons
))
3406 (widget-put widget
:buttons buttons
)
3407 ;; Insert documentation.
3408 (if (and (eq custom-buffer-style
'links
) (> level
1))
3409 (widget-put widget
:documentation-indent
0))
3410 (widget-default-format-handler widget ?h
))
3413 ;; Add parent groups references above the group.
3414 (if t
;;; This should test that the buffer
3415 ;;; was made to display a group.
3417 (if (custom-add-parent-links widget
3418 "Go to parent group:")
3420 ;; Create level indicator.
3421 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3424 (let ((start (point)))
3426 (widget-specify-sample widget start
(point)))
3428 ;; Create visibility indicator.
3429 (unless (eq custom-buffer-style
'links
)
3431 (push (widget-create-child-and-convert
3433 :help-echo
"Hide members of this group."
3434 :action
'custom-toggle-parent
3435 (not (eq state
'hidden
)))
3438 ;; Create more dashes.
3439 ;; Use 76 instead of 75 to compensate for the temporary "<"
3440 ;; added by `widget-insert'.
3441 (insert-char ?-
(- 76 (current-column)
3442 (* custom-buffer-indent level
)))
3444 ;; Create magic button.
3445 (let ((magic (widget-create-child-and-convert
3446 widget
'custom-magic
3449 (widget-put widget
:custom-magic magic
)
3450 (push magic buttons
))
3452 (widget-put widget
:buttons buttons
)
3453 ;; Insert documentation.
3454 (widget-default-format-handler widget ?h
)
3456 (if nil
;;; This should test that the buffer
3457 ;;; was not made to display a group.
3459 (insert-char ?\ custom-buffer-indent
)
3460 (custom-add-parent-links widget
)))
3461 (custom-add-see-also widget
3462 (make-string (* custom-buffer-indent level
)
3465 (message "Creating group...")
3466 (let* ((members (custom-sort-items members
3467 custom-buffer-sort-alphabetically
3468 custom-buffer-order-groups
))
3469 (prefixes (widget-get widget
:custom-prefixes
))
3470 (custom-prefix-list (custom-prefix-add symbol prefixes
))
3471 (length (length members
))
3473 (children (mapcar (lambda (entry)
3474 (widget-insert "\n")
3476 Creating group members... %2d%%"
3477 (/ (* 100.0 count
) length
))
3478 (setq count
(1+ count
))
3480 (widget-create-child-and-convert
3481 widget
(nth 1 entry
)
3483 :tag
(custom-unlispify-tag-name
3485 :custom-prefixes custom-prefix-list
3486 :custom-level
(1+ level
)
3487 :value
(nth 0 entry
))
3488 (unless (eq (preceding-char) ?
\n)
3489 (widget-insert "\n"))))
3491 (message "Creating group magic...")
3492 (mapc 'custom-magic-reset children
)
3493 (message "Creating group state...")
3494 (widget-put widget
:children children
)
3495 (custom-group-state-update widget
)
3496 (message "Creating group... done"))
3499 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3500 (insert "\\- " (widget-get widget
:tag
) " group end ")
3501 (insert-char ?-
(- 75 (current-column) (* custom-buffer-indent level
)))
3504 (defvar custom-group-menu
3505 '(("Set for Current Session" custom-group-set
3507 (eq (widget-get widget
:custom-state
) 'modified
)))
3508 ("Save for Future Sessions" custom-group-save
3510 (memq (widget-get widget
:custom-state
) '(modified set
))))
3511 ("Reset to Current" custom-group-reset-current
3513 (memq (widget-get widget
:custom-state
) '(modified))))
3514 ("Reset to Saved" custom-group-reset-saved
3516 (memq (widget-get widget
:custom-state
) '(modified set
))))
3517 ("Reset to standard setting" custom-group-reset-standard
3519 (memq (widget-get widget
:custom-state
) '(modified set saved
)))))
3520 "Alist of actions for the `custom-group' widget.
3521 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3522 the menu entry, ACTION is the function to call on the widget when the
3523 menu is selected, and FILTER is a predicate which takes a `custom-group'
3524 widget as an argument, and returns non-nil if ACTION is valid on that
3525 widget. If FILTER is nil, ACTION is always valid.")
3527 (defun custom-group-action (widget &optional event
)
3528 "Show the menu for `custom-group' WIDGET.
3529 Optional EVENT is the location for the menu."
3530 (if (eq (widget-get widget
:custom-state
) 'hidden
)
3531 (custom-toggle-hide widget
)
3532 (let* ((completion-ignore-case t
)
3533 (answer (widget-choose (concat "Operation on "
3534 (custom-unlispify-tag-name
3535 (widget-get widget
:value
)))
3536 (custom-menu-filter custom-group-menu
3540 (funcall answer widget
)))))
3542 (defun custom-group-set (widget)
3543 "Set changes in all modified group members."
3544 (let ((children (widget-get widget
:children
)))
3545 (mapc (lambda (child)
3546 (when (eq (widget-get child
:custom-state
) 'modified
)
3547 (widget-apply child
:custom-set
)))
3550 (defun custom-group-save (widget)
3551 "Save all modified group members."
3552 (let ((children (widget-get widget
:children
)))
3553 (mapc (lambda (child)
3554 (when (memq (widget-get child
:custom-state
) '(modified set
))
3555 (widget-apply child
:custom-save
)))
3558 (defun custom-group-reset-current (widget)
3559 "Reset all modified group members."
3560 (let ((children (widget-get widget
:children
)))
3561 (mapc (lambda (child)
3562 (when (eq (widget-get child
:custom-state
) 'modified
)
3563 (widget-apply child
:custom-reset-current
)))
3566 (defun custom-group-reset-saved (widget)
3567 "Reset all modified or set group members."
3568 (let ((children (widget-get widget
:children
)))
3569 (mapc (lambda (child)
3570 (when (memq (widget-get child
:custom-state
) '(modified set
))
3571 (widget-apply child
:custom-reset-saved
)))
3574 (defun custom-group-reset-standard (widget)
3575 "Reset all modified, set, or saved group members."
3576 (let ((children (widget-get widget
:children
)))
3577 (mapc (lambda (child)
3578 (when (memq (widget-get child
:custom-state
)
3579 '(modified set saved
))
3580 (widget-apply child
:custom-reset-standard
)))
3583 (defun custom-group-state-update (widget)
3585 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
3586 (let* ((children (widget-get widget
:children
))
3587 (states (mapcar (lambda (child)
3588 (widget-get child
:custom-state
))
3590 (magics custom-magic-alist
)
3593 (let ((magic (car (car magics
))))
3594 (if (and (not (eq magic
'hidden
))
3595 (memq magic states
))
3598 (setq magics
(cdr magics
)))))
3599 (widget-put widget
:custom-state found
)))
3600 (custom-magic-reset widget
))
3602 ;;; The `custom-save-all' Function.
3604 (defcustom custom-file nil
3605 "File used for storing customization information.
3606 The default is nil, which means to use your init file
3607 as specified by `user-init-file'. If you specify some other file,
3608 you need to explicitly load that file for the settings to take effect.
3610 When you change this variable, look in the previous custom file
3611 \(usually your init file) for the forms `(custom-set-variables ...)'
3612 and `(custom-set-faces ...)', and copy them (whichever ones you find)
3613 to the new custom file. This will preserve your existing customizations."
3614 :type
'(choice (const :tag
"Your Emacs init file" nil
) file
)
3617 (defun custom-file ()
3618 "Return the file name for saving customizations."
3621 (let ((user-init-file user-init-file
)
3623 (if (eq system-type
'ms-dos
) "~/_emacs" "~/.emacs")))
3624 (when (null user-init-file
)
3625 (if (or (file-exists-p default-init-file
)
3626 (and (eq system-type
'windows-nt
)
3627 (file-exists-p "~/_emacs")))
3628 ;; Started with -q, i.e. the file containing
3629 ;; Custom settings hasn't been read. Saving
3630 ;; settings there would overwrite other settings.
3631 (error "Saving settings from \"emacs -q\" would overwrite existing customizations"))
3632 (setq user-init-file default-init-file
))
3635 (defun custom-save-delete (symbol)
3636 "Visit `custom-file' and delete all calls to SYMBOL from it.
3637 Leave point at the old location of the first such call,
3638 or (if there were none) at the end of the buffer."
3639 (let ((default-major-mode 'emacs-lisp-mode
))
3640 (set-buffer (find-file-noselect (custom-file))))
3641 (goto-char (point-min))
3642 ;; Skip all whitespace and comments.
3643 (while (forward-comment 1))
3645 (save-excursion (forward-sexp (buffer-size)))) ; Test for scan errors.
3648 (while t
;; We exit this loop only via throw.
3649 ;; Skip all whitespace and comments.
3650 (while (forward-comment 1))
3651 (let ((start (point))
3652 (sexp (condition-case nil
3653 (read (current-buffer))
3654 (end-of-file (throw 'found nil
)))))
3655 (when (and (listp sexp
)
3656 (eq (car sexp
) symbol
))
3657 (delete-region start
(point))
3659 (setq first
(point)))))))
3662 ;; Move in front of local variables, otherwise long Custom
3663 ;; entries would make them ineffective.
3664 (let ((pos (point-max))
3665 (case-fold-search t
))
3667 (goto-char (point-max))
3668 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
3670 (when (search-forward "Local Variables:" nil t
)
3671 (setq pos
(line-beginning-position))))
3674 (defun custom-save-variables ()
3675 "Save all customized variables in `custom-file'."
3677 (custom-save-delete 'custom-load-themes
)
3678 (custom-save-delete 'custom-reset-variables
)
3679 (custom-save-delete 'custom-set-variables
)
3680 (custom-save-loaded-themes)
3681 (custom-save-resets 'theme-value
'custom-reset-variables nil
)
3682 (let ((standard-output (current-buffer))
3683 (saved-list (make-list 1 0))
3685 ;; First create a sorted list of saved variables.
3688 (if (get symbol
'saved-value
)
3689 (nconc saved-list
(list symbol
)))))
3690 (setq saved-list
(sort (cdr saved-list
) 'string
<))
3693 (princ "(custom-set-variables
3694 ;; custom-set-variables was added by Custom.
3695 ;; If you edit it by hand, you could mess it up, so be careful.
3696 ;; Your init file should contain only one such instance.
3697 ;; If there is more than one, they won't work right.\n")
3700 (let ((spec (car-safe (get symbol
'theme-value
)))
3701 (value (get symbol
'saved-value
))
3702 (requests (get symbol
'custom-requests
))
3703 (now (not (or (custom-variable-p symbol
)
3704 (and (not (boundp symbol
))
3705 (not (eq (get symbol
'force-value
)
3707 (comment (get symbol
'saved-variable-comment
))
3710 (eq (nth 0 spec
) 'user
)
3711 (eq (nth 1 spec
) 'set
))
3713 (and (null spec
) (get symbol
'saved-value
)))
3720 (cond ((or now requests comment
)
3725 (cond ((or requests comment
)
3744 (unless (looking-at "\n")
3747 (defun custom-save-faces ()
3748 "Save all customized faces in `custom-file'."
3750 (custom-save-delete 'custom-reset-faces
)
3751 (custom-save-delete 'custom-set-faces
)
3752 (custom-save-resets 'theme-face
'custom-reset-faces
'(default))
3753 (let ((standard-output (current-buffer))
3754 (saved-list (make-list 1 0))
3756 ;; First create a sorted list of saved faces.
3759 (if (get symbol
'saved-face
)
3760 (nconc saved-list
(list symbol
)))))
3761 (setq saved-list
(sort (cdr saved-list
) 'string
<))
3762 ;; The default face must be first, since it affects the others.
3763 (if (memq 'default saved-list
)
3764 (setq saved-list
(cons 'default
(delq 'default saved-list
))))
3767 (princ "(custom-set-faces
3768 ;; custom-set-faces was added by Custom.
3769 ;; If you edit it by hand, you could mess it up, so be careful.
3770 ;; Your init file should contain only one such instance.
3771 ;; If there is more than one, they won't work right.\n")
3774 (let ((theme-spec (car-safe (get symbol
'theme-face
)))
3775 (value (get symbol
'saved-face
))
3776 (now (not (or (get symbol
'face-defface-spec
)
3777 (and (not (custom-facep symbol
))
3778 (not (get symbol
'force-face
))))))
3779 (comment (get symbol
'saved-face-comment
)))
3780 (when (or (and theme-spec
3781 (eq (nth 0 theme-spec
) 'user
)
3782 (eq (nth 1 theme-spec
) 'set
))
3784 (and (null theme-spec
) (get symbol
'saved-face
)))
3785 ;; Don't print default face here.
3792 (cond ((or now comment
)
3809 (unless (looking-at "\n")
3812 (defun custom-save-resets (property setter special
)
3813 (let (started-writing ignored-special
)
3814 ;; (custom-save-delete setter) Done by caller
3815 (let ((standard-output (current-buffer))
3816 (mapper `(lambda (object)
3817 (let ((spec (car-safe (get object
(quote ,property
)))))
3818 (when (and (not (memq object ignored-special
))
3819 (eq (nth 0 spec
) 'user
)
3820 (eq (nth 1 spec
) 'reset
))
3821 ;; Do not write reset statements unless necessary.
3822 (unless started-writing
3823 (setq started-writing t
)
3827 (princ (quote ,setter
))
3831 (prin1 (nth 3 spec
))
3833 (mapc mapper special
)
3834 (setq ignored-special special
)
3836 (when started-writing
3839 (defun custom-save-loaded-themes ()
3840 (let ((themes (reverse (get 'user
'theme-loads-themes
)))
3841 (standard-output (current-buffer)))
3843 (unless (bolp) (princ "\n"))
3844 (princ "(custom-load-themes")
3845 (mapc (lambda (theme)
3847 (prin1 theme
)) themes
)
3851 (defun customize-save-customized ()
3852 "Save all user options which have been set in this session."
3854 (mapatoms (lambda (symbol)
3855 (let ((face (get symbol
'customized-face
))
3856 (value (get symbol
'customized-value
))
3857 (face-comment (get symbol
'customized-face-comment
))
3859 (get symbol
'customized-variable-comment
)))
3861 (put symbol
'saved-face face
)
3862 (custom-push-theme 'theme-face symbol
'user
'set value
)
3863 (put symbol
'customized-face nil
))
3865 (put symbol
'saved-value value
)
3866 (custom-push-theme 'theme-value symbol
'user
'set value
)
3867 (put symbol
'customized-value nil
))
3868 (when variable-comment
3869 (put symbol
'saved-variable-comment variable-comment
)
3870 (put symbol
'customized-variable-comment nil
))
3872 (put symbol
'saved-face-comment face-comment
)
3873 (put symbol
'customized-face-comment nil
)))))
3874 ;; We really should update all custom buffers here.
3878 (defun custom-save-all ()
3879 "Save all customizations in `custom-file'."
3880 (let ((inhibit-read-only t
))
3881 (custom-save-variables)
3884 (let ((default-major-mode nil
))
3885 (set-buffer (find-file-noselect (custom-file))))
3886 (let ((file-precious-flag t
))
3889 ;;; The Customize Menu.
3893 (defcustom custom-menu-nesting
2
3894 "Maximum nesting in custom menus."
3896 :group
'custom-menu
)
3898 (defun custom-face-menu-create (widget symbol
)
3899 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
3900 (vector (custom-unlispify-menu-entry symbol
)
3901 `(customize-face ',symbol
)
3904 (defun custom-variable-menu-create (widget symbol
)
3905 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
3906 (let ((type (get symbol
'custom-type
)))
3907 (unless (listp type
)
3908 (setq type
(list type
)))
3909 (if (and type
(widget-get type
:custom-menu
))
3910 (widget-apply type
:custom-menu symbol
)
3911 (vector (custom-unlispify-menu-entry symbol
)
3912 `(customize-variable ',symbol
)
3915 ;; Add checkboxes to boolean variable entries.
3916 (widget-put (get 'boolean
'widget-type
)
3917 :custom-menu
(lambda (widget symbol
)
3918 (vector (custom-unlispify-menu-entry symbol
)
3919 `(customize-variable ',symbol
)
3921 ':selected symbol
)))
3923 (defun custom-group-menu-create (widget symbol
)
3924 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
3925 `( ,(custom-unlispify-menu-entry symbol t
)
3926 :filter
(lambda (&rest junk
)
3927 (let ((menu (custom-menu-create ',symbol
)))
3928 (if (consp menu
) (cdr menu
) menu
)))))
3931 (defun custom-menu-create (symbol)
3932 "Create menu for customization group SYMBOL.
3933 The menu is in a format applicable to `easy-menu-define'."
3934 (let* ((item (vector (custom-unlispify-menu-entry symbol
)
3935 `(customize-group ',symbol
)
3937 (if (and (or (not (boundp 'custom-menu-nesting
))
3938 (>= custom-menu-nesting
0))
3940 (custom-load-symbol symbol
)
3941 (< (length (get symbol
'custom-group
)) widget-menu-max-size
)))
3942 (let ((custom-prefix-list (custom-prefix-add symbol
3943 custom-prefix-list
))
3944 (members (custom-sort-items (get symbol
'custom-group
)
3945 custom-menu-sort-alphabetically
3946 custom-menu-order-groups
)))
3947 `(,(custom-unlispify-menu-entry symbol t
)
3950 ,@(mapcar (lambda (entry)
3951 (widget-apply (if (listp (nth 1 entry
))
3953 (list (nth 1 entry
)))
3954 :custom-menu
(nth 0 entry
)))
3959 (defun customize-menu-create (symbol &optional name
)
3960 "Return a customize menu for customization group SYMBOL.
3961 If optional NAME is given, use that as the name of the menu.
3962 Otherwise the menu will be named `Customize'.
3963 The format is suitable for use with `easy-menu-define'."
3965 (setq name
"Customize"))
3967 :filter
(lambda (&rest junk
)
3968 (let ((menu (custom-menu-create ',symbol
)))
3969 (if (consp menu
) (cdr menu
) menu
)))))
3971 ;;; The Custom Mode.
3973 (defvar custom-mode-map nil
3974 "Keymap for `custom-mode'.")
3976 (unless custom-mode-map
3977 ;; This keymap should be dense, but a dense keymap would prevent inheriting
3978 ;; "\r" bindings from the parent map.
3979 (setq custom-mode-map
(make-sparse-keymap))
3980 (set-keymap-parent custom-mode-map widget-keymap
)
3981 (suppress-keymap custom-mode-map
)
3982 (define-key custom-mode-map
" " 'scroll-up
)
3983 (define-key custom-mode-map
"\177" 'scroll-down
)
3984 (define-key custom-mode-map
"q" 'Custom-buffer-done
)
3985 (define-key custom-mode-map
"u" 'Custom-goto-parent
)
3986 (define-key custom-mode-map
"n" 'widget-forward
)
3987 (define-key custom-mode-map
"p" 'widget-backward
)
3988 (define-key custom-mode-map
[mouse-1
] 'Custom-move-and-invoke
))
3990 (defun Custom-move-and-invoke (event)
3991 "Move to where you click, and if it is an active field, invoke it."
3993 (mouse-set-point event
)
3994 (if (widget-event-point event
)
3995 (let* ((pos (widget-event-point event
))
3996 (button (get-char-property pos
'button
)))
3998 (widget-button-click event
)))))
4000 (easy-menu-define Custom-mode-menu
4002 "Menu used in customization buffers."
4004 ,(customize-menu-create 'customize
)
4005 ["Set" Custom-set t
]
4006 ["Save" Custom-save t
]
4007 ["Reset to Current" Custom-reset-current t
]
4008 ["Reset to Saved" Custom-reset-saved t
]
4009 ["Reset to Standard Settings" Custom-reset-standard t
]
4010 ["Info" (Info-goto-node "(emacs)Easy Customization") t
]))
4012 (defun Custom-goto-parent ()
4013 "Go to the parent group listed at the top of this buffer.
4014 If several parents are listed, go to the first of them."
4017 (goto-char (point-min))
4018 (if (search-forward "\nGo to parent group: " nil t
)
4019 (let* ((button (get-char-property (point) 'button
))
4020 (parent (downcase (widget-get button
:tag
))))
4021 (customize-group parent
)))))
4023 (defcustom custom-mode-hook nil
4024 "Hook called when entering Custom mode."
4026 :group
'custom-buffer
)
4028 (defun custom-state-buffer-message (widget)
4029 (if (eq (widget-get (widget-get widget
:parent
) :custom-state
) 'modified
)
4030 (message "To install your edits, invoke [State] and choose the Set operation")))
4032 (defun custom-mode ()
4033 "Major mode for editing customization buffers.
4035 The following commands are available:
4037 Move to next button or editable field. \\[widget-forward]
4038 Move to previous button or editable field. \\[widget-backward]
4039 \\<widget-field-keymap>\
4040 Complete content of editable text field. \\[widget-complete]
4041 \\<custom-mode-map>\
4042 Invoke button under the mouse pointer. \\[Custom-move-and-invoke]
4043 Invoke button under point. \\[widget-button-press]
4044 Set all modifications. \\[Custom-set]
4045 Make all modifications default. \\[Custom-save]
4046 Reset all modified options. \\[Custom-reset-current]
4047 Reset all modified or set options. \\[Custom-reset-saved]
4048 Reset all options. \\[Custom-reset-standard]
4050 Entry to this mode calls the value of `custom-mode-hook'
4051 if that value is non-nil."
4052 (kill-all-local-variables)
4053 (setq major-mode
'custom-mode
4055 (use-local-map custom-mode-map
)
4056 (easy-menu-add Custom-mode-menu
)
4057 (make-local-variable 'custom-options
)
4058 (make-local-variable 'widget-documentation-face
)
4059 (setq widget-documentation-face
'custom-documentation-face
)
4060 (make-local-variable 'widget-button-face
)
4061 (setq widget-button-face
'custom-button-face
)
4062 (set (make-local-variable 'widget-button-pressed-face
)
4063 'custom-button-pressed-face
)
4064 (set (make-local-variable 'widget-mouse-face
)
4065 'custom-button-pressed-face
) ; buttons `depress' when moused
4066 ;; When possible, use relief for buttons, not bracketing. This test
4067 ;; may not be optimal.
4068 (when custom-raised-buttons
4069 (set (make-local-variable 'widget-push-button-prefix
) "")
4070 (set (make-local-variable 'widget-push-button-suffix
) "")
4071 (set (make-local-variable 'widget-link-prefix
) "")
4072 (set (make-local-variable 'widget-link-suffix
) ""))
4073 (add-hook 'widget-edit-functions
'custom-state-buffer-message nil t
)
4074 (run-hooks 'custom-mode-hook
))
4076 (put 'custom-mode
'mode-class
'special
)
4079 'debug-ignored-errors
4080 "^No user options have changed defaults in recent Emacs versions$")
4086 ;;; cus-edit.el ends here