1 ;;; cus-edit.el --- tools for customizing Emacs and Lisp packages
3 ;; Copyright (C) 1996,97,1999,2000,01,02,2003 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
) "...")))
443 (with-current-buffer (get-buffer-create " *Custom-Work*")
445 (princ symbol
(current-buffer))
446 (goto-char (point-min))
447 ;; FIXME: Boolean variables are not predicates, so they shouldn't
448 ;; end with `-p'. -stef
449 ;; (when (and (eq (get symbol 'custom-type) 'boolean)
450 ;; (re-search-forward "-p\\'" nil t))
451 ;; (replace-match "" t t)
452 ;; (goto-char (point-min)))
453 (if custom-unlispify-remove-prefixes
454 (let ((prefixes custom-prefix-list
)
457 (setq prefix
(car prefixes
))
458 (if (search-forward prefix
(+ (point) (length prefix
)) t
)
461 (delete-region (point-min) (point)))
462 (setq prefixes
(cdr prefixes
))))))
463 (subst-char-in-region (point-min) (point-max) ?- ?\ t
)
464 (capitalize-region (point-min) (point-max))
466 (goto-char (point-max))
470 (defcustom custom-unlispify-tag-names t
471 "Display tag names as words instead of symbols if non nil."
472 :group
'custom-buffer
475 (defun custom-unlispify-tag-name (symbol)
476 "Convert SYMBOL into a menu entry."
477 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names
))
478 (custom-unlispify-menu-entry symbol t
)))
480 (defun custom-prefix-add (symbol prefixes
)
481 "Add SYMBOL to list of ignored PREFIXES."
482 (cons (or (get symbol
'custom-prefix
)
483 (concat (symbol-name symbol
) "-"))
488 (defcustom custom-guess-name-alist
493 ("-function\\'" function
)
494 ("-functions\\'" (repeat function
))
495 ("-list\\'" (repeat sexp
))
496 ("-alist\\'" (repeat (cons sexp sexp
))))
497 "Alist of (MATCH TYPE).
499 MATCH should be a regexp matching the name of a symbol, and TYPE should
500 be a widget suitable for editing the value of that symbol. The TYPE
501 of the first entry where MATCH matches the name of the symbol will be
504 This is used for guessing the type of variables not declared with
506 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
509 (defcustom custom-guess-doc-alist
510 '(("\\`\\*?Non-nil " boolean
))
511 "Alist of (MATCH TYPE).
513 MATCH should be a regexp matching a documentation string, and TYPE
514 should be a widget suitable for editing the value of a variable with
515 that documentation string. The TYPE of the first entry where MATCH
516 matches the name of the symbol will be used.
518 This is used for guessing the type of variables not declared with
520 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
523 (defun custom-guess-type (symbol)
524 "Guess a widget suitable for editing the value of SYMBOL.
525 This is done by matching SYMBOL with `custom-guess-name-alist' and
526 if that fails, the doc string with `custom-guess-doc-alist'."
527 (let ((name (symbol-name symbol
))
528 (names custom-guess-name-alist
)
531 (setq current
(car names
)
533 (when (string-match (nth 0 current
) name
)
534 (setq found
(nth 1 current
)
537 (let ((doc (documentation-property symbol
'variable-documentation
))
538 (docs custom-guess-doc-alist
))
541 (setq current
(car docs
)
543 (when (string-match (nth 0 current
) doc
)
544 (setq found
(nth 1 current
)
550 (defcustom custom-browse-sort-alphabetically nil
551 "If non-nil, sort members of each customization group alphabetically."
553 :group
'custom-browse
)
555 (defcustom custom-browse-order-groups nil
556 "If non-nil, order group members within each customization group.
557 If `first', order groups before non-groups.
558 If `last', order groups after non-groups."
559 :type
'(choice (const first
)
561 (const :tag
"none" nil
))
562 :group
'custom-browse
)
564 (defcustom custom-browse-only-groups nil
565 "If non-nil, show group members only within each customization group."
567 :group
'custom-browse
)
569 (defcustom custom-buffer-sort-alphabetically nil
570 "If non-nil, sort members of each customization group alphabetically."
572 :group
'custom-buffer
)
574 (defcustom custom-buffer-order-groups
'last
575 "If non-nil, order group members within each customization group.
576 If `first', order groups before non-groups.
577 If `last', order groups after non-groups."
578 :type
'(choice (const first
)
580 (const :tag
"none" nil
))
581 :group
'custom-buffer
)
583 (defcustom custom-menu-sort-alphabetically nil
584 "If non-nil, sort members of each customization group alphabetically."
588 (defcustom custom-menu-order-groups
'first
589 "If non-nil, order group members within each customization group.
590 If `first', order groups before non-groups.
591 If `last', order groups after non-groups."
592 :type
'(choice (const first
)
594 (const :tag
"none" nil
))
597 ;;;###autoload (add-hook 'same-window-regexps "\\`\\*Customiz.*\\*\\'")
599 (defun custom-sort-items (items sort-alphabetically order-groups
)
600 "Return a sorted copy of ITEMS.
601 ITEMS should be a `custom-group' property.
602 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
603 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
604 groups after non-groups, if nil do not order groups at all."
605 (sort (copy-sequence items
)
607 (let ((typea (nth 1 a
)) (typeb (nth 1 b
))
608 (namea (nth 0 a
)) (nameb (nth 0 b
)))
609 (cond ((not order-groups
)
610 ;; Since we don't care about A and B order, maybe sort.
611 (when sort-alphabetically
612 (string-lessp namea nameb
)))
613 ((eq typea
'custom-group
)
614 ;; If B is also a group, maybe sort. Otherwise, order A and B.
615 (if (eq typeb
'custom-group
)
616 (when sort-alphabetically
617 (string-lessp namea nameb
))
618 (eq order-groups
'first
)))
619 ((eq typeb
'custom-group
)
620 ;; Since A cannot be a group, order A and B.
621 (eq order-groups
'last
))
623 ;; Since A and B cannot be groups, sort.
624 (string-lessp namea nameb
)))))))
626 ;;; Custom Mode Commands.
628 (defvar custom-options nil
629 "Customization widgets in the current buffer.")
632 "Set changes in all modified options."
634 (let ((children custom-options
))
635 (mapc (lambda (child)
636 (when (eq (widget-get child
:custom-state
) 'modified
)
637 (widget-apply child
:custom-set
)))
640 (defun Custom-save ()
641 "Set all modified group members and save them."
643 (let ((children custom-options
))
644 (mapc (lambda (child)
645 (when (memq (widget-get child
:custom-state
)
646 '(modified set changed rogue
))
647 (widget-apply child
:custom-save
)))
651 (defvar custom-reset-menu
652 '(("Current" . Custom-reset-current
)
653 ("Saved" . Custom-reset-saved
)
654 ("Erase Customization (use standard settings)" . Custom-reset-standard
))
655 "Alist of actions for the `Reset' button.
656 The key is a string containing the name of the action, the value is a
657 Lisp function taking the widget as an element which will be called
658 when the action is chosen.")
660 (defun custom-reset (event)
661 "Select item from reset menu."
662 (let* ((completion-ignore-case t
)
663 (answer (widget-choose "Reset to"
669 (defun Custom-reset-current (&rest ignore
)
670 "Reset all modified group members to their current value."
672 (let ((children custom-options
))
673 (mapc (lambda (widget)
674 (if (memq (widget-get widget
:custom-state
)
676 (widget-apply widget
:custom-reset-current
)))
679 (defun Custom-reset-saved (&rest ignore
)
680 "Reset all modified or set group members to their saved value."
682 (let ((children custom-options
))
683 (mapc (lambda (widget)
684 (if (memq (widget-get widget
:custom-state
)
685 '(modified set changed rogue
))
686 (widget-apply widget
:custom-reset-saved
)))
689 (defun Custom-reset-standard (&rest ignore
)
690 "Erase all customization (either current or saved) for the group members.
691 The immediate result is to restore them to their standard settings.
692 This operation eliminates any saved settings for the group members,
693 making them as if they had never been customized at all."
695 (let ((children custom-options
))
696 (mapc (lambda (widget)
697 (and (widget-apply widget
:custom-standard-value
)
698 (if (memq (widget-get widget
:custom-state
)
699 '(modified set changed saved rogue
))
700 (widget-apply widget
:custom-reset-standard
))))
703 ;;; The Customize Commands
705 (defun custom-prompt-variable (prompt-var prompt-val
&optional comment
)
706 "Prompt for a variable and a value and return them as a list.
707 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
708 prompt for the value. The %s escape in PROMPT-VAL is replaced with
709 the name of the variable.
711 If the variable has a `variable-interactive' property, that is used as if
712 it were the arg to `interactive' (which see) to interactively read the value.
714 If the variable has a `custom-type' property, it must be a widget and the
715 `:prompt-value' property of that widget will be used for reading the value.
717 If optional COMMENT argument is non nil, also prompt for a comment and return
718 it as the third element in the list."
719 (let* ((var (read-variable prompt-var
))
720 (minibuffer-help-form '(describe-variable var
))
722 (let ((prop (get var
'variable-interactive
))
723 (type (get var
'custom-type
))
724 (prompt (format prompt-val var
)))
726 (setq type
(list type
)))
728 ;; Use VAR's `variable-interactive' property
729 ;; as an interactive spec for prompting.
730 (call-interactively (list 'lambda
'(arg)
731 (list 'interactive prop
)
734 (widget-prompt-value type
740 (eval-minibuffer prompt
))))))
743 (read-string "Comment: " (get var
'variable-comment
)))
747 (defun customize-set-value (variable value
&optional comment
)
748 "Set VARIABLE to VALUE, and return VALUE. VALUE is a Lisp object.
750 If VARIABLE has a `variable-interactive' property, that is used as if
751 it were the arg to `interactive' (which see) to interactively read the value.
753 If VARIABLE has a `custom-type' property, it must be a widget and the
754 `:prompt-value' property of that widget will be used for reading the value.
756 If given a prefix (or a COMMENT argument), also prompt for a comment."
757 (interactive (custom-prompt-variable "Set variable: "
761 (cond ((string= comment
"")
762 (put variable
'variable-comment nil
))
764 (put variable
'variable-comment comment
)))
765 (set variable value
))
768 (defun customize-set-variable (variable value
&optional comment
)
769 "Set the default for VARIABLE to VALUE, and return VALUE.
770 VALUE is a Lisp object.
772 If VARIABLE has a `custom-set' property, that is used for setting
773 VARIABLE, otherwise `set-default' is used.
775 The `customized-value' property of the VARIABLE will be set to a list
776 with a quoted VALUE as its sole list member.
778 If VARIABLE has a `variable-interactive' property, that is used as if
779 it were the arg to `interactive' (which see) to interactively read the value.
781 If VARIABLE has a `custom-type' property, it must be a widget and the
782 `:prompt-value' property of that widget will be used for reading the value.
784 If given a prefix (or a COMMENT argument), also prompt for a comment."
785 (interactive (custom-prompt-variable "Set variable: "
786 "Set customized value for %s to: "
788 (custom-load-symbol variable
)
789 (funcall (or (get variable
'custom-set
) 'set-default
) variable value
)
790 (put variable
'customized-value
(list (custom-quote value
)))
791 (cond ((string= comment
"")
792 (put variable
'variable-comment nil
)
793 (put variable
'customized-variable-comment nil
))
795 (put variable
'variable-comment comment
)
796 (put variable
'customized-variable-comment comment
)))
800 (defun customize-save-variable (variable value
&optional comment
)
801 "Set the default for VARIABLE to VALUE, and save it for future sessions.
804 If VARIABLE has a `custom-set' property, that is used for setting
805 VARIABLE, otherwise `set-default' is used.
807 The `customized-value' property of the VARIABLE will be set to a list
808 with a quoted VALUE as its sole list member.
810 If VARIABLE has a `variable-interactive' property, that is used as if
811 it were the arg to `interactive' (which see) to interactively read the value.
813 If VARIABLE has a `custom-type' property, it must be a widget and the
814 `:prompt-value' property of that widget will be used for reading the value.
816 If given a prefix (or a COMMENT argument), also prompt for a comment."
817 (interactive (custom-prompt-variable "Set and save variable: "
818 "Set and save value for %s as: "
820 (funcall (or (get variable
'custom-set
) 'set-default
) variable value
)
821 (put variable
'saved-value
(list (custom-quote value
)))
822 (custom-push-theme 'theme-value variable
'user
'set
(list (custom-quote value
)))
823 (cond ((string= comment
"")
824 (put variable
'variable-comment nil
)
825 (put variable
'saved-variable-comment nil
))
827 (put variable
'variable-comment comment
)
828 (put variable
'saved-variable-comment comment
)))
834 "Select a customization buffer which you can use to set user options.
835 User options are structured into \"groups\".
836 Initially the top-level group `Emacs' and its immediate subgroups
837 are shown; the contents of those subgroups are initially hidden."
839 (customize-group 'emacs
))
842 (defun customize-mode (mode)
843 "Customize options related to the current major mode.
844 If a prefix \\[universal-argument] was given (or if the current major mode has no known group),
845 then prompt for the MODE to customize."
848 (let ((completion-regexp-list '("-mode\\'"))
849 (group (custom-group-of-mode major-mode
)))
850 (if (and group
(not current-prefix-arg
))
853 (completing-read (if group
854 (format "Major mode (default %s): " major-mode
)
857 'custom-group-of-mode
858 t nil nil
(if group
(symbol-name major-mode
))))))))
859 (customize-group (custom-group-of-mode mode
)))
863 (defun customize-group (group)
864 "Customize GROUP, which must be a customization group."
865 (interactive (list (let ((completion-ignore-case t
))
866 (completing-read "Customize group: (default emacs) "
869 (or (get symbol
'custom-loads
)
870 (get symbol
'custom-group
)))
872 (when (stringp group
)
873 (if (string-equal "" group
)
875 (setq group
(intern group
))))
876 (let ((name (format "*Customize Group: %s*"
877 (custom-unlispify-tag-name group
))))
878 (if (get-buffer name
)
880 (custom-buffer-create (list (list group
'custom-group
))
882 (concat " for group "
883 (custom-unlispify-tag-name group
))))))
886 (defun customize-group-other-window (group)
887 "Customize GROUP, which must be a customization group."
888 (interactive (list (let ((completion-ignore-case t
))
889 (completing-read "Customize group: (default emacs) "
892 (or (get symbol
'custom-loads
)
893 (get symbol
'custom-group
)))
895 (when (stringp group
)
896 (if (string-equal "" group
)
898 (setq group
(intern group
))))
899 (let ((name (format "*Customize Group: %s*"
900 (custom-unlispify-tag-name group
))))
901 (if (get-buffer name
)
902 (let ((window (selected-window))
903 ;; Copied from `custom-buffer-create-other-window'.
905 (special-display-buffer-names nil
)
906 (special-display-regexps nil
)
907 (same-window-buffer-names nil
)
908 (same-window-regexps nil
))
910 (select-window window
))
911 (custom-buffer-create-other-window
912 (list (list group
'custom-group
))
914 (concat " for group "
915 (custom-unlispify-tag-name group
))))))
918 (defalias 'customize-variable
'customize-option
)
921 (defun customize-option (symbol)
922 "Customize SYMBOL, which must be a user option variable."
923 (interactive (custom-variable-prompt))
924 (custom-buffer-create (list (list symbol
'custom-variable
))
925 (format "*Customize Option: %s*"
926 (custom-unlispify-tag-name symbol
))))
929 (defalias 'customize-variable-other-window
'customize-option-other-window
)
932 (defun customize-option-other-window (symbol)
933 "Customize SYMBOL, which must be a user option variable.
934 Show the buffer in another window, but don't select it."
935 (interactive (custom-variable-prompt))
936 (custom-buffer-create-other-window
937 (list (list symbol
'custom-variable
))
938 (format "*Customize Option: %s*" (custom-unlispify-tag-name symbol
))))
940 (defvar customize-changed-options-previous-release
"20.2"
941 "Version for `customize-changed-options' to refer back to by default.")
944 (defun customize-changed-options (since-version)
945 "Customize all user option variables changed in Emacs itself.
946 This includes new user option variables and faces, and new
947 customization groups, as well as older options and faces whose default
948 values have changed since the previous major Emacs release.
950 With argument SINCE-VERSION (a string), customize all user option
951 variables that were added (or their meanings were changed) since that
954 (interactive "sCustomize options changed, since version (default all versions): ")
955 (if (equal since-version
"")
956 (setq since-version nil
)
957 (unless (condition-case nil
958 (numberp (read since-version
))
960 (signal 'wrong-type-argument
(list 'numberp since-version
))))
961 (unless since-version
962 (setq since-version customize-changed-options-previous-release
))
964 ;; Load the information for versions since since-version. We use
965 ;; custom-load-symbol for this.
966 (put 'custom-versions-load-alist
'custom-loads nil
)
967 (dolist (elt custom-versions-load-alist
)
968 (if (customize-version-lessp since-version
(car elt
))
969 (dolist (load (cdr elt
))
970 (custom-add-load 'custom-versions-load-alist load
))))
971 (custom-load-symbol 'custom-versions-load-alist
)
972 (put 'custom-versions-load-alist
'custom-loads nil
)
977 (let ((version (get symbol
'custom-version
)))
979 (when (customize-version-lessp since-version version
)
980 (if (or (get symbol
'custom-group
)
981 (get symbol
'group-documentation
))
982 (push (list symbol
'custom-group
) found
))
983 (if (custom-variable-p symbol
)
984 (push (list symbol
'custom-variable
) found
))
985 (if (custom-facep symbol
)
986 (push (list symbol
'custom-face
) found
)))))))
988 (custom-buffer-create (custom-sort-items found t
'first
)
989 "*Customize Changed Options*")
990 (error "No user option defaults have been changed since Emacs %s"
993 (defun customize-version-lessp (version1 version2
)
994 ;; Why are the versions strings, and given that they are, why aren't
995 ;; they converted to numbers and compared as such here? -- fx
997 ;; In case someone made a mistake and left out the quotes
998 ;; in the :version value.
999 (if (numberp version2
)
1000 (setq version2
(prin1-to-string version2
)))
1001 (let (major1 major2 minor1 minor2
)
1002 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version1
)
1003 (setq major1
(read (or (match-string 1 version1
)
1005 (setq minor1
(read (or (match-string 3 version1
)
1007 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version2
)
1008 (setq major2
(read (or (match-string 1 version2
)
1010 (setq minor2
(read (or (match-string 3 version2
)
1012 (or (< major1 major2
)
1013 (and (= major1 major2
)
1014 (< minor1 minor2
)))))
1017 (defun customize-face (&optional face
)
1018 "Customize SYMBOL, which should be a face name or nil.
1019 If SYMBOL is nil, customize all faces.
1021 Interactively, when point is on text which has a face specified,
1022 suggest to customized that face, if it's customizable."
1024 (list (read-face-name "Customize face" "all faces" t
)))
1025 (if (member face
'(nil ""))
1026 (setq face
(face-list)))
1027 (if (and (listp face
) (null (cdr face
)))
1028 (setq face
(car face
)))
1030 (custom-buffer-create (custom-sort-items
1032 (list s
'custom-face
))
1035 "*Customize Faces*")
1036 (unless (facep face
)
1037 (error "Invalid face %S" face
))
1038 (custom-buffer-create (list (list face
'custom-face
))
1039 (format "*Customize Face: %s*"
1040 (custom-unlispify-tag-name face
)))))
1043 (defun customize-face-other-window (&optional face
)
1044 "Show customization buffer for face SYMBOL in other window.
1046 Interactively, when point is on text which has a face specified,
1047 suggest to customized that face, if it's customizable."
1049 (list (read-face-name "Customize face" "all faces" t
)))
1050 (if (member face
'(nil ""))
1051 (setq face
(face-list)))
1052 (if (and (listp face
) (null (cdr face
)))
1053 (setq face
(car face
)))
1055 (custom-buffer-create-other-window
1058 (list s
'custom-face
))
1061 "*Customize Faces*")
1062 (unless (facep face
)
1063 (error "Invalid face %S" face
))
1064 (custom-buffer-create-other-window
1065 (list (list face
'custom-face
))
1066 (format "*Customize Face: %s*"
1067 (custom-unlispify-tag-name face
)))))
1070 (defun customize-customized ()
1071 "Customize all user options set since the last save in this session."
1074 (mapatoms (lambda (symbol)
1075 (and (or (get symbol
'customized-face
)
1076 (get symbol
'customized-face-comment
))
1077 (custom-facep symbol
)
1078 (push (list symbol
'custom-face
) found
))
1079 (and (or (get symbol
'customized-value
)
1080 (get symbol
'customized-variable-comment
))
1082 (push (list symbol
'custom-variable
) found
))))
1084 (error "No customized user options")
1085 (custom-buffer-create (custom-sort-items found t nil
)
1086 "*Customize Customized*"))))
1089 (defun customize-rogue ()
1090 "Customize all user variable modified outside customize."
1093 (mapatoms (lambda (symbol)
1094 (let ((cval (or (get symbol
'customized-value
)
1095 (get symbol
'saved-value
)
1096 (get symbol
'standard-value
))))
1097 (when (and cval
;Declared with defcustom.
1098 (default-boundp symbol
) ;Has a value.
1099 (not (equal (eval (car cval
))
1100 ;; Which does not match customize.
1101 (default-value symbol
))))
1102 (push (list symbol
'custom-variable
) found
)))))
1104 (error "No rogue user options")
1105 (custom-buffer-create (custom-sort-items found t nil
)
1106 "*Customize Rogue*"))))
1108 (defun customize-saved ()
1109 "Customize all already saved user options."
1112 (mapatoms (lambda (symbol)
1113 (and (or (get symbol
'saved-face
)
1114 (get symbol
'saved-face-comment
))
1115 (custom-facep symbol
)
1116 (push (list symbol
'custom-face
) found
))
1117 (and (or (get symbol
'saved-value
)
1118 (get symbol
'saved-variable-comment
))
1120 (push (list symbol
'custom-variable
) found
))))
1122 (error "No saved user options")
1123 (custom-buffer-create (custom-sort-items found t nil
)
1124 "*Customize Saved*"))))
1127 (defun customize-apropos (regexp &optional all
)
1128 "Customize all user options matching REGEXP.
1129 If ALL is `options', include only options.
1130 If ALL is `faces', include only faces.
1131 If ALL is `groups', include only groups.
1132 If ALL is t (interactively, with prefix arg), include options which are not
1133 user-settable, as well as faces and groups."
1134 (interactive "sCustomize regexp: \nP")
1136 (mapatoms (lambda (symbol)
1137 (when (string-match regexp
(symbol-name symbol
))
1138 (when (and (not (memq all
'(faces options
)))
1139 (get symbol
'custom-group
))
1140 (push (list symbol
'custom-group
) found
))
1141 (when (and (not (memq all
'(options groups
)))
1142 (custom-facep symbol
))
1143 (push (list symbol
'custom-face
) found
))
1144 (when (and (not (memq all
'(groups faces
)))
1146 (or (get symbol
'saved-value
)
1147 (custom-variable-p symbol
)
1148 (if (memq all
'(nil options
))
1149 (user-variable-p symbol
)
1150 (get symbol
'variable-documentation
))))
1151 (push (list symbol
'custom-variable
) found
)))))
1153 (error "No matches")
1154 (custom-buffer-create (custom-sort-items found t
1155 custom-buffer-order-groups
)
1156 "*Customize Apropos*"))))
1159 (defun customize-apropos-options (regexp &optional arg
)
1160 "Customize all user options matching REGEXP.
1161 With prefix arg, include options which are not user-settable."
1162 (interactive "sCustomize regexp: \nP")
1163 (customize-apropos regexp
(or arg
'options
)))
1166 (defun customize-apropos-faces (regexp)
1167 "Customize all user faces matching REGEXP."
1168 (interactive "sCustomize regexp: \n")
1169 (customize-apropos regexp
'faces
))
1172 (defun customize-apropos-groups (regexp)
1173 "Customize all user groups matching REGEXP."
1174 (interactive "sCustomize regexp: \n")
1175 (customize-apropos regexp
'groups
))
1179 (defcustom custom-buffer-style
'links
1180 "Control the presentation style for customization buffers.
1181 The value should be a symbol, one of:
1183 brackets: groups nest within each other with big horizontal brackets.
1184 links: groups have links to subgroups."
1185 :type
'(radio (const brackets
)
1187 :group
'custom-buffer
)
1189 ;; If we pass BUFFER to `bury-buffer', the buffer isn't removed from
1191 (defun custom-bury-buffer (buffer)
1192 (with-current-buffer buffer
1195 (defcustom custom-buffer-done-function
'custom-bury-buffer
1196 "*Function called to remove a Custom buffer when the user is done with it.
1197 Called with one argument, the buffer to remove."
1198 :type
'(choice (function-item :tag
"Bury buffer" custom-bury-buffer
)
1199 (function-item :tag
"Kill buffer" kill-buffer
)
1200 (function :tag
"Other"))
1202 :group
'custom-buffer
)
1204 (defcustom custom-buffer-indent
3
1205 "Number of spaces to indent nested groups."
1207 :group
'custom-buffer
)
1209 (defun custom-get-fresh-buffer (name)
1210 "Get a fresh new buffer with name NAME.
1211 If the buffer already exist, clean it up to be like new.
1212 Beware: it's not quite like new. Good enough for custom, but maybe
1214 ;; To be more complete, we should also kill all permanent-local variables,
1215 ;; but it's not needed for custom.
1216 (let ((buf (get-buffer name
)))
1217 (when (and buf
(buffer-local-value 'buffer-file-name buf
))
1218 ;; This will check if the file is not saved.
1222 (get-buffer-create name
)
1223 (with-current-buffer buf
1224 (kill-all-local-variables)
1225 (run-hooks 'kill-buffer-hook
)
1226 ;; Delete overlays before erasing the buffer so the overlay hooks
1227 ;; don't get run spuriously when we erase the buffer.
1228 (let ((ols (overlay-lists)))
1229 (dolist (ol (nconc (car ols
) (cdr ols
)))
1230 (delete-overlay ol
)))
1235 (defun custom-buffer-create (options &optional name description
)
1236 "Create a buffer containing OPTIONS.
1237 Optional NAME is the name of the buffer.
1238 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1239 SYMBOL is a customization option, and WIDGET is a widget for editing
1241 (pop-to-buffer (custom-get-fresh-buffer (or name
"*Customization*")))
1242 (custom-buffer-create-internal options description
))
1245 (defun custom-buffer-create-other-window (options &optional name description
)
1246 "Create a buffer containing OPTIONS.
1247 Optional NAME is the name of the buffer.
1248 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1249 SYMBOL is a customization option, and WIDGET is a widget for editing
1251 (unless name
(setq name
"*Customization*"))
1252 (let ((window (selected-window))
1254 (special-display-buffer-names nil
)
1255 (special-display-regexps nil
)
1256 (same-window-buffer-names nil
)
1257 (same-window-regexps nil
))
1258 (pop-to-buffer (custom-get-fresh-buffer name
))
1259 (custom-buffer-create-internal options description
)
1260 (select-window window
)))
1262 (defcustom custom-reset-button-menu nil
1263 "If non-nil, only show a single reset button in customize buffers.
1264 This button will have a menu with all three reset operations."
1266 :group
'custom-buffer
)
1268 (defcustom custom-buffer-verbose-help t
1269 "If non-nil, include explanatory text in the customization buffer."
1271 :group
'custom-buffer
)
1273 (defun Custom-buffer-done (&rest ignore
)
1274 "Remove current buffer by calling `custom-buffer-done-function'."
1276 (funcall custom-buffer-done-function
(current-buffer)))
1278 (defcustom custom-raised-buttons
(not (equal (face-valid-attribute-values :box
)
1279 '(("unspecified" . unspecified
))))
1280 "If non-nil, indicate active buttons in a `raised-button' style.
1281 Otherwise use brackets."
1284 :group
'custom-buffer
)
1286 (defun custom-buffer-create-internal (options &optional description
)
1287 (message "Creating customization buffer...")
1289 (if custom-buffer-verbose-help
1291 (widget-insert "This is a customization buffer")
1293 (widget-insert description
))
1294 (widget-insert (format ".
1295 %s show active fields; type RET or click mouse-1
1296 on an active field to invoke its action. Editing an option value
1297 changes the text in the buffer; invoke the State button and
1298 choose the Set operation to set the option value.
1299 Invoke " (if custom-raised-buttons
1301 "Square brackets")))
1302 (widget-create 'info-link
1304 :help-echo
"Read the online help."
1305 "(emacs)Easy Customization")
1306 (widget-insert " for more information.\n\n")
1307 (message "Creating customization buttons...")
1308 (widget-insert "Operate on everything in this buffer:\n "))
1309 (widget-insert " "))
1310 (widget-create 'push-button
1311 :tag
"Set for Current Session"
1313 Make your editing in this buffer take effect for this session."
1314 :action
(lambda (widget &optional event
)
1317 (widget-create 'push-button
1318 :tag
"Save for Future Sessions"
1320 Make your editing in this buffer take effect for future Emacs sessions."
1321 :action
(lambda (widget &optional event
)
1323 (if custom-reset-button-menu
1326 (widget-create 'push-button
1328 :help-echo
"Show a menu with reset operations."
1329 :mouse-down-action
(lambda (&rest junk
) t
)
1330 :action
(lambda (widget &optional event
)
1331 (custom-reset event
))))
1332 (widget-insert "\n ")
1333 (widget-create 'push-button
1336 Reset all edited text in this buffer to reflect current values."
1337 :action
'Custom-reset-current
)
1339 (widget-create 'push-button
1340 :tag
"Reset to Saved"
1342 Reset all values in this buffer to their saved settings."
1343 :action
'Custom-reset-saved
)
1345 (widget-create 'push-button
1346 :tag
"Erase Customization"
1348 Un-customize all values in this buffer. They get their standard settings."
1349 :action
'Custom-reset-standard
))
1350 (if (not custom-buffer-verbose-help
)
1353 (widget-create 'info-link
1355 :help-echo
"Read the online help."
1356 "(emacs)Easy Customization")))
1358 (widget-create 'push-button
1361 (lambda (&rest ignore
)
1363 ((eq custom-buffer-done-function
1364 'custom-bury-buffer
)
1366 ((eq custom-buffer-done-function
'kill-buffer
)
1368 (t "Finish with this buffer")))
1369 :action
#'Custom-buffer-done
)
1370 (widget-insert "\n\n")
1371 (message "Creating customization items...")
1372 (buffer-disable-undo)
1373 (setq custom-options
1374 (if (= (length options
) 1)
1375 (mapcar (lambda (entry)
1376 (widget-create (nth 1 entry
)
1377 :documentation-shown t
1378 :custom-state
'unknown
1379 :tag
(custom-unlispify-tag-name
1381 :value
(nth 0 entry
)))
1384 (length (length options
)))
1385 (mapcar (lambda (entry)
1387 (message "Creating customization items ...%2d%%"
1388 (/ (* 100.0 count
) length
))
1389 (widget-create (nth 1 entry
)
1390 :tag
(custom-unlispify-tag-name
1392 :value
(nth 0 entry
))
1393 (setq count
(1+ count
))
1394 (unless (eq (preceding-char) ?
\n)
1395 (widget-insert "\n"))
1396 (widget-insert "\n")))
1398 (unless (eq (preceding-char) ?
\n)
1399 (widget-insert "\n"))
1400 (message "Creating customization items ...done")
1401 (unless (eq custom-buffer-style
'tree
)
1402 (mapc 'custom-magic-reset custom-options
))
1403 (message "Creating customization setup...")
1405 (buffer-enable-undo)
1406 (goto-char (point-min))
1407 (message "Creating customization buffer...done"))
1409 ;;; The Tree Browser.
1412 (defun customize-browse (&optional group
)
1413 "Create a tree browser for the customize hierarchy."
1416 (setq group
'emacs
))
1417 (let ((name "*Customize Browser*"))
1418 (pop-to-buffer (custom-get-fresh-buffer name
)))
1421 Square brackets show active fields; type RET or click mouse-1
1422 on an active field to invoke its action.
1423 Invoke [+] below to expand a group, and [-] to collapse an expanded group.\n")
1424 (if custom-browse-only-groups
1426 Invoke the [Group] button below to edit that item in another window.\n\n")
1427 (widget-insert "Invoke the ")
1428 (widget-create 'item
1431 :tag-glyph
"folder")
1432 (widget-insert ", ")
1433 (widget-create 'item
1437 (widget-insert ", and ")
1438 (widget-create 'item
1441 :tag-glyph
"option")
1442 (widget-insert " buttons below to edit that
1443 item in another window.\n\n"))
1444 (let ((custom-buffer-style 'tree
))
1445 (widget-create 'custom-group
1447 :custom-state
'unknown
1448 :tag
(custom-unlispify-tag-name group
)
1451 (goto-char (point-min)))
1453 (define-widget 'custom-browse-visibility
'item
1454 "Control visibility of items in the customize tree browser."
1456 :action
'custom-browse-visibility-action
)
1458 (defun custom-browse-visibility-action (widget &rest ignore
)
1459 (let ((custom-buffer-style 'tree
))
1460 (custom-toggle-parent widget
)))
1462 (define-widget 'custom-browse-group-tag
'push-button
1463 "Show parent in other window when activated."
1466 :action
'custom-browse-group-tag-action
)
1468 (defun custom-browse-group-tag-action (widget &rest ignore
)
1469 (let ((parent (widget-get widget
:parent
)))
1470 (customize-group-other-window (widget-value parent
))))
1472 (define-widget 'custom-browse-variable-tag
'push-button
1473 "Show parent in other window when activated."
1476 :action
'custom-browse-variable-tag-action
)
1478 (defun custom-browse-variable-tag-action (widget &rest ignore
)
1479 (let ((parent (widget-get widget
:parent
)))
1480 (customize-variable-other-window (widget-value parent
))))
1482 (define-widget 'custom-browse-face-tag
'push-button
1483 "Show parent in other window when activated."
1486 :action
'custom-browse-face-tag-action
)
1488 (defun custom-browse-face-tag-action (widget &rest ignore
)
1489 (let ((parent (widget-get widget
:parent
)))
1490 (customize-face-other-window (widget-value parent
))))
1492 (defconst custom-browse-alist
'((" " "space")
1498 (defun custom-browse-insert-prefix (prefix)
1499 "Insert PREFIX. On XEmacs convert it to line graphics."
1500 ;; Fixme: do graphics.
1501 (if nil
; (string-match "XEmacs" emacs-version)
1504 (while (not (string-equal prefix
""))
1505 (let ((entry (substring prefix
0 3)))
1506 (setq prefix
(substring prefix
3))
1507 (let ((overlay (make-overlay (1- (point)) (point) nil t nil
))
1508 (name (nth 1 (assoc entry custom-browse-alist
))))
1509 (overlay-put overlay
'end-glyph
(widget-glyph-find name entry
))
1510 (overlay-put overlay
'start-open t
)
1511 (overlay-put overlay
'end-open t
)))))
1514 ;;; Modification of Basic Widgets.
1516 ;; We add extra properties to the basic widgets needed here. This is
1517 ;; fine, as long as we are careful to stay within out own namespace.
1519 ;; We want simple widgets to be displayed by default, but complex
1520 ;; widgets to be hidden.
1522 (widget-put (get 'item
'widget-type
) :custom-show t
)
1523 (widget-put (get 'editable-field
'widget-type
)
1524 :custom-show
(lambda (widget value
)
1525 (let ((pp (pp-to-string value
)))
1526 (cond ((string-match "\n" pp
)
1531 (widget-put (get 'menu-choice
'widget-type
) :custom-show t
)
1533 ;;; The `custom-manual' Widget.
1535 (define-widget 'custom-manual
'info-link
1536 "Link to the manual entry for this customization option."
1537 :help-echo
"Read the manual entry for this option."
1540 ;;; The `custom-magic' Widget.
1542 (defgroup custom-magic-faces nil
1543 "Faces used by the magic button."
1544 :group
'custom-faces
1545 :group
'custom-buffer
)
1547 (defface custom-invalid-face
'((((class color
))
1548 (:foreground
"yellow" :background
"red"))
1550 (:weight bold
:slant italic
:underline t
)))
1551 "Face used when the customize item is invalid."
1552 :group
'custom-magic-faces
)
1554 (defface custom-rogue-face
'((((class color
))
1555 (:foreground
"pink" :background
"black"))
1558 "Face used when the customize item is not defined for customization."
1559 :group
'custom-magic-faces
)
1561 (defface custom-modified-face
'((((class color
))
1562 (:foreground
"white" :background
"blue"))
1564 (:slant italic
:bold
)))
1565 "Face used when the customize item has been modified."
1566 :group
'custom-magic-faces
)
1568 (defface custom-set-face
'((((class color
))
1569 (:foreground
"blue" :background
"white"))
1572 "Face used when the customize item has been set."
1573 :group
'custom-magic-faces
)
1575 (defface custom-changed-face
'((((class color
))
1576 (:foreground
"white" :background
"blue"))
1579 "Face used when the customize item has been changed."
1580 :group
'custom-magic-faces
)
1582 (defface custom-saved-face
'((t (:underline t
)))
1583 "Face used when the customize item has been saved."
1584 :group
'custom-magic-faces
)
1586 (defconst custom-magic-alist
'((nil "#" underline
"\
1587 uninitialized, you should not see this.")
1588 (unknown "?" italic
"\
1589 unknown, you should not see this.")
1590 (hidden "-" default
"\
1591 hidden, invoke \"Show\" in the previous line to show." "\
1592 group now hidden, invoke \"Show\", above, to show contents.")
1593 (invalid "x" custom-invalid-face
"\
1594 the value displayed for this %c is invalid and cannot be set.")
1595 (modified "*" custom-modified-face
"\
1596 you have edited the value as text, but you have not set the %c." "\
1597 you have edited something in this group, but not set it.")
1598 (set "+" custom-set-face
"\
1599 you have set this %c, but not saved it for future sessions." "\
1600 something in this group has been set, but not saved.")
1601 (changed ":" custom-changed-face
"\
1602 this %c has been changed outside the customize buffer." "\
1603 something in this group has been changed outside customize.")
1604 (saved "!" custom-saved-face
"\
1605 this %c has been set and saved." "\
1606 something in this group has been set and saved.")
1607 (rogue "@" custom-rogue-face
"\
1608 this %c has not been changed with customize." "\
1609 something in this group is not prepared for customization.")
1610 (standard " " nil
"\
1611 this %c is unchanged from its standard setting." "\
1612 visible group members are all at standard settings."))
1613 "Alist of customize option states.
1614 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1616 STATE is one of the following symbols:
1619 For internal use, should never occur.
1621 For internal use, should never occur.
1623 This item is not being displayed.
1625 This item is modified, but has an invalid form.
1627 This item is modified, and has a valid form.
1629 This item has been set but not saved.
1631 The current value of this item has been changed temporarily.
1633 This item is marked for saving.
1635 This item has no customization information.
1637 This item is unchanged from the standard setting.
1639 MAGIC is a string used to present that state.
1641 FACE is a face used to present the state.
1643 ITEM-DESC is a string describing the state for options.
1645 GROUP-DESC is a string describing the state for groups. If this is
1646 left out, ITEM-DESC will be used.
1648 The string %c in either description will be replaced with the
1649 category of the item. These are `group'. `option', and `face'.
1651 The list should be sorted most significant first.")
1653 (defcustom custom-magic-show
'long
1654 "If non-nil, show textual description of the state.
1655 If `long', show a full-line description, not just one word."
1656 :type
'(choice (const :tag
"no" nil
)
1658 (other :tag
"short" short
))
1659 :group
'custom-buffer
)
1661 (defcustom custom-magic-show-hidden
'(option face
)
1662 "Control whether the State button is shown for hidden items.
1663 The value should be a list with the custom categories where the State
1664 button should be visible. Possible categories are `group', `option',
1666 :type
'(set (const group
) (const option
) (const face
))
1667 :group
'custom-buffer
)
1669 (defcustom custom-magic-show-button nil
1670 "Show a \"magic\" button indicating the state of each customization option."
1672 :group
'custom-buffer
)
1674 (define-widget 'custom-magic
'default
1675 "Show and manipulate state for a customization option."
1677 :action
'widget-parent-action
1680 :value-create
'custom-magic-value-create
1681 :value-delete
'widget-children-value-delete
)
1683 (defun widget-magic-mouse-down-action (widget &optional event
)
1684 ;; Non-nil unless hidden.
1685 (not (eq (widget-get (widget-get (widget-get widget
:parent
) :parent
)
1689 (defun custom-magic-value-create (widget)
1690 "Create compact status report for WIDGET."
1691 (let* ((parent (widget-get widget
:parent
))
1692 (state (widget-get parent
:custom-state
))
1693 (hidden (eq state
'hidden
))
1694 (entry (assq state custom-magic-alist
))
1695 (magic (nth 1 entry
))
1696 (face (nth 2 entry
))
1697 (category (widget-get parent
:custom-category
))
1698 (text (or (and (eq category
'group
)
1701 (form (widget-get parent
:custom-form
))
1703 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text
)
1704 (setq text
(concat (match-string 1 text
)
1705 (symbol-name category
)
1706 (match-string 2 text
))))
1707 (when (and custom-magic-show
1709 (memq category custom-magic-show-hidden
)))
1711 (when (and (eq category
'group
)
1712 (not (and (eq custom-buffer-style
'links
)
1713 (> (widget-get parent
:custom-level
) 1))))
1714 (insert-char ?\
(* custom-buffer-indent
1715 (widget-get parent
:custom-level
))))
1716 (push (widget-create-child-and-convert
1718 :help-echo
"Change the state of this item."
1719 :format
(if hidden
"%t" "%[%t%]")
1720 :button-prefix
'widget-push-button-prefix
1721 :button-suffix
'widget-push-button-suffix
1722 :mouse-down-action
'widget-magic-mouse-down-action
1726 (let ((start (point)))
1727 (if (eq custom-magic-show
'long
)
1729 (insert (symbol-name state
)))
1730 (cond ((eq form
'lisp
)
1732 ((eq form
'mismatch
)
1733 (insert " (mismatch)")))
1734 (put-text-property start
(point) 'face
'custom-state-face
))
1736 (when (and (eq category
'group
)
1737 (not (and (eq custom-buffer-style
'links
)
1738 (> (widget-get parent
:custom-level
) 1))))
1739 (insert-char ?\
(* custom-buffer-indent
1740 (widget-get parent
:custom-level
))))
1741 (when custom-magic-show-button
1742 (when custom-magic-show
1743 (let ((indent (widget-get parent
:indent
)))
1745 (insert-char ? indent
))))
1746 (push (widget-create-child-and-convert
1748 :mouse-down-action
'widget-magic-mouse-down-action
1752 :help-echo
"Change the state."
1753 :format
(if hidden
"%t" "%[%t%]")
1754 :tag
(if (memq form
'(lisp mismatch
))
1755 (concat "(" magic
")")
1756 (concat "[" magic
"]")))
1759 (widget-put widget
:children children
)))
1761 (defun custom-magic-reset (widget)
1762 "Redraw the :custom-magic property of WIDGET."
1763 (let ((magic (widget-get widget
:custom-magic
)))
1764 (widget-value-set magic
(widget-value magic
))))
1766 ;;; The `custom' Widget.
1768 (defface custom-button-face
1769 '((((type x w32 mac
) (class color
)) ; Like default modeline
1770 (:box
(:line-width
2 :style released-button
)
1771 :background
"lightgrey" :foreground
"black"))
1774 "Face used for buttons in customization buffers."
1776 :group
'custom-faces
)
1778 (defface custom-button-pressed-face
1779 '((((type x w32 mac
) (class color
))
1780 (:box
(:line-width
2 :style pressed-button
)
1781 :background
"lightgrey" :foreground
"black"))
1783 (:inverse-video t
)))
1784 "Face used for buttons in customization buffers."
1786 :group
'custom-faces
)
1788 (defface custom-documentation-face nil
1789 "Face used for documentation strings in customization buffers."
1790 :group
'custom-faces
)
1792 (defface custom-state-face
'((((class color
)
1794 (:foreground
"lime green"))
1797 (:foreground
"dark green"))
1799 "Face used for State descriptions in the customize buffer."
1800 :group
'custom-faces
)
1802 (define-widget 'custom
'default
1803 "Customize a user option."
1805 :convert-widget
'custom-convert-widget
1806 :notify
'custom-notify
1809 :custom-state
'hidden
1810 :documentation-property
'widget-subclass-responsibility
1811 :value-create
'widget-subclass-responsibility
1812 :value-delete
'widget-children-value-delete
1813 :value-get
'widget-value-value-get
1814 :validate
'widget-children-validate
1815 :match
(lambda (widget value
) (symbolp value
)))
1817 (defun custom-convert-widget (widget)
1818 "Initialize :value and :tag from :args in WIDGET."
1819 (let ((args (widget-get widget
:args
)))
1821 (widget-put widget
:value
(widget-apply widget
1822 :value-to-internal
(car args
)))
1823 (widget-put widget
:tag
(custom-unlispify-tag-name (car args
)))
1824 (widget-put widget
:args nil
)))
1827 (defun custom-notify (widget &rest args
)
1828 "Keep track of changes."
1829 (let ((state (widget-get widget
:custom-state
)))
1830 (unless (eq state
'modified
)
1831 (unless (memq state
'(nil unknown hidden
))
1832 (widget-put widget
:custom-state
'modified
))
1833 (custom-magic-reset widget
)
1834 (apply 'widget-default-notify widget args
))))
1836 (defun custom-redraw (widget)
1837 "Redraw WIDGET with current settings."
1838 (let ((line (count-lines (point-min) (point)))
1839 (column (current-column))
1841 (from (marker-position (widget-get widget
:from
)))
1842 (to (marker-position (widget-get widget
:to
))))
1844 (widget-value-set widget
(widget-value widget
))
1845 (custom-redraw-magic widget
))
1846 (when (and (>= pos from
) (<= pos to
))
1851 (goto-line (1+ line
)))
1852 (move-to-column column
))
1855 (defun custom-redraw-magic (widget)
1856 "Redraw WIDGET state with current settings."
1858 (let ((magic (widget-get widget
:custom-magic
)))
1860 (widget-value-set magic
(widget-value magic
))
1861 (when (setq widget
(widget-get widget
:group
))
1862 (custom-group-state-update widget
)))
1864 (setq widget nil
)))))
1867 (defun custom-show (widget value
)
1868 "Non-nil if WIDGET should be shown with VALUE by default."
1869 (let ((show (widget-get widget
:custom-show
)))
1875 (funcall show widget value
)))))
1877 (defun custom-load-widget (widget)
1878 "Load all dependencies for WIDGET."
1879 (custom-load-symbol (widget-value widget
)))
1881 (defun custom-unloaded-symbol-p (symbol)
1882 "Return non-nil if the dependencies of SYMBOL has not yet been loaded."
1884 (loads (get symbol
'custom-loads
))
1887 (setq load
(car loads
)
1889 (cond ((symbolp load
)
1890 (unless (featurep load
)
1892 ((assoc load load-history
))
1893 ((assoc (locate-library load
) load-history
)
1899 (defun custom-unloaded-widget-p (widget)
1900 "Return non-nil if the dependencies of WIDGET has not yet been loaded."
1901 (custom-unloaded-symbol-p (widget-value widget
)))
1903 (defun custom-toggle-hide (widget)
1904 "Toggle visibility of WIDGET."
1905 (custom-load-widget widget
)
1906 (let ((state (widget-get widget
:custom-state
)))
1907 (cond ((memq state
'(invalid modified
))
1908 (error "There are unset changes"))
1910 (widget-put widget
:custom-state
'unknown
))
1912 (widget-put widget
:documentation-shown nil
)
1913 (widget-put widget
:custom-state
'hidden
)))
1914 (custom-redraw widget
)
1917 (defun custom-toggle-parent (widget &rest ignore
)
1918 "Toggle visibility of parent of WIDGET."
1919 (custom-toggle-hide (widget-get widget
:parent
)))
1921 (defun custom-add-see-also (widget &optional prefix
)
1922 "Add `See also ...' to WIDGET if there are any links.
1923 Insert PREFIX first if non-nil."
1924 (let* ((symbol (widget-get widget
:value
))
1925 (links (get symbol
'custom-links
))
1926 (many (> (length links
) 2))
1927 (buttons (widget-get widget
:buttons
))
1928 (indent (widget-get widget
:indent
)))
1931 (insert-char ?\ indent
))
1934 (insert "See also ")
1936 (push (widget-create-child-and-convert widget
(car links
))
1938 (setq links
(cdr links
))
1947 (widget-put widget
:buttons buttons
))))
1949 (defun custom-add-parent-links (widget &optional initial-string
)
1950 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
1951 The value if non-nil if any parents were found.
1952 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
1953 (let ((name (widget-value widget
))
1954 (type (widget-type widget
))
1955 (buttons (widget-get widget
:buttons
))
1958 (insert (or initial-string
"Parent groups:"))
1959 (mapatoms (lambda (symbol)
1960 (let ((entry (assq name
(get symbol
'custom-group
))))
1961 (when (eq (nth 1 entry
) type
)
1963 (push (widget-create-child-and-convert
1964 widget
'custom-group-link
1965 :tag
(custom-unlispify-tag-name symbol
)
1969 (widget-put widget
:buttons buttons
)
1972 (delete-region start
(point)))
1975 ;;; The `custom-comment' Widget.
1977 ;; like the editable field
1978 (defface custom-comment-face
'((((class grayscale color
)
1980 (:background
"gray85"))
1981 (((class grayscale color
)
1983 (:background
"dim gray"))
1986 "Face used for comments on variables or faces"
1988 :group
'custom-faces
)
1990 ;; like font-lock-comment-face
1991 (defface custom-comment-tag-face
1992 '((((class color
) (background dark
)) (:foreground
"gray80"))
1993 (((class color
) (background light
)) (:foreground
"blue4"))
1994 (((class grayscale
) (background light
))
1995 (:foreground
"DimGray" :weight bold
:slant italic
))
1996 (((class grayscale
) (background dark
))
1997 (:foreground
"LightGray" :weight bold
:slant italic
))
1999 "Face used for variables or faces comment tags"
2000 :group
'custom-faces
)
2002 (define-widget 'custom-comment
'string
2005 :help-echo
"Edit a comment here."
2006 :sample-face
'custom-comment-tag-face
2007 :value-face
'custom-comment-face
2009 :create
'custom-comment-create
)
2011 (defun custom-comment-create (widget)
2012 (let* ((null-comment (equal "" (widget-value widget
))))
2013 (if (or (widget-get (widget-get widget
:parent
) :comment-shown
)
2015 (widget-default-create widget
)
2016 ;; `widget-default-delete' expects markers in these slots --
2017 ;; maybe it shouldn't.
2018 (widget-put widget
:from
(point-marker))
2019 (widget-put widget
:to
(point-marker)))))
2021 (defun custom-comment-hide (widget)
2022 (widget-put (widget-get widget
:parent
) :comment-shown nil
))
2024 ;; Those functions are for the menu. WIDGET is NOT the comment widget. It's
2025 ;; the global custom one
2026 (defun custom-comment-show (widget)
2027 (widget-put widget
:comment-shown t
)
2028 (custom-redraw widget
)
2031 (defun custom-comment-invisible-p (widget)
2032 (let ((val (widget-value (widget-get widget
:comment-widget
))))
2034 (not (widget-get widget
:comment-shown
)))))
2036 ;;; The `custom-variable' Widget.
2038 ;; When this was underlined blue, users confused it with a
2039 ;; Mosaic-style hyperlink...
2040 (defface custom-variable-tag-face
2043 (:foreground
"light blue" :weight bold
:height
1.2 :inherit variable-pitch
))
2046 (:foreground
"blue" :weight bold
:height
1.2 :inherit variable-pitch
))
2048 "Face used for unpushable variable tags."
2049 :group
'custom-faces
)
2051 (defface custom-variable-button-face
'((t (:underline t
:weight bold
)))
2052 "Face used for pushable variable tags."
2053 :group
'custom-faces
)
2055 (defcustom custom-variable-default-form
'edit
2056 "Default form of displaying variable values."
2057 :type
'(choice (const edit
)
2059 :group
'custom-buffer
2062 (define-widget 'custom-variable
'custom
2063 "Customize variable."
2065 :help-echo
"Set or reset this variable."
2066 :documentation-property
'variable-documentation
2067 :custom-category
'option
2069 :custom-menu
'custom-variable-menu-create
2070 :custom-form nil
; defaults to value of `custom-variable-default-form'
2071 :value-create
'custom-variable-value-create
2072 :action
'custom-variable-action
2073 :custom-set
'custom-variable-set
2074 :custom-save
'custom-variable-save
2075 :custom-reset-current
'custom-redraw
2076 :custom-reset-saved
'custom-variable-reset-saved
2077 :custom-reset-standard
'custom-variable-reset-standard
2078 :custom-standard-value
'custom-variable-standard-value
)
2080 (defun custom-variable-type (symbol)
2081 "Return a widget suitable for editing the value of SYMBOL.
2082 If SYMBOL has a `custom-type' property, use that.
2083 Otherwise, look up symbol in `custom-guess-type-alist'."
2084 (let* ((type (or (get symbol
'custom-type
)
2085 (and (not (get symbol
'standard-value
))
2086 (custom-guess-type symbol
))
2088 (options (get symbol
'custom-options
))
2089 (tmp (if (listp type
)
2090 (copy-sequence type
)
2093 (widget-put tmp
:options options
))
2096 (defun custom-variable-value-create (widget)
2097 "Here is where you edit the variable's value."
2098 (custom-load-widget widget
)
2099 (unless (widget-get widget
:custom-form
)
2100 (widget-put widget
:custom-form custom-variable-default-form
))
2101 (let* ((buttons (widget-get widget
:buttons
))
2102 (children (widget-get widget
:children
))
2103 (form (widget-get widget
:custom-form
))
2104 (state (widget-get widget
:custom-state
))
2105 (symbol (widget-get widget
:value
))
2106 (tag (widget-get widget
:tag
))
2107 (type (custom-variable-type symbol
))
2108 (conv (widget-convert type
))
2109 (get (or (get symbol
'custom-get
) 'default-value
))
2110 (prefix (widget-get widget
:custom-prefix
))
2111 (last (widget-get widget
:custom-last
))
2112 (value (if (default-boundp symbol
)
2113 (funcall get symbol
)
2114 (widget-get conv
:value
))))
2115 ;; If the widget is new, the child determines whether it is hidden.
2117 ((custom-show type value
)
2118 (setq state
'unknown
))
2120 (setq state
'hidden
)))
2121 ;; If we don't know the state, see if we need to edit it in lisp form.
2122 (when (eq state
'unknown
)
2123 (unless (widget-apply conv
:match value
)
2124 ;; (widget-apply (widget-convert type) :match value)
2125 (setq form
'mismatch
)))
2126 ;; Now we can create the child widget.
2127 (cond ((eq custom-buffer-style
'tree
)
2128 (insert prefix
(if last
" `--- " " |--- "))
2129 (push (widget-create-child-and-convert
2130 widget
'custom-browse-variable-tag
)
2132 (insert " " tag
"\n")
2133 (widget-put widget
:buttons buttons
))
2135 ;; Indicate hidden value.
2136 (push (widget-create-child-and-convert
2139 :sample-face
'custom-variable-tag-face
2143 (push (widget-create-child-and-convert
2145 :help-echo
"Show the value of this option."
2147 :action
'custom-toggle-parent
2150 ((memq form
'(lisp mismatch
))
2151 ;; In lisp mode edit the saved value when possible.
2152 (let* ((value (cond ((get symbol
'saved-value
)
2153 (car (get symbol
'saved-value
)))
2154 ((get symbol
'standard-value
)
2155 (car (get symbol
'standard-value
)))
2156 ((default-boundp symbol
)
2157 (custom-quote (funcall get symbol
)))
2159 (custom-quote (widget-get conv
:value
))))))
2160 (insert (symbol-name symbol
) ": ")
2161 (push (widget-create-child-and-convert
2163 :help-echo
"Hide the value of this option."
2166 :action
'custom-toggle-parent
2170 (push (widget-create-child-and-convert
2172 :button-face
'custom-variable-button-face
2174 :tag
(symbol-name symbol
)
2180 (let* ((format (widget-get type
:format
))
2181 tag-format value-format
)
2182 (unless (string-match ":" format
)
2183 (error "Bad format"))
2184 (setq tag-format
(substring format
0 (match-end 0)))
2185 (setq value-format
(substring format
(match-end 0)))
2186 (push (widget-create-child-and-convert
2189 :action
'custom-tag-action
2190 :help-echo
"Change value of this option."
2191 :mouse-down-action
'custom-tag-mouse-down-action
2192 :button-face
'custom-variable-button-face
2193 :sample-face
'custom-variable-tag-face
2197 (push (widget-create-child-and-convert
2199 :help-echo
"Hide the value of this option."
2202 :action
'custom-toggle-parent
2205 (push (widget-create-child-and-convert
2207 :format value-format
2210 (unless (eq custom-buffer-style
'tree
)
2211 (unless (eq (preceding-char) ?
\n)
2212 (widget-insert "\n"))
2213 ;; Create the magic button.
2214 (let ((magic (widget-create-child-and-convert
2215 widget
'custom-magic nil
)))
2216 (widget-put widget
:custom-magic magic
)
2217 (push magic buttons
))
2218 ;; ### NOTE: this is ugly!!!! I need to update the :buttons property
2219 ;; before the call to `widget-default-format-handler'. Otherwise, I
2220 ;; loose my current `buttons'. This function shouldn't be called like
2221 ;; this anyway. The doc string widget should be added like the others.
2223 (widget-put widget
:buttons buttons
)
2225 ;; Insert documentation.
2226 (widget-default-format-handler widget ?h
)
2228 ;; The comment field
2229 (unless (eq state
'hidden
)
2230 (let* ((comment (get symbol
'variable-comment
))
2232 (widget-create-child-and-convert
2233 widget
'custom-comment
2235 :value
(or comment
""))))
2236 (widget-put widget
:comment-widget comment-widget
)
2237 ;; Don't push it !!! Custom assumes that the first child is the
2239 (setq children
(append children
(list comment-widget
)))))
2240 ;; Update the rest of the properties properties.
2241 (widget-put widget
:custom-form form
)
2242 (widget-put widget
:children children
)
2243 ;; Now update the state.
2244 (if (eq state
'hidden
)
2245 (widget-put widget
:custom-state state
)
2246 (custom-variable-state-set widget
))
2248 (unless (eq state
'hidden
)
2249 (when (eq (widget-get widget
:custom-level
) 1)
2250 (custom-add-parent-links widget
))
2251 (custom-add-see-also widget
)))))
2253 (defun custom-tag-action (widget &rest args
)
2254 "Pass :action to first child of WIDGET's parent."
2255 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2258 (defun custom-tag-mouse-down-action (widget &rest args
)
2259 "Pass :mouse-down-action to first child of WIDGET's parent."
2260 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2261 :mouse-down-action args
))
2263 (defun custom-variable-state-set (widget)
2264 "Set the state of WIDGET."
2265 (let* ((symbol (widget-value widget
))
2266 (get (or (get symbol
'custom-get
) 'default-value
))
2267 (value (if (default-boundp symbol
)
2268 (funcall get symbol
)
2269 (widget-get widget
:value
)))
2270 (comment (get symbol
'variable-comment
))
2273 (state (cond ((progn (setq tmp
(get symbol
'customized-value
))
2275 (get symbol
'customized-variable-comment
))
2277 (if (condition-case nil
2278 (and (equal value
(eval (car tmp
)))
2279 (equal comment temp
))
2283 ((progn (setq tmp
(get symbol
'saved-value
))
2284 (setq temp
(get symbol
'saved-variable-comment
))
2286 (if (condition-case nil
2287 (and (equal value
(eval (car tmp
)))
2288 (equal comment temp
))
2292 ((setq tmp
(get symbol
'standard-value
))
2293 (if (condition-case nil
2294 (and (equal value
(eval (car tmp
)))
2295 (equal comment nil
))
2300 (widget-put widget
:custom-state state
)))
2302 (defun custom-variable-standard-value (widget)
2303 (get (widget-value widget
) 'standard-value
))
2305 (defvar custom-variable-menu
2306 '(("Set for Current Session" custom-variable-set
2308 (eq (widget-get widget
:custom-state
) 'modified
)))
2309 ("Save for Future Sessions" custom-variable-save
2311 (memq (widget-get widget
:custom-state
) '(modified set changed rogue
))))
2312 ("Reset to Current" custom-redraw
2314 (and (default-boundp (widget-value widget
))
2315 (memq (widget-get widget
:custom-state
) '(modified changed
)))))
2316 ("Reset to Saved" custom-variable-reset-saved
2318 (and (or (get (widget-value widget
) 'saved-value
)
2319 (get (widget-value widget
) 'saved-variable-comment
))
2320 (memq (widget-get widget
:custom-state
)
2321 '(modified set changed rogue
)))))
2322 ("Erase Customization" custom-variable-reset-standard
2324 (and (get (widget-value widget
) 'standard-value
)
2325 (memq (widget-get widget
:custom-state
)
2326 '(modified set changed saved rogue
)))))
2327 ("Use Backup Value" custom-variable-reset-backup
2329 (get (widget-value widget
) 'backup-value
)))
2330 ("---" ignore ignore
)
2331 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
2332 ("---" ignore ignore
)
2333 ("Don't show as Lisp expression" custom-variable-edit
2335 (eq (widget-get widget
:custom-form
) 'lisp
)))
2336 ("Show initial Lisp expression" custom-variable-edit-lisp
2338 (eq (widget-get widget
:custom-form
) 'edit
))))
2339 "Alist of actions for the `custom-variable' widget.
2340 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2341 the menu entry, ACTION is the function to call on the widget when the
2342 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2343 widget as an argument, and returns non-nil if ACTION is valid on that
2344 widget. If FILTER is nil, ACTION is always valid.")
2346 (defun custom-variable-action (widget &optional event
)
2347 "Show the menu for `custom-variable' WIDGET.
2348 Optional EVENT is the location for the menu."
2349 (if (eq (widget-get widget
:custom-state
) 'hidden
)
2350 (custom-toggle-hide widget
)
2351 (unless (eq (widget-get widget
:custom-state
) 'modified
)
2352 (custom-variable-state-set widget
))
2353 (custom-redraw-magic widget
)
2354 (let* ((completion-ignore-case t
)
2355 (answer (widget-choose (concat "Operation on "
2356 (custom-unlispify-tag-name
2357 (widget-get widget
:value
)))
2358 (custom-menu-filter custom-variable-menu
2362 (funcall answer widget
)))))
2364 (defun custom-variable-edit (widget)
2365 "Edit value of WIDGET."
2366 (widget-put widget
:custom-state
'unknown
)
2367 (widget-put widget
:custom-form
'edit
)
2368 (custom-redraw widget
))
2370 (defun custom-variable-edit-lisp (widget)
2371 "Edit the Lisp representation of the value of WIDGET."
2372 (widget-put widget
:custom-state
'unknown
)
2373 (widget-put widget
:custom-form
'lisp
)
2374 (custom-redraw widget
))
2376 (defun custom-variable-set (widget)
2377 "Set the current value for the variable being edited by WIDGET."
2378 (let* ((form (widget-get widget
:custom-form
))
2379 (state (widget-get widget
:custom-state
))
2380 (child (car (widget-get widget
:children
)))
2381 (symbol (widget-value widget
))
2382 (set (or (get symbol
'custom-set
) 'set-default
))
2383 (comment-widget (widget-get widget
:comment-widget
))
2384 (comment (widget-value comment-widget
))
2386 (cond ((eq state
'hidden
)
2387 (error "Cannot set hidden variable"))
2388 ((setq val
(widget-apply child
:validate
))
2389 (goto-char (widget-get val
:from
))
2390 (error "%s" (widget-get val
:error
)))
2391 ((memq form
'(lisp mismatch
))
2392 (when (equal comment
"")
2394 ;; Make the comment invisible by hand if it's empty
2395 (custom-comment-hide comment-widget
))
2396 (custom-variable-backup-value widget
)
2397 (funcall set symbol
(eval (setq val
(widget-value child
))))
2398 (put symbol
'customized-value
(list val
))
2399 (put symbol
'variable-comment comment
)
2400 (put symbol
'customized-variable-comment comment
))
2402 (when (equal comment
"")
2404 ;; Make the comment invisible by hand if it's empty
2405 (custom-comment-hide comment-widget
))
2406 (custom-variable-backup-value widget
)
2407 (funcall set symbol
(setq val
(widget-value child
)))
2408 (put symbol
'customized-value
(list (custom-quote val
)))
2409 (put symbol
'variable-comment comment
)
2410 (put symbol
'customized-variable-comment comment
)))
2411 (custom-variable-state-set widget
)
2412 (custom-redraw-magic widget
)))
2414 (defun custom-variable-save (widget)
2415 "Set and save the value for the variable being edited by WIDGET."
2416 (let* ((form (widget-get widget
:custom-form
))
2417 (state (widget-get widget
:custom-state
))
2418 (child (car (widget-get widget
:children
)))
2419 (symbol (widget-value widget
))
2420 (set (or (get symbol
'custom-set
) 'set-default
))
2421 (comment-widget (widget-get widget
:comment-widget
))
2422 (comment (widget-value comment-widget
))
2424 (cond ((eq state
'hidden
)
2425 (error "Cannot set hidden variable"))
2426 ((setq val
(widget-apply child
:validate
))
2427 (goto-char (widget-get val
:from
))
2428 (error "Saving %s: %s" symbol
(widget-get val
:error
)))
2429 ((memq form
'(lisp mismatch
))
2430 (when (equal comment
"")
2432 ;; Make the comment invisible by hand if it's empty
2433 (custom-comment-hide comment-widget
))
2434 (put symbol
'saved-value
(list (widget-value child
)))
2435 (custom-push-theme 'theme-value symbol
'user
2436 'set
(list (widget-value child
)))
2437 (funcall set symbol
(eval (widget-value child
)))
2438 (put symbol
'variable-comment comment
)
2439 (put symbol
'saved-variable-comment comment
))
2441 (when (equal comment
"")
2443 ;; Make the comment invisible by hand if it's empty
2444 (custom-comment-hide comment-widget
))
2445 (put symbol
'saved-value
2446 (list (custom-quote (widget-value child
))))
2447 (custom-push-theme 'theme-value symbol
'user
2448 'set
(list (custom-quote (widget-value
2450 (funcall set symbol
(widget-value child
))
2451 (put symbol
'variable-comment comment
)
2452 (put symbol
'saved-variable-comment comment
)))
2453 (put symbol
'customized-value nil
)
2454 (put symbol
'customized-variable-comment nil
)
2456 (custom-variable-state-set widget
)
2457 (custom-redraw-magic widget
)))
2459 (defun custom-variable-reset-saved (widget)
2460 "Restore the saved value for the variable being edited by WIDGET.
2461 The value that was current before this operation
2462 becomes the backup value, so you can get it again."
2463 (let* ((symbol (widget-value widget
))
2464 (set (or (get symbol
'custom-set
) 'set-default
))
2465 (value (get symbol
'saved-value
))
2466 (comment (get symbol
'saved-variable-comment
)))
2467 (cond ((or value comment
)
2468 (put symbol
'variable-comment comment
)
2469 (custom-variable-backup-value widget
)
2471 (funcall set symbol
(eval (car value
)))
2474 (error "No saved value for %s" symbol
)))
2475 (put symbol
'customized-value nil
)
2476 (put symbol
'customized-variable-comment nil
)
2477 (widget-put widget
:custom-state
'unknown
)
2478 ;; This call will possibly make the comment invisible
2479 (custom-redraw widget
)))
2481 (defun custom-variable-reset-standard (widget)
2482 "Restore the standard setting for the variable being edited by WIDGET.
2483 This operation eliminates any saved setting for the variable,
2484 restoring it to the state of a variable that has never been customized.
2485 The value that was current before this operation
2486 becomes the backup value, so you can get it again."
2487 (let* ((symbol (widget-value widget
))
2488 (set (or (get symbol
'custom-set
) 'set-default
)))
2489 (if (get symbol
'standard-value
)
2491 (custom-variable-backup-value widget
)
2492 (funcall set symbol
(eval (car (get symbol
'standard-value
)))))
2493 (error "No standard setting known for %S" symbol
))
2494 (put symbol
'variable-comment nil
)
2495 (put symbol
'customized-value nil
)
2496 (put symbol
'customized-variable-comment nil
)
2497 (when (or (get symbol
'saved-value
) (get symbol
'saved-variable-comment
))
2498 (put symbol
'saved-value nil
)
2499 (custom-push-theme 'theme-value symbol
'user
'reset
'standard
)
2500 ;; As a special optimizations we do not (explictly)
2501 ;; save resets to standard when no theme set the value.
2502 (if (null (cdr (get symbol
'theme-value
)))
2503 (put symbol
'theme-value nil
))
2504 (put symbol
'saved-variable-comment nil
)
2506 (widget-put widget
:custom-state
'unknown
)
2507 ;; This call will possibly make the comment invisible
2508 (custom-redraw widget
)))
2510 (defun custom-variable-backup-value (widget)
2511 "Back up the current value for WIDGET's variable.
2512 The backup value is kept in the car of the `backup-value' property."
2513 (let* ((symbol (widget-value widget
))
2514 (get (or (get symbol
'custom-get
) 'default-value
))
2515 (type (custom-variable-type symbol
))
2516 (conv (widget-convert type
))
2517 (value (if (default-boundp symbol
)
2518 (funcall get symbol
)
2519 (widget-get conv
:value
))))
2520 (put symbol
'backup-value
(list value
))))
2522 (defun custom-variable-reset-backup (widget)
2523 "Restore the backup value for the variable being edited by WIDGET.
2524 The value that was current before this operation
2525 becomes the backup value, so you can use this operation repeatedly
2526 to switch between two values."
2527 (let* ((symbol (widget-value widget
))
2528 (set (or (get symbol
'custom-set
) 'set-default
))
2529 (value (get symbol
'backup-value
))
2530 (comment-widget (widget-get widget
:comment-widget
))
2531 (comment (widget-value comment-widget
)))
2534 (custom-variable-backup-value widget
)
2536 (funcall set symbol
(car value
))
2538 (error "No backup value for %s" symbol
))
2539 (put symbol
'customized-value
(list (car value
)))
2540 (put symbol
'variable-comment comment
)
2541 (put symbol
'customized-variable-comment comment
)
2542 (custom-variable-state-set widget
)
2543 ;; This call will possibly make the comment invisible
2544 (custom-redraw widget
)))
2546 ;;; The `custom-face-edit' Widget.
2548 (define-widget 'custom-face-edit
'checklist
2549 "Edit face attributes."
2553 :button-args
'(:help-echo
"Control whether this attribute has any effect.")
2554 :value-to-internal
'custom-face-edit-fix-value
2555 :match
(lambda (widget value
)
2556 (widget-checklist-match widget
2557 (custom-face-edit-fix-value widget value
)))
2558 :convert-widget
'custom-face-edit-convert-widget
2559 :args
(mapcar (lambda (att)
2562 :sibling-args
(widget-get (nth 1 att
) :sibling-args
)
2563 (list 'const
:format
"" :value
(nth 0 att
))
2565 custom-face-attributes
))
2567 (defun custom-face-edit-fix-value (widget value
)
2568 "Ignoring WIDGET, convert :bold and :italic in VALUE to new form.
2569 Also change :reverse-video to :inverse-video."
2573 (let ((key (car value
))
2574 (val (car (cdr value
))))
2575 (cond ((eq key
:italic
)
2576 (push :slant result
)
2577 (push (if val
'italic
'normal
) result
))
2579 (push :weight result
)
2580 (push (if val
'bold
'normal
) result
))
2581 ((eq key
:reverse-video
)
2582 (push :inverse-video result
)
2586 (push val result
))))
2587 (setq value
(cdr (cdr value
))))
2588 (setq result
(nreverse result
))
2592 (defun custom-face-edit-convert-widget (widget)
2593 "Convert :args as widget types in WIDGET."
2596 :args
(mapcar (lambda (arg)
2598 :deactivate
'custom-face-edit-deactivate
2599 :activate
'custom-face-edit-activate
2600 :delete
'custom-face-edit-delete
))
2601 (widget-get widget
:args
)))
2604 (defun custom-face-edit-deactivate (widget)
2605 "Make face widget WIDGET inactive for user modifications."
2606 (unless (widget-get widget
:inactive
)
2607 (let ((tag (custom-face-edit-attribute-tag widget
))
2608 (from (copy-marker (widget-get widget
:from
)))
2609 (value (widget-value widget
))
2610 (inhibit-read-only t
)
2611 (inhibit-modification-hooks t
))
2614 (widget-default-delete widget
)
2615 (insert tag
": *\n")
2616 (widget-put widget
:inactive
2617 (cons value
(cons from
(- (point) from
))))))))
2619 (defun custom-face-edit-activate (widget)
2620 "Make face widget WIDGET inactive for user modifications."
2621 (let ((inactive (widget-get widget
:inactive
))
2622 (inhibit-read-only t
)
2623 (inhibit-modification-hooks t
))
2624 (when (consp inactive
)
2626 (goto-char (car (cdr inactive
)))
2627 (delete-region (point) (+ (point) (cdr (cdr inactive
))))
2628 (widget-put widget
:inactive nil
)
2629 (widget-apply widget
:create
)
2630 (widget-value-set widget
(car inactive
))
2633 (defun custom-face-edit-delete (widget)
2634 "Remove widget from the buffer."
2635 (let ((inactive (widget-get widget
:inactive
))
2636 (inhibit-read-only t
)
2637 (inhibit-modification-hooks t
))
2639 ;; Widget is alive, we don't have to do anything special
2640 (widget-default-delete widget
)
2641 ;; WIDGET is already deleted because we did so to inactivate it;
2642 ;; now just get rid of the label we put in its place.
2643 (delete-region (car (cdr inactive
))
2644 (+ (car (cdr inactive
)) (cdr (cdr inactive
))))
2645 (widget-put widget
:inactive nil
))))
2648 (defun custom-face-edit-attribute-tag (widget)
2649 "Returns the first :tag property in WIDGET or one of its children."
2650 (let ((tag (widget-get widget
:tag
)))
2651 (or (and (not (equal tag
"")) tag
)
2652 (let ((children (widget-get widget
:children
)))
2653 (while (and (null tag
) children
)
2654 (setq tag
(custom-face-edit-attribute-tag (pop children
))))
2657 ;;; The `custom-display' Widget.
2659 (define-widget 'custom-display
'menu-choice
2660 "Select a display type."
2663 :help-echo
"Specify frames where the face attributes should be used."
2664 :args
'((const :tag
"all" t
)
2668 :args
((group :sibling-args
(:help-echo
"\
2669 Only match the specified window systems.")
2670 (const :format
"Type: "
2672 (checklist :inline t
2675 :sibling-args
(:help-echo
"\
2676 The X11 Window System.")
2678 (const :format
"PM "
2679 :sibling-args
(:help-echo
"\
2680 OS/2 Presentation Manager.")
2682 (const :format
"W32 "
2683 :sibling-args
(:help-echo
"\
2686 (const :format
"MAC "
2687 :sibling-args
(:help-echo
"\
2690 (const :format
"DOS "
2691 :sibling-args
(:help-echo
"\
2694 (const :format
"TTY%n"
2695 :sibling-args
(:help-echo
"\
2696 Plain text terminals.")
2698 (group :sibling-args
(:help-echo
"\
2699 Only match the frames with the specified color support.")
2700 (const :format
"Class: "
2702 (checklist :inline t
2704 (const :format
"Color "
2705 :sibling-args
(:help-echo
"\
2706 Match color frames.")
2708 (const :format
"Grayscale "
2709 :sibling-args
(:help-echo
"\
2710 Match grayscale frames.")
2712 (const :format
"Monochrome%n"
2713 :sibling-args
(:help-echo
"\
2714 Match frames with no color support.")
2716 (group :sibling-args
(:help-echo
"\
2717 Only match frames with the specified intensity.")
2719 Background brightness: "
2721 (checklist :inline t
2723 (const :format
"Light "
2724 :sibling-args
(:help-echo
"\
2725 Match frames with light backgrounds.")
2727 (const :format
"Dark\n"
2728 :sibling-args
(:help-echo
"\
2729 Match frames with dark backgrounds.")
2731 (group :sibling-args
(:help-echo
"\
2732 Only match frames that support the specified face attributes.")
2733 (const :format
"Supports attributes:" supports
)
2734 (custom-face-edit :inline t
:format
"%n%v"))))))
2736 ;;; The `custom-face' Widget.
2738 (defface custom-face-tag-face
2739 `((t (:weight bold
:height
1.2 :inherit variable-pitch
)))
2740 "Face used for face tags."
2741 :group
'custom-faces
)
2743 (defcustom custom-face-default-form
'selected
2744 "Default form of displaying face definition."
2745 :type
'(choice (const all
)
2748 :group
'custom-buffer
2751 (define-widget 'custom-face
'custom
2753 :sample-face
'custom-face-tag-face
2754 :help-echo
"Set or reset this face."
2755 :documentation-property
#'face-doc-string
2756 :value-create
'custom-face-value-create
2757 :action
'custom-face-action
2758 :custom-category
'face
2759 :custom-form nil
; defaults to value of `custom-face-default-form'
2760 :custom-set
'custom-face-set
2761 :custom-save
'custom-face-save
2762 :custom-reset-current
'custom-redraw
2763 :custom-reset-saved
'custom-face-reset-saved
2764 :custom-reset-standard
'custom-face-reset-standard
2765 :custom-standard-value
'custom-face-standard-value
2766 :custom-menu
'custom-face-menu-create
)
2768 (define-widget 'custom-face-all
'editable-list
2769 "An editable list of display specifications and attributes."
2770 :entry-format
"%i %d %v"
2771 :insert-button-args
'(:help-echo
"Insert new display specification here.")
2772 :append-button-args
'(:help-echo
"Append new display specification here.")
2773 :delete-button-args
'(:help-echo
"Delete this display specification.")
2774 :args
'((group :format
"%v" custom-display custom-face-edit
)))
2776 (defconst custom-face-all
(widget-convert 'custom-face-all
)
2777 "Converted version of the `custom-face-all' widget.")
2779 (define-widget 'custom-display-unselected
'item
2780 "A display specification that doesn't match the selected display."
2781 :match
'custom-display-unselected-match
)
2783 (defun custom-display-unselected-match (widget value
)
2784 "Non-nil if VALUE is an unselected display specification."
2785 (not (face-spec-set-match-display value
(selected-frame))))
2787 (define-widget 'custom-face-selected
'group
2788 "Edit the attributes of the selected display in a face specification."
2789 :args
'((repeat :format
""
2791 (group custom-display-unselected sexp
))
2792 (group (sexp :format
"") custom-face-edit
)
2797 (defconst custom-face-selected
(widget-convert 'custom-face-selected
)
2798 "Converted version of the `custom-face-selected' widget.")
2800 (defun custom-filter-face-spec (spec filter-index
&optional default-filter
)
2801 "Return a canonicalized version of SPEC using.
2802 FILTER-INDEX is the index in the entry for each attribute in
2803 `custom-face-attributes' at which the appropriate filter function can be
2804 found, and DEFAULT-FILTER is the filter to apply for attributes that
2806 (mapcar (lambda (entry)
2807 ;; Filter a single face-spec entry
2808 (let ((tests (car entry
))
2810 ;; Handle both old- and new-style attribute syntax
2811 (if (listp (car (cdr entry
)))
2814 (filtered-attrs nil
))
2815 ;; Filter each face attribute
2816 (while unfiltered-attrs
2817 (let* ((attr (pop unfiltered-attrs
))
2818 (pre-filtered-value (pop unfiltered-attrs
))
2820 (or (nth filter-index
(assq attr custom-face-attributes
))
2824 (funcall filter pre-filtered-value
)
2825 pre-filtered-value
)))
2826 (push filtered-value filtered-attrs
)
2827 (push attr filtered-attrs
)))
2829 (list tests filtered-attrs
)))
2832 (defun custom-pre-filter-face-spec (spec)
2833 "Return SPEC changed as necessary for editing by the face customization widget.
2834 SPEC must be a full face spec."
2835 (custom-filter-face-spec spec
2))
2837 (defun custom-post-filter-face-spec (spec)
2838 "Return the customized SPEC in a form suitable for setting the face."
2839 (custom-filter-face-spec spec
3))
2841 (defun custom-face-value-create (widget)
2842 "Create a list of the display specifications for WIDGET."
2843 (let ((buttons (widget-get widget
:buttons
))
2845 (symbol (widget-get widget
:value
))
2846 (tag (widget-get widget
:tag
))
2847 (state (widget-get widget
:custom-state
))
2849 (is-last (widget-get widget
:custom-last
))
2850 (prefix (widget-get widget
:custom-prefix
)))
2852 (setq tag
(prin1-to-string symbol
)))
2853 (cond ((eq custom-buffer-style
'tree
)
2854 (insert prefix
(if is-last
" `--- " " |--- "))
2855 (push (widget-create-child-and-convert
2856 widget
'custom-browse-face-tag
)
2858 (insert " " tag
"\n")
2859 (widget-put widget
:buttons buttons
))
2863 (widget-specify-sample widget begin
(point))
2864 (if (eq custom-buffer-style
'face
)
2866 (if (string-match "face\\'" tag
)
2868 (insert " face: ")))
2870 (push (widget-create-child-and-convert widget
'item
2877 (push (widget-create-child-and-convert
2879 :help-echo
"Hide or show this face."
2882 :action
'custom-toggle-parent
2883 (not (eq state
'hidden
)))
2887 (let ((magic (widget-create-child-and-convert
2888 widget
'custom-magic nil
)))
2889 (widget-put widget
:custom-magic magic
)
2890 (push magic buttons
))
2892 (widget-put widget
:buttons buttons
)
2893 ;; Insert documentation.
2894 (widget-default-format-handler widget ?h
)
2895 ;; The comment field
2896 (unless (eq state
'hidden
)
2897 (let* ((comment (get symbol
'face-comment
))
2899 (widget-create-child-and-convert
2900 widget
'custom-comment
2902 :value
(or comment
""))))
2903 (widget-put widget
:comment-widget comment-widget
)
2904 (push comment-widget children
)))
2906 (unless (eq state
'hidden
)
2907 (when (eq (widget-get widget
:custom-level
) 1)
2908 (custom-add-parent-links widget
))
2909 (custom-add-see-also widget
))
2911 (unless (eq (preceding-char) ?
\n)
2913 (unless (eq state
'hidden
)
2914 (message "Creating face editor...")
2915 (custom-load-widget widget
)
2916 (unless (widget-get widget
:custom-form
)
2917 (widget-put widget
:custom-form custom-face-default-form
))
2918 (let* ((symbol (widget-value widget
))
2919 (spec (or (get symbol
'customized-face
)
2920 (get symbol
'saved-face
)
2921 (get symbol
'face-defface-spec
)
2922 ;; Attempt to construct it.
2923 (list (list t
(custom-face-attributes-get
2924 symbol
(selected-frame))))))
2925 (form (widget-get widget
:custom-form
))
2926 (indent (widget-get widget
:indent
))
2928 ;; If the user has changed this face in some other way,
2929 ;; edit it as the user has specified it.
2930 (if (not (face-spec-match-p symbol spec
(selected-frame)))
2931 (setq spec
(list (list t
(face-attr-construct symbol
(selected-frame))))))
2932 (setq spec
(custom-pre-filter-face-spec spec
))
2933 (setq edit
(widget-create-child-and-convert
2935 (cond ((and (eq form
'selected
)
2936 (widget-apply custom-face-selected
2938 (when indent
(insert-char ?\ indent
))
2939 'custom-face-selected
)
2940 ((and (not (eq form
'lisp
))
2941 (widget-apply custom-face-all
2945 (when indent
(insert-char ?\ indent
))
2948 (custom-face-state-set widget
)
2949 (push edit children
)
2950 (widget-put widget
:children children
))
2951 (message "Creating face editor...done"))))))
2953 (defvar custom-face-menu
2954 '(("Set for Current Session" custom-face-set
)
2955 ("Save for Future Sessions" custom-face-save-command
)
2956 ("Reset to Saved" custom-face-reset-saved
2958 (or (get (widget-value widget
) 'saved-face
)
2959 (get (widget-value widget
) 'saved-face-comment
))))
2960 ("Erase Customization" custom-face-reset-standard
2962 (get (widget-value widget
) 'face-defface-spec
)))
2963 ("---" ignore ignore
)
2964 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
2965 ("---" ignore ignore
)
2966 ("Show all display specs" custom-face-edit-all
2968 (not (eq (widget-get widget
:custom-form
) 'all
))))
2969 ("Just current attributes" custom-face-edit-selected
2971 (not (eq (widget-get widget
:custom-form
) 'selected
))))
2972 ("Show as Lisp expression" custom-face-edit-lisp
2974 (not (eq (widget-get widget
:custom-form
) 'lisp
)))))
2975 "Alist of actions for the `custom-face' widget.
2976 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2977 the menu entry, ACTION is the function to call on the widget when the
2978 menu is selected, and FILTER is a predicate which takes a `custom-face'
2979 widget as an argument, and returns non-nil if ACTION is valid on that
2980 widget. If FILTER is nil, ACTION is always valid.")
2982 (defun custom-face-edit-selected (widget)
2983 "Edit selected attributes of the value of WIDGET."
2984 (widget-put widget
:custom-state
'unknown
)
2985 (widget-put widget
:custom-form
'selected
)
2986 (custom-redraw widget
))
2988 (defun custom-face-edit-all (widget)
2989 "Edit all attributes of the value of WIDGET."
2990 (widget-put widget
:custom-state
'unknown
)
2991 (widget-put widget
:custom-form
'all
)
2992 (custom-redraw widget
))
2994 (defun custom-face-edit-lisp (widget)
2995 "Edit the Lisp representation of the value of WIDGET."
2996 (widget-put widget
:custom-state
'unknown
)
2997 (widget-put widget
:custom-form
'lisp
)
2998 (custom-redraw widget
))
3000 (defun custom-face-state-set (widget)
3001 "Set the state of WIDGET."
3002 (let* ((symbol (widget-value widget
))
3003 (comment (get symbol
'face-comment
))
3007 (setq tmp
(get symbol
'customized-face
))
3008 (setq temp
(get symbol
'customized-face-comment
))
3010 (if (equal temp comment
)
3014 (setq tmp
(get symbol
'saved-face
))
3015 (setq temp
(get symbol
'saved-face-comment
))
3017 (if (equal temp comment
)
3020 ((get symbol
'face-defface-spec
)
3021 (if (equal comment nil
)
3026 ;; If the user called set-face-attribute to change the default
3027 ;; for new frames, this face is "set outside of Customize".
3028 (if (and (not (eq state
'rogue
))
3029 (get symbol
'face-modified
))
3030 (setq state
'changed
))
3031 (widget-put widget
:custom-state state
)))
3033 (defun custom-face-action (widget &optional event
)
3034 "Show the menu for `custom-face' WIDGET.
3035 Optional EVENT is the location for the menu."
3036 (if (eq (widget-get widget
:custom-state
) 'hidden
)
3037 (custom-toggle-hide widget
)
3038 (let* ((completion-ignore-case t
)
3039 (symbol (widget-get widget
:value
))
3040 (answer (widget-choose (concat "Operation on "
3041 (custom-unlispify-tag-name symbol
))
3042 (custom-menu-filter custom-face-menu
3046 (funcall answer widget
)))))
3048 (defun custom-face-set (widget)
3049 "Make the face attributes in WIDGET take effect."
3050 (let* ((symbol (widget-value widget
))
3051 (child (car (widget-get widget
:children
)))
3052 (value (custom-post-filter-face-spec (widget-value child
)))
3053 (comment-widget (widget-get widget
:comment-widget
))
3054 (comment (widget-value comment-widget
)))
3055 (when (equal comment
"")
3057 ;; Make the comment invisible by hand if it's empty
3058 (custom-comment-hide comment-widget
))
3059 (put symbol
'customized-face value
)
3060 (if (face-spec-choose value
)
3061 (face-spec-set symbol value
)
3062 ;; face-set-spec ignores empty attribute lists, so just give it
3063 ;; something harmless instead.
3064 (face-spec-set symbol
'((t :foreground unspecified
))))
3065 (put symbol
'customized-face-comment comment
)
3066 (put symbol
'face-comment comment
)
3067 (custom-face-state-set widget
)
3068 (custom-redraw-magic widget
)))
3070 (defun custom-face-save-command (widget)
3071 "Save in `.emacs' the face attributes in WIDGET."
3072 (custom-face-save widget
)
3075 (defun custom-face-save (widget)
3076 "Prepare for saving WIDGET's face attributes, but don't write `.emacs'."
3077 (let* ((symbol (widget-value widget
))
3078 (child (car (widget-get widget
:children
)))
3079 (value (custom-post-filter-face-spec (widget-value child
)))
3080 (comment-widget (widget-get widget
:comment-widget
))
3081 (comment (widget-value comment-widget
)))
3082 (when (equal comment
"")
3084 ;; Make the comment invisible by hand if it's empty
3085 (custom-comment-hide comment-widget
))
3086 (if (face-spec-choose value
)
3087 (face-spec-set symbol value
)
3088 ;; face-set-spec ignores empty attribute lists, so just give it
3089 ;; something harmless instead.
3090 (face-spec-set symbol
'((t :foreground unspecified
))))
3091 (unless (eq (widget-get widget
:custom-state
) 'standard
)
3092 (put symbol
'saved-face value
))
3093 (custom-push-theme 'theme-face symbol
'user
'set value
)
3094 (put symbol
'customized-face nil
)
3095 (put symbol
'face-comment comment
)
3096 (put symbol
'customized-face-comment nil
)
3097 (put symbol
'saved-face-comment comment
)
3099 (custom-face-state-set widget
)
3100 (custom-redraw-magic widget
)))
3102 (defun custom-face-reset-saved (widget)
3103 "Restore WIDGET to the face's default attributes."
3104 (let* ((symbol (widget-value widget
))
3105 (child (car (widget-get widget
:children
)))
3106 (value (get symbol
'saved-face
))
3107 (comment (get symbol
'saved-face-comment
))
3108 (comment-widget (widget-get widget
:comment-widget
)))
3109 (unless (or value comment
)
3110 (error "No saved value for this face"))
3111 (put symbol
'customized-face nil
)
3112 (put symbol
'customized-face-comment nil
)
3113 (face-spec-set symbol value
)
3114 (put symbol
'face-comment comment
)
3115 (widget-value-set child value
)
3116 ;; This call manages the comment visibility
3117 (widget-value-set comment-widget
(or comment
""))
3118 (custom-face-state-set widget
)
3119 (custom-redraw-magic widget
)))
3121 (defun custom-face-standard-value (widget)
3122 (get (widget-value widget
) 'face-defface-spec
))
3124 (defun custom-face-reset-standard (widget)
3125 "Restore WIDGET to the face's standard settings.
3126 This operation eliminates any saved setting for the face,
3127 restoring it to the state of a face that has never been customized."
3128 (let* ((symbol (widget-value widget
))
3129 (child (car (widget-get widget
:children
)))
3130 (value (get symbol
'face-defface-spec
))
3131 (comment-widget (widget-get widget
:comment-widget
)))
3133 (error "No standard setting for this face"))
3134 (put symbol
'customized-face nil
)
3135 (put symbol
'customized-face-comment nil
)
3136 (when (or (get symbol
'saved-face
) (get symbol
'saved-face-comment
))
3137 (put symbol
'saved-face nil
)
3138 (custom-push-theme 'theme-face symbol
'user
'reset
'standard
)
3139 ;; Do not explictly save resets to standards without themes.
3140 (if (null (cdr (get symbol
'theme-face
)))
3141 (put symbol
'theme-face nil
))
3142 (put symbol
'saved-face-comment nil
)
3144 (face-spec-set symbol value
)
3145 (put symbol
'face-comment nil
)
3146 (widget-value-set child value
)
3147 ;; This call manages the comment visibility
3148 (widget-value-set comment-widget
"")
3149 (custom-face-state-set widget
)
3150 (custom-redraw-magic widget
)))
3152 ;;; The `face' Widget.
3154 (define-widget 'face
'default
3155 "Select and customize a face."
3156 :convert-widget
'widget-value-convert-widget
3157 :button-prefix
'widget-push-button-prefix
3158 :button-suffix
'widget-push-button-suffix
3159 :format
"%{%t%}: %[select face%] %v"
3162 :value-create
'widget-face-value-create
3163 :value-delete
'widget-face-value-delete
3164 :value-get
'widget-value-value-get
3165 :validate
'widget-children-validate
3166 :action
'widget-face-action
3167 :match
(lambda (widget value
) (symbolp value
)))
3169 (defun widget-face-value-create (widget)
3170 "Create a `custom-face' child."
3171 (let* ((symbol (widget-value widget
))
3172 (custom-buffer-style 'face
)
3173 (child (widget-create-child-and-convert
3177 (custom-magic-reset child
)
3178 (setq custom-options
(cons child custom-options
))
3179 (widget-put widget
:children
(list child
))))
3181 (defun widget-face-value-delete (widget)
3182 "Remove the child from the options."
3183 (let ((child (car (widget-get widget
:children
))))
3184 (setq custom-options
(delq child custom-options
))
3185 (widget-children-value-delete widget
)))
3187 (defvar face-history nil
3188 "History of entered face names.")
3190 (defun widget-face-action (widget &optional event
)
3191 "Prompt for a face."
3192 (let ((answer (completing-read "Face: "
3193 (mapcar (lambda (face)
3194 (list (symbol-name face
)))
3198 (unless (zerop (length answer
))
3199 (widget-value-set widget
(intern answer
))
3200 (widget-apply widget
:notify widget event
)
3203 ;;; The `hook' Widget.
3205 (define-widget 'hook
'list
3207 :value-to-internal
(lambda (widget value
)
3208 (if (and value
(symbolp value
))
3211 :match
(lambda (widget value
)
3213 (widget-group-match widget value
)))
3214 ;; Avoid adding undefined functions to the hook, especially for
3215 ;; things like `find-file-hook' or even more basic ones, to avoid
3217 :set
(lambda (symbol value
)
3220 (add-hook symbol elt
))))
3221 :convert-widget
'custom-hook-convert-widget
3224 (defun custom-hook-convert-widget (widget)
3225 ;; Handle `:options'.
3226 (let* ((options (widget-get widget
:options
))
3227 (other `(editable-list :inline t
3228 :entry-format
"%i %d%v"
3229 (function :format
" %v")))
3231 (list `(checklist :inline t
3232 ,@(mapcar (lambda (entry)
3233 `(function-item ,entry
))
3237 (widget-put widget
:args args
)
3240 ;;; The `custom-group-link' Widget.
3242 (define-widget 'custom-group-link
'link
3243 "Show parent in other window when activated."
3244 :help-echo
"Create customization buffer for this group."
3245 :action
'custom-group-link-action
)
3247 (defun custom-group-link-action (widget &rest ignore
)
3248 (customize-group (widget-value widget
)))
3250 ;;; The `custom-group' Widget.
3252 (defcustom custom-group-tag-faces nil
3253 ;; In XEmacs, this ought to play games with font size.
3254 ;; Fixme: make it do so in Emacs.
3255 "Face used for group tags.
3256 The first member is used for level 1 groups, the second for level 2,
3257 and so forth. The remaining group tags are shown with
3258 `custom-group-tag-face'."
3259 :type
'(repeat face
)
3260 :group
'custom-faces
)
3262 (defface custom-group-tag-face-1
3265 (:foreground
"pink" :weight bold
:height
1.2 :inherit variable-pitch
))
3268 (:foreground
"red" :weight bold
:height
1.2 :inherit variable-pitch
))
3270 "Face used for group tags."
3271 :group
'custom-faces
)
3273 (defface custom-group-tag-face
3276 (:foreground
"light blue" :weight bold
:height
1.2))
3279 (:foreground
"blue" :weight bold
:height
1.2))
3281 "Face used for low level group tags."
3282 :group
'custom-faces
)
3284 (define-widget 'custom-group
'custom
3287 :sample-face-get
'custom-group-sample-face-get
3288 :documentation-property
'group-documentation
3289 :help-echo
"Set or reset all members of this group."
3290 :value-create
'custom-group-value-create
3291 :action
'custom-group-action
3292 :custom-category
'group
3293 :custom-set
'custom-group-set
3294 :custom-save
'custom-group-save
3295 :custom-reset-current
'custom-group-reset-current
3296 :custom-reset-saved
'custom-group-reset-saved
3297 :custom-reset-standard
'custom-group-reset-standard
3298 :custom-menu
'custom-group-menu-create
)
3300 (defun custom-group-sample-face-get (widget)
3301 ;; Use :sample-face.
3302 (or (nth (1- (widget-get widget
:custom-level
)) custom-group-tag-faces
)
3303 'custom-group-tag-face
))
3305 (define-widget 'custom-group-visibility
'visibility
3306 "An indicator and manipulator for hidden group contents."
3307 :create
'custom-group-visibility-create
)
3309 (defun custom-group-visibility-create (widget)
3310 (let ((visible (widget-value widget
)))
3312 (insert "--------")))
3313 (widget-default-create widget
))
3315 (defun custom-group-members (symbol groups-only
)
3316 "Return SYMBOL's custom group members.
3317 If GROUPS-ONLY non-nil, return only those members that are groups."
3318 (if (not groups-only
)
3319 (get symbol
'custom-group
)
3321 (dolist (entry (get symbol
'custom-group
))
3322 (when (eq (nth 1 entry
) 'custom-group
)
3323 (push entry members
)))
3324 (nreverse members
))))
3326 (defun custom-group-value-create (widget)
3327 "Insert a customize group for WIDGET in the current buffer."
3328 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
3329 (custom-load-widget widget
))
3330 (let* ((state (widget-get widget
:custom-state
))
3331 (level (widget-get widget
:custom-level
))
3332 ;; (indent (widget-get widget :indent))
3333 (prefix (widget-get widget
:custom-prefix
))
3334 (buttons (widget-get widget
:buttons
))
3335 (tag (widget-get widget
:tag
))
3336 (symbol (widget-value widget
))
3337 (members (custom-group-members symbol
3338 (and (eq custom-buffer-style
'tree
)
3339 custom-browse-only-groups
))))
3340 (cond ((and (eq custom-buffer-style
'tree
)
3342 (or members
(custom-unloaded-widget-p widget
)))
3343 (custom-browse-insert-prefix prefix
)
3344 (push (widget-create-child-and-convert
3345 widget
'custom-browse-visibility
3346 ;; :tag-glyph "plus"
3350 ;; (widget-glyph-insert nil "-- " "horizontal")
3351 (push (widget-create-child-and-convert
3352 widget
'custom-browse-group-tag
)
3354 (insert " " tag
"\n")
3355 (widget-put widget
:buttons buttons
))
3356 ((and (eq custom-buffer-style
'tree
)
3357 (zerop (length members
)))
3358 (custom-browse-insert-prefix prefix
)
3360 ;; (widget-glyph-insert nil "[ ]" "empty")
3361 ;; (widget-glyph-insert nil "-- " "horizontal")
3362 (push (widget-create-child-and-convert
3363 widget
'custom-browse-group-tag
)
3365 (insert " " tag
"\n")
3366 (widget-put widget
:buttons buttons
))
3367 ((eq custom-buffer-style
'tree
)
3368 (custom-browse-insert-prefix prefix
)
3369 (if (zerop (length members
))
3371 (custom-browse-insert-prefix prefix
)
3373 ;; (widget-glyph-insert nil "[ ]" "empty")
3374 ;; (widget-glyph-insert nil "-- " "horizontal")
3375 (push (widget-create-child-and-convert
3376 widget
'custom-browse-group-tag
)
3378 (insert " " tag
"\n")
3379 (widget-put widget
:buttons buttons
))
3380 (push (widget-create-child-and-convert
3381 widget
'custom-browse-visibility
3382 ;; :tag-glyph "minus"
3386 ;; (widget-glyph-insert nil "-\\ " "top")
3387 (push (widget-create-child-and-convert
3388 widget
'custom-browse-group-tag
)
3390 (insert " " tag
"\n")
3391 (widget-put widget
:buttons buttons
)
3392 (message "Creating group...")
3393 (let* ((members (custom-sort-items members
3394 custom-browse-sort-alphabetically
3395 custom-browse-order-groups
))
3396 (prefixes (widget-get widget
:custom-prefixes
))
3397 (custom-prefix-list (custom-prefix-add symbol prefixes
))
3398 (extra-prefix (if (widget-get widget
:custom-last
)
3401 (prefix (concat prefix extra-prefix
))
3404 (setq entry
(car members
)
3405 members
(cdr members
))
3406 (push (widget-create-child-and-convert
3407 widget
(nth 1 entry
)
3409 :tag
(custom-unlispify-tag-name (nth 0 entry
))
3410 :custom-prefixes custom-prefix-list
3411 :custom-level
(1+ level
)
3412 :custom-last
(null members
)
3413 :value
(nth 0 entry
)
3414 :custom-prefix prefix
)
3416 (widget-put widget
:children
(reverse children
)))
3417 (message "Creating group...done")))
3420 ;; Create level indicator.
3421 (unless (eq custom-buffer-style
'links
)
3422 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3425 (let ((begin (point)))
3427 (widget-specify-sample widget begin
(point)))
3429 ;; Create link/visibility indicator.
3430 (if (eq custom-buffer-style
'links
)
3431 (push (widget-create-child-and-convert
3432 widget
'custom-group-link
3436 (push (widget-create-child-and-convert
3437 widget
'custom-group-visibility
3438 :help-echo
"Show members of this group."
3439 :action
'custom-toggle-parent
3440 (not (eq state
'hidden
)))
3443 ;; Create magic button.
3444 (let ((magic (widget-create-child-and-convert
3445 widget
'custom-magic nil
)))
3446 (widget-put widget
:custom-magic magic
)
3447 (push magic buttons
))
3449 (widget-put widget
:buttons buttons
)
3450 ;; Insert documentation.
3451 (if (and (eq custom-buffer-style
'links
) (> level
1))
3452 (widget-put widget
:documentation-indent
0))
3453 (widget-default-format-handler widget ?h
))
3456 ;; Add parent groups references above the group.
3457 (if t
;;; This should test that the buffer
3458 ;;; was made to display a group.
3460 (if (custom-add-parent-links widget
3461 "Go to parent group:")
3463 ;; Create level indicator.
3464 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3467 (let ((start (point)))
3469 (widget-specify-sample widget start
(point)))
3471 ;; Create visibility indicator.
3472 (unless (eq custom-buffer-style
'links
)
3474 (push (widget-create-child-and-convert
3476 :help-echo
"Hide members of this group."
3477 :action
'custom-toggle-parent
3478 (not (eq state
'hidden
)))
3481 ;; Create more dashes.
3482 ;; Use 76 instead of 75 to compensate for the temporary "<"
3483 ;; added by `widget-insert'.
3484 (insert-char ?-
(- 76 (current-column)
3485 (* custom-buffer-indent level
)))
3487 ;; Create magic button.
3488 (let ((magic (widget-create-child-and-convert
3489 widget
'custom-magic
3492 (widget-put widget
:custom-magic magic
)
3493 (push magic buttons
))
3495 (widget-put widget
:buttons buttons
)
3496 ;; Insert documentation.
3497 (widget-default-format-handler widget ?h
)
3499 (if nil
;;; This should test that the buffer
3500 ;;; was not made to display a group.
3502 (insert-char ?\ custom-buffer-indent
)
3503 (custom-add-parent-links widget
)))
3504 (custom-add-see-also widget
3505 (make-string (* custom-buffer-indent level
)
3508 (message "Creating group...")
3509 (let* ((members (custom-sort-items members
3510 custom-buffer-sort-alphabetically
3511 custom-buffer-order-groups
))
3512 (prefixes (widget-get widget
:custom-prefixes
))
3513 (custom-prefix-list (custom-prefix-add symbol prefixes
))
3514 (length (length members
))
3516 (children (mapcar (lambda (entry)
3517 (widget-insert "\n")
3519 Creating group members... %2d%%"
3520 (/ (* 100.0 count
) length
))
3521 (setq count
(1+ count
))
3523 (widget-create-child-and-convert
3524 widget
(nth 1 entry
)
3526 :tag
(custom-unlispify-tag-name
3528 :custom-prefixes custom-prefix-list
3529 :custom-level
(1+ level
)
3530 :value
(nth 0 entry
))
3531 (unless (eq (preceding-char) ?
\n)
3532 (widget-insert "\n"))))
3534 (message "Creating group magic...")
3535 (mapc 'custom-magic-reset children
)
3536 (message "Creating group state...")
3537 (widget-put widget
:children children
)
3538 (custom-group-state-update widget
)
3539 (message "Creating group... done"))
3542 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3543 (insert "\\- " (widget-get widget
:tag
) " group end ")
3544 (insert-char ?-
(- 75 (current-column) (* custom-buffer-indent level
)))
3547 (defvar custom-group-menu
3548 '(("Set for Current Session" custom-group-set
3550 (eq (widget-get widget
:custom-state
) 'modified
)))
3551 ("Save for Future Sessions" custom-group-save
3553 (memq (widget-get widget
:custom-state
) '(modified set
))))
3554 ("Reset to Current" custom-group-reset-current
3556 (memq (widget-get widget
:custom-state
) '(modified))))
3557 ("Reset to Saved" custom-group-reset-saved
3559 (memq (widget-get widget
:custom-state
) '(modified set
))))
3560 ("Reset to standard setting" custom-group-reset-standard
3562 (memq (widget-get widget
:custom-state
) '(modified set saved
)))))
3563 "Alist of actions for the `custom-group' widget.
3564 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3565 the menu entry, ACTION is the function to call on the widget when the
3566 menu is selected, and FILTER is a predicate which takes a `custom-group'
3567 widget as an argument, and returns non-nil if ACTION is valid on that
3568 widget. If FILTER is nil, ACTION is always valid.")
3570 (defun custom-group-action (widget &optional event
)
3571 "Show the menu for `custom-group' WIDGET.
3572 Optional EVENT is the location for the menu."
3573 (if (eq (widget-get widget
:custom-state
) 'hidden
)
3574 (custom-toggle-hide widget
)
3575 (let* ((completion-ignore-case t
)
3576 (answer (widget-choose (concat "Operation on "
3577 (custom-unlispify-tag-name
3578 (widget-get widget
:value
)))
3579 (custom-menu-filter custom-group-menu
3583 (funcall answer widget
)))))
3585 (defun custom-group-set (widget)
3586 "Set changes in all modified group members."
3587 (let ((children (widget-get widget
:children
)))
3588 (mapc (lambda (child)
3589 (when (eq (widget-get child
:custom-state
) 'modified
)
3590 (widget-apply child
:custom-set
)))
3593 (defun custom-group-save (widget)
3594 "Save all modified group members."
3595 (let ((children (widget-get widget
:children
)))
3596 (mapc (lambda (child)
3597 (when (memq (widget-get child
:custom-state
) '(modified set
))
3598 (widget-apply child
:custom-save
)))
3601 (defun custom-group-reset-current (widget)
3602 "Reset all modified group members."
3603 (let ((children (widget-get widget
:children
)))
3604 (mapc (lambda (child)
3605 (when (eq (widget-get child
:custom-state
) 'modified
)
3606 (widget-apply child
:custom-reset-current
)))
3609 (defun custom-group-reset-saved (widget)
3610 "Reset all modified or set group members."
3611 (let ((children (widget-get widget
:children
)))
3612 (mapc (lambda (child)
3613 (when (memq (widget-get child
:custom-state
) '(modified set
))
3614 (widget-apply child
:custom-reset-saved
)))
3617 (defun custom-group-reset-standard (widget)
3618 "Reset all modified, set, or saved group members."
3619 (let ((children (widget-get widget
:children
)))
3620 (mapc (lambda (child)
3621 (when (memq (widget-get child
:custom-state
)
3622 '(modified set saved
))
3623 (widget-apply child
:custom-reset-standard
)))
3626 (defun custom-group-state-update (widget)
3628 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
3629 (let* ((children (widget-get widget
:children
))
3630 (states (mapcar (lambda (child)
3631 (widget-get child
:custom-state
))
3633 (magics custom-magic-alist
)
3636 (let ((magic (car (car magics
))))
3637 (if (and (not (eq magic
'hidden
))
3638 (memq magic states
))
3641 (setq magics
(cdr magics
)))))
3642 (widget-put widget
:custom-state found
)))
3643 (custom-magic-reset widget
))
3645 ;;; The `custom-save-all' Function.
3647 (defcustom custom-file nil
3648 "File used for storing customization information.
3649 The default is nil, which means to use your init file
3650 as specified by `user-init-file'. If you specify some other file,
3651 you need to explicitly load that file for the settings to take effect.
3653 When you change this variable, look in the previous custom file
3654 \(usually your init file) for the forms `(custom-set-variables ...)'
3655 and `(custom-set-faces ...)', and copy them (whichever ones you find)
3656 to the new custom file. This will preserve your existing customizations."
3657 :type
'(choice (const :tag
"Your Emacs init file" nil
) file
)
3660 (defun custom-file ()
3661 "Return the file name for saving customizations."
3664 (let ((user-init-file user-init-file
)
3666 (if (eq system-type
'ms-dos
) "~/_emacs" "~/.emacs")))
3667 (when (null user-init-file
)
3668 (if (or (file-exists-p default-init-file
)
3669 (and (eq system-type
'windows-nt
)
3670 (file-exists-p "~/_emacs")))
3671 ;; Started with -q, i.e. the file containing
3672 ;; Custom settings hasn't been read. Saving
3673 ;; settings there would overwrite other settings.
3674 (error "Saving settings from \"emacs -q\" would overwrite existing customizations"))
3675 (setq user-init-file default-init-file
))
3678 (defun custom-save-delete (symbol)
3679 "Visit `custom-file' and delete all calls to SYMBOL from it.
3680 Leave point at the old location of the first such call,
3681 or (if there were none) at the end of the buffer."
3682 (let ((default-major-mode 'emacs-lisp-mode
))
3683 (set-buffer (find-file-noselect (custom-file))))
3684 (goto-char (point-min))
3685 ;; Skip all whitespace and comments.
3686 (while (forward-comment 1))
3688 (save-excursion (forward-sexp (buffer-size)))) ; Test for scan errors.
3691 (while t
;; We exit this loop only via throw.
3692 ;; Skip all whitespace and comments.
3693 (while (forward-comment 1))
3694 (let ((start (point))
3695 (sexp (condition-case nil
3696 (read (current-buffer))
3697 (end-of-file (throw 'found nil
)))))
3698 (when (and (listp sexp
)
3699 (eq (car sexp
) symbol
))
3700 (delete-region start
(point))
3702 (setq first
(point)))))))
3705 ;; Move in front of local variables, otherwise long Custom
3706 ;; entries would make them ineffective.
3707 (let ((pos (point-max))
3708 (case-fold-search t
))
3710 (goto-char (point-max))
3711 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
3713 (when (search-forward "Local Variables:" nil t
)
3714 (setq pos
(line-beginning-position))))
3717 (defun custom-save-variables ()
3718 "Save all customized variables in `custom-file'."
3720 (custom-save-delete 'custom-load-themes
)
3721 (custom-save-delete 'custom-reset-variables
)
3722 (custom-save-delete 'custom-set-variables
)
3723 (custom-save-loaded-themes)
3724 (custom-save-resets 'theme-value
'custom-reset-variables nil
)
3725 (let ((standard-output (current-buffer))
3726 (saved-list (make-list 1 0))
3728 ;; First create a sorted list of saved variables.
3731 (if (get symbol
'saved-value
)
3732 (nconc saved-list
(list symbol
)))))
3733 (setq saved-list
(sort (cdr saved-list
) 'string
<))
3736 (princ "(custom-set-variables
3737 ;; custom-set-variables was added by Custom.
3738 ;; If you edit it by hand, you could mess it up, so be careful.
3739 ;; Your init file should contain only one such instance.
3740 ;; If there is more than one, they won't work right.\n")
3741 (dolist (symbol saved-list
)
3742 (let ((spec (car-safe (get symbol
'theme-value
)))
3743 (value (get symbol
'saved-value
))
3744 (requests (get symbol
'custom-requests
))
3745 (now (not (or (custom-variable-p symbol
)
3746 (and (not (boundp symbol
))
3747 (not (eq (get symbol
'force-value
)
3749 (comment (get symbol
'saved-variable-comment
)))
3750 ;; Check `requests'.
3751 (dolist (request requests
)
3752 (when (and (symbolp request
) (not (featurep request
)))
3753 (message "Unknown requested feature: %s" request
)
3754 (setq requests
(delq request requests
))))
3756 (eq (nth 0 spec
) 'user
)
3757 (eq (nth 1 spec
) 'set
))
3759 (and (null spec
) (get symbol
'saved-value
)))
3766 (when (or now requests comment
)
3769 (when (or requests comment
)
3779 (unless (looking-at "\n")
3782 (defun custom-save-faces ()
3783 "Save all customized faces in `custom-file'."
3785 (custom-save-delete 'custom-reset-faces
)
3786 (custom-save-delete 'custom-set-faces
)
3787 (custom-save-resets 'theme-face
'custom-reset-faces
'(default))
3788 (let ((standard-output (current-buffer))
3789 (saved-list (make-list 1 0))
3791 ;; First create a sorted list of saved faces.
3794 (if (get symbol
'saved-face
)
3795 (nconc saved-list
(list symbol
)))))
3796 (setq saved-list
(sort (cdr saved-list
) 'string
<))
3797 ;; The default face must be first, since it affects the others.
3798 (if (memq 'default saved-list
)
3799 (setq saved-list
(cons 'default
(delq 'default saved-list
))))
3802 (princ "(custom-set-faces
3803 ;; custom-set-faces was added by Custom.
3804 ;; If you edit it by hand, you could mess it up, so be careful.
3805 ;; Your init file should contain only one such instance.
3806 ;; If there is more than one, they won't work right.\n")
3807 (dolist (symbol saved-list
)
3808 (let ((spec (car-safe (get symbol
'theme-face
)))
3809 (value (get symbol
'saved-face
))
3810 (now (not (or (get symbol
'face-defface-spec
)
3811 (and (not (custom-facep symbol
))
3812 (not (get symbol
'force-face
))))))
3813 (comment (get symbol
'saved-face-comment
)))
3815 (eq (nth 0 spec
) 'user
)
3816 (eq (nth 1 spec
) 'set
))
3818 (and (null spec
) (get symbol
'saved-face
)))
3819 ;; Don't print default face here.
3826 (when (or now comment
)
3836 (unless (looking-at "\n")
3839 (defun custom-save-resets (property setter special
)
3840 (let (started-writing ignored-special
)
3841 ;; (custom-save-delete setter) Done by caller
3842 (let ((standard-output (current-buffer))
3843 (mapper `(lambda (object)
3844 (let ((spec (car-safe (get object
(quote ,property
)))))
3845 (when (and (not (memq object ignored-special
))
3846 (eq (nth 0 spec
) 'user
)
3847 (eq (nth 1 spec
) 'reset
))
3848 ;; Do not write reset statements unless necessary.
3849 (unless started-writing
3850 (setq started-writing t
)
3854 (princ (quote ,setter
))
3858 (prin1 (nth 3 spec
))
3860 (mapc mapper special
)
3861 (setq ignored-special special
)
3863 (when started-writing
3866 (defun custom-save-loaded-themes ()
3867 (let ((themes (reverse (get 'user
'theme-loads-themes
)))
3868 (standard-output (current-buffer)))
3870 (unless (bolp) (princ "\n"))
3871 (princ "(custom-load-themes")
3872 (mapc (lambda (theme)
3874 (prin1 theme
)) themes
)
3878 (defun customize-save-customized ()
3879 "Save all user options which have been set in this session."
3881 (mapatoms (lambda (symbol)
3882 (let ((face (get symbol
'customized-face
))
3883 (value (get symbol
'customized-value
))
3884 (face-comment (get symbol
'customized-face-comment
))
3886 (get symbol
'customized-variable-comment
)))
3888 (put symbol
'saved-face face
)
3889 (custom-push-theme 'theme-face symbol
'user
'set value
)
3890 (put symbol
'customized-face nil
))
3892 (put symbol
'saved-value value
)
3893 (custom-push-theme 'theme-value symbol
'user
'set value
)
3894 (put symbol
'customized-value nil
))
3895 (when variable-comment
3896 (put symbol
'saved-variable-comment variable-comment
)
3897 (put symbol
'customized-variable-comment nil
))
3899 (put symbol
'saved-face-comment face-comment
)
3900 (put symbol
'customized-face-comment nil
)))))
3901 ;; We really should update all custom buffers here.
3905 (defun custom-save-all ()
3906 "Save all customizations in `custom-file'."
3907 (let ((inhibit-read-only t
))
3908 (custom-save-variables)
3911 (let ((default-major-mode nil
))
3912 (set-buffer (find-file-noselect (custom-file))))
3913 (let ((file-precious-flag t
))
3916 ;;; The Customize Menu.
3920 (defcustom custom-menu-nesting
2
3921 "Maximum nesting in custom menus."
3923 :group
'custom-menu
)
3925 (defun custom-face-menu-create (widget symbol
)
3926 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
3927 (vector (custom-unlispify-menu-entry symbol
)
3928 `(customize-face ',symbol
)
3931 (defun custom-variable-menu-create (widget symbol
)
3932 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
3933 (let ((type (get symbol
'custom-type
)))
3934 (unless (listp type
)
3935 (setq type
(list type
)))
3936 (if (and type
(widget-get type
:custom-menu
))
3937 (widget-apply type
:custom-menu symbol
)
3938 (vector (custom-unlispify-menu-entry symbol
)
3939 `(customize-variable ',symbol
)
3942 ;; Add checkboxes to boolean variable entries.
3943 (widget-put (get 'boolean
'widget-type
)
3944 :custom-menu
(lambda (widget symbol
)
3945 (vector (custom-unlispify-menu-entry symbol
)
3946 `(customize-variable ',symbol
)
3948 ':selected symbol
)))
3950 (defun custom-group-menu-create (widget symbol
)
3951 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
3952 `( ,(custom-unlispify-menu-entry symbol t
)
3953 :filter
(lambda (&rest junk
)
3954 (let ((menu (custom-menu-create ',symbol
)))
3955 (if (consp menu
) (cdr menu
) menu
)))))
3958 (defun custom-menu-create (symbol)
3959 "Create menu for customization group SYMBOL.
3960 The menu is in a format applicable to `easy-menu-define'."
3961 (let* ((item (vector (custom-unlispify-menu-entry symbol
)
3962 `(customize-group ',symbol
)
3964 (if (and (or (not (boundp 'custom-menu-nesting
))
3965 (>= custom-menu-nesting
0))
3967 (custom-load-symbol symbol
)
3968 (< (length (get symbol
'custom-group
)) widget-menu-max-size
)))
3969 (let ((custom-prefix-list (custom-prefix-add symbol
3970 custom-prefix-list
))
3971 (members (custom-sort-items (get symbol
'custom-group
)
3972 custom-menu-sort-alphabetically
3973 custom-menu-order-groups
)))
3974 `(,(custom-unlispify-menu-entry symbol t
)
3977 ,@(mapcar (lambda (entry)
3978 (widget-apply (if (listp (nth 1 entry
))
3980 (list (nth 1 entry
)))
3981 :custom-menu
(nth 0 entry
)))
3986 (defun customize-menu-create (symbol &optional name
)
3987 "Return a customize menu for customization group SYMBOL.
3988 If optional NAME is given, use that as the name of the menu.
3989 Otherwise the menu will be named `Customize'.
3990 The format is suitable for use with `easy-menu-define'."
3992 (setq name
"Customize"))
3994 :filter
(lambda (&rest junk
)
3995 (let ((menu (custom-menu-create ',symbol
)))
3996 (if (consp menu
) (cdr menu
) menu
)))))
3998 ;;; The Custom Mode.
4000 (defvar custom-mode-map nil
4001 "Keymap for `custom-mode'.")
4003 (unless custom-mode-map
4004 ;; This keymap should be dense, but a dense keymap would prevent inheriting
4005 ;; "\r" bindings from the parent map.
4006 (setq custom-mode-map
(make-sparse-keymap))
4007 (set-keymap-parent custom-mode-map widget-keymap
)
4008 (suppress-keymap custom-mode-map
)
4009 (define-key custom-mode-map
" " 'scroll-up
)
4010 (define-key custom-mode-map
"\177" 'scroll-down
)
4011 (define-key custom-mode-map
"q" 'Custom-buffer-done
)
4012 (define-key custom-mode-map
"u" 'Custom-goto-parent
)
4013 (define-key custom-mode-map
"n" 'widget-forward
)
4014 (define-key custom-mode-map
"p" 'widget-backward
)
4015 (define-key custom-mode-map
[mouse-1
] 'Custom-move-and-invoke
))
4017 (defun Custom-move-and-invoke (event)
4018 "Move to where you click, and if it is an active field, invoke it."
4020 (mouse-set-point event
)
4021 (if (widget-event-point event
)
4022 (let* ((pos (widget-event-point event
))
4023 (button (get-char-property pos
'button
)))
4025 (widget-button-click event
)))))
4027 (easy-menu-define Custom-mode-menu
4029 "Menu used in customization buffers."
4031 ,(customize-menu-create 'customize
)
4032 ["Set" Custom-set t
]
4033 ["Save" Custom-save t
]
4034 ["Reset to Current" Custom-reset-current t
]
4035 ["Reset to Saved" Custom-reset-saved t
]
4036 ["Reset to Standard Settings" Custom-reset-standard t
]
4037 ["Info" (Info-goto-node "(emacs)Easy Customization") t
]))
4039 (defun Custom-goto-parent ()
4040 "Go to the parent group listed at the top of this buffer.
4041 If several parents are listed, go to the first of them."
4044 (goto-char (point-min))
4045 (if (search-forward "\nGo to parent group: " nil t
)
4046 (let* ((button (get-char-property (point) 'button
))
4047 (parent (downcase (widget-get button
:tag
))))
4048 (customize-group parent
)))))
4050 (defcustom custom-mode-hook nil
4051 "Hook called when entering Custom mode."
4053 :group
'custom-buffer
)
4055 (defun custom-state-buffer-message (widget)
4056 (if (eq (widget-get (widget-get widget
:parent
) :custom-state
) 'modified
)
4057 (message "To install your edits, invoke [State] and choose the Set operation")))
4059 (defun custom-mode ()
4060 "Major mode for editing customization buffers.
4062 The following commands are available:
4064 Move to next button or editable field. \\[widget-forward]
4065 Move to previous button or editable field. \\[widget-backward]
4066 \\<widget-field-keymap>\
4067 Complete content of editable text field. \\[widget-complete]
4068 \\<custom-mode-map>\
4069 Invoke button under the mouse pointer. \\[Custom-move-and-invoke]
4070 Invoke button under point. \\[widget-button-press]
4071 Set all modifications. \\[Custom-set]
4072 Make all modifications default. \\[Custom-save]
4073 Reset all modified options. \\[Custom-reset-current]
4074 Reset all modified or set options. \\[Custom-reset-saved]
4075 Reset all options. \\[Custom-reset-standard]
4077 Entry to this mode calls the value of `custom-mode-hook'
4078 if that value is non-nil."
4079 (kill-all-local-variables)
4080 (setq major-mode
'custom-mode
4082 (use-local-map custom-mode-map
)
4083 (easy-menu-add Custom-mode-menu
)
4084 (make-local-variable 'custom-options
)
4085 (make-local-variable 'custom-local-buffer
)
4086 (make-local-variable 'widget-documentation-face
)
4087 (setq widget-documentation-face
'custom-documentation-face
)
4088 (make-local-variable 'widget-button-face
)
4089 (setq widget-button-face
'custom-button-face
)
4090 (set (make-local-variable 'widget-button-pressed-face
)
4091 'custom-button-pressed-face
)
4092 (set (make-local-variable 'widget-mouse-face
)
4093 'custom-button-pressed-face
) ; buttons `depress' when moused
4094 ;; When possible, use relief for buttons, not bracketing. This test
4095 ;; may not be optimal.
4096 (when custom-raised-buttons
4097 (set (make-local-variable 'widget-push-button-prefix
) "")
4098 (set (make-local-variable 'widget-push-button-suffix
) "")
4099 (set (make-local-variable 'widget-link-prefix
) "")
4100 (set (make-local-variable 'widget-link-suffix
) ""))
4101 (add-hook 'widget-edit-functions
'custom-state-buffer-message nil t
)
4102 (run-hooks 'custom-mode-hook
))
4104 (put 'custom-mode
'mode-class
'special
)
4107 'debug-ignored-errors
4108 "^No user options have changed defaults in recent Emacs versions$")
4114 ;;; cus-edit.el ends here