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."
77 :link
'(custom-manual "(emacs)Emulation")
84 (defgroup outlines nil
85 "Support for hierarchical outlining."
88 (defgroup external nil
89 "Interfacing to external utilities."
92 (defgroup processes nil
93 "Process, subshell, compilation, and job control support."
97 (defgroup convenience nil
98 "Convenience features for faster editing."
101 (defgroup programming nil
102 "Support for programming in other languages."
105 (defgroup languages nil
106 "Specialized modes for editing programming languages."
110 "Lisp support, including Emacs Lisp."
115 "Support for the C language and related languages."
116 :link
'(custom-manual "(ccmode)")
124 "Support for object-oriented programming."
127 (defgroup applications nil
128 "Applications written in Emacs."
131 (defgroup calendar nil
132 "Calendar and time management support."
133 :group
'applications
)
136 "Modes for electronic-mail handling."
137 :group
'applications
)
140 "Support for netnews reading and posting."
141 :link
'(custom-manual "(gnus)")
142 :group
'applications
)
145 "Games, jokes and amusements."
146 :group
'applications
)
148 (defgroup development nil
149 "Support for further development of Emacs."
153 "Support for Emacs documentation."
156 (defgroup extensions nil
157 "Emacs Lisp language extensions."
160 (defgroup internal nil
161 "Code for Emacs internals, build process, defaults."
165 "Maintenance aids for the Emacs development group."
169 (defgroup environment nil
170 "Fitting Emacs with its environment."
174 "Communications, networking, remote access to files."
178 (defgroup hardware nil
179 "Support for interfacing with exotic hardware."
182 (defgroup terminals nil
183 "Support for terminal types."
187 "Front-ends/assistants for, or emulators of, UNIX features."
191 "Support code for vms."
195 "Internationalization and alternate character-set support."
196 :link
'(custom-manual "(emacs)International")
201 "The X Window system."
205 "Support for Emacs frames and window systems."
209 "Support editing files of data."
213 "Support editing files."
221 "Code related to the TeX formatter."
225 "Support for multiple fonts."
228 (defgroup hypermedia nil
229 "Support for links between text or other media types."
233 "Support for on-line help systems."
236 (defgroup multimedia nil
237 "Non-textual support, specifically images and sound."
241 "Code local to your site."
244 (defgroup customize
'((widgets custom-group
))
245 "Customization of the Customization support."
246 :link
'(custom-manual "(elisp)Customization")
250 (defgroup custom-faces nil
251 "Faces used by customize."
255 (defgroup custom-browse nil
256 "Control customize browser."
260 (defgroup custom-buffer nil
261 "Control customize buffers."
265 (defgroup custom-menu nil
266 "Control customize menus."
270 (defgroup abbrev-mode nil
271 "Word abbreviations mode."
272 :link
'(custom-manual "(emacs)Abbrevs")
276 "Storage allocation and gc for GNU Emacs Lisp interpreter."
277 :tag
"Storage Allocation"
281 "Undoing changes in buffers."
282 :link
'(custom-manual "(emacs)Undo")
285 (defgroup modeline nil
286 "Content of the modeline."
290 "Indenting and filling text."
291 :link
'(custom-manual "(emacs)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."
324 :link
'(custom-manual "(emacs)Minibuffer")
327 (defgroup keyboard nil
328 "Input from the keyboard."
332 "Input from the mouse."
336 "Input from the menus."
339 (defgroup auto-save nil
340 "Preventing accidential loss of data."
343 (defgroup processes-basics nil
344 "Basic stuff dealing with processes."
348 "MULE Emacs internationalization."
351 (defgroup windows nil
352 "Windows within a frame."
353 :link
'(custom-manual "(emacs)Windows")
358 (defun custom-quote (sexp)
359 "Quote SEXP iff it is not self quoting."
360 (if (or (memq sexp
'(t nil
))
363 (memq (car sexp
) '(lambda)))
367 ;;; (and (fboundp 'characterp)
368 ;;; (characterp sexp))
373 (defun custom-split-regexp-maybe (regexp)
374 "If REGEXP is a string, split it to a list at `\\|'.
375 You can get the original back with from the result with:
376 (mapconcat 'identity result \"\\|\")
378 IF REGEXP is not a string, return it unchanged."
382 (while (string-match "\\\\|" regexp start
)
383 (setq all
(cons (substring regexp start
(match-beginning 0)) all
)
384 start
(match-end 0)))
385 (nreverse (cons (substring regexp start
) all
)))
388 (defun custom-variable-prompt ()
389 "Prompt for a custom variable, defaulting to the variable at point.
390 Return a list suitable for use in `interactive'."
391 (let ((v (variable-at-point))
392 (enable-recursive-minibuffers t
)
394 (setq val
(completing-read
395 (if (and (symbolp v
) (custom-variable-p v
))
396 (format "Customize option: (default %s) " v
)
397 "Customize option: ")
398 obarray
'custom-variable-p t
))
399 (list (if (equal val
"")
400 (if (symbolp v
) v nil
)
403 (defun custom-menu-filter (menu widget
)
404 "Convert MENU to the form used by `widget-choose'.
405 MENU should be in the same format as `custom-variable-menu'.
406 WIDGET is the widget to apply the filter entries of MENU on."
408 current name action filter
)
410 (setq current
(car menu
)
412 action
(nth 1 current
)
413 filter
(nth 2 current
)
415 (if (or (null filter
) (funcall filter widget
))
416 (push (cons name action
) result
)
422 (defvar custom-prefix-list nil
423 "List of prefixes that should be ignored by `custom-unlispify'.")
425 (defcustom custom-unlispify-menu-entries t
426 "Display menu entries as words instead of symbols if non nil."
430 (defcustom custom-unlispify-remove-prefixes nil
431 "Non-nil means remove group prefixes from option names in buffer."
433 :group
'custom-buffer
436 (defun custom-unlispify-menu-entry (symbol &optional no-suffix
)
437 "Convert SYMBOL into a menu entry."
438 (cond ((not custom-unlispify-menu-entries
)
439 (symbol-name symbol
))
440 ((get symbol
'custom-tag
)
442 (get symbol
'custom-tag
)
443 (concat (get symbol
'custom-tag
) "...")))
445 (with-current-buffer (get-buffer-create " *Custom-Work*")
447 (princ symbol
(current-buffer))
448 (goto-char (point-min))
449 ;; FIXME: Boolean variables are not predicates, so they shouldn't
450 ;; end with `-p'. -stef
451 ;; (when (and (eq (get symbol 'custom-type) 'boolean)
452 ;; (re-search-forward "-p\\'" nil t))
453 ;; (replace-match "" t t)
454 ;; (goto-char (point-min)))
455 (if custom-unlispify-remove-prefixes
456 (let ((prefixes custom-prefix-list
)
459 (setq prefix
(car prefixes
))
460 (if (search-forward prefix
(+ (point) (length prefix
)) t
)
463 (delete-region (point-min) (point)))
464 (setq prefixes
(cdr prefixes
))))))
465 (subst-char-in-region (point-min) (point-max) ?- ?\ t
)
466 (capitalize-region (point-min) (point-max))
468 (goto-char (point-max))
472 (defcustom custom-unlispify-tag-names t
473 "Display tag names as words instead of symbols if non nil."
474 :group
'custom-buffer
477 (defun custom-unlispify-tag-name (symbol)
478 "Convert SYMBOL into a menu entry."
479 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names
))
480 (custom-unlispify-menu-entry symbol t
)))
482 (defun custom-prefix-add (symbol prefixes
)
483 "Add SYMBOL to list of ignored PREFIXES."
484 (cons (or (get symbol
'custom-prefix
)
485 (concat (symbol-name symbol
) "-"))
490 (defcustom custom-guess-name-alist
495 ("-function\\'" function
)
496 ("-functions\\'" (repeat function
))
497 ("-list\\'" (repeat sexp
))
498 ("-alist\\'" (repeat (cons sexp sexp
))))
499 "Alist of (MATCH TYPE).
501 MATCH should be a regexp matching the name of a symbol, and TYPE should
502 be a widget suitable for editing the value of that symbol. The TYPE
503 of the first entry where MATCH matches the name of the symbol will be
506 This is used for guessing the type of variables not declared with
508 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
511 (defcustom custom-guess-doc-alist
512 '(("\\`\\*?Non-nil " boolean
))
513 "Alist of (MATCH TYPE).
515 MATCH should be a regexp matching a documentation string, and TYPE
516 should be a widget suitable for editing the value of a variable with
517 that documentation string. The TYPE of the first entry where MATCH
518 matches the name of the symbol will be used.
520 This is used for guessing the type of variables not declared with
522 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
525 (defun custom-guess-type (symbol)
526 "Guess a widget suitable for editing the value of SYMBOL.
527 This is done by matching SYMBOL with `custom-guess-name-alist' and
528 if that fails, the doc string with `custom-guess-doc-alist'."
529 (let ((name (symbol-name symbol
))
530 (names custom-guess-name-alist
)
533 (setq current
(car names
)
535 (when (string-match (nth 0 current
) name
)
536 (setq found
(nth 1 current
)
539 (let ((doc (documentation-property symbol
'variable-documentation
))
540 (docs custom-guess-doc-alist
))
543 (setq current
(car docs
)
545 (when (string-match (nth 0 current
) doc
)
546 (setq found
(nth 1 current
)
552 (defcustom custom-browse-sort-alphabetically nil
553 "If non-nil, sort members of each customization group alphabetically."
555 :group
'custom-browse
)
557 (defcustom custom-browse-order-groups nil
558 "If non-nil, order group members within each customization group.
559 If `first', order groups before non-groups.
560 If `last', order groups after non-groups."
561 :type
'(choice (const first
)
563 (const :tag
"none" nil
))
564 :group
'custom-browse
)
566 (defcustom custom-browse-only-groups nil
567 "If non-nil, show group members only within each customization group."
569 :group
'custom-browse
)
571 (defcustom custom-buffer-sort-alphabetically nil
572 "If non-nil, sort members of each customization group alphabetically."
574 :group
'custom-buffer
)
576 (defcustom custom-buffer-order-groups
'last
577 "If non-nil, order group members within each customization group.
578 If `first', order groups before non-groups.
579 If `last', order groups after non-groups."
580 :type
'(choice (const first
)
582 (const :tag
"none" nil
))
583 :group
'custom-buffer
)
585 (defcustom custom-menu-sort-alphabetically nil
586 "If non-nil, sort members of each customization group alphabetically."
590 (defcustom custom-menu-order-groups
'first
591 "If non-nil, order group members within each customization group.
592 If `first', order groups before non-groups.
593 If `last', order groups after non-groups."
594 :type
'(choice (const first
)
596 (const :tag
"none" nil
))
599 ;;;###autoload (add-hook 'same-window-regexps "\\`\\*Customiz.*\\*\\'")
601 (defun custom-sort-items (items sort-alphabetically order-groups
)
602 "Return a sorted copy of ITEMS.
603 ITEMS should be a `custom-group' property.
604 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
605 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
606 groups after non-groups, if nil do not order groups at all."
607 (sort (copy-sequence items
)
609 (let ((typea (nth 1 a
)) (typeb (nth 1 b
))
610 (namea (nth 0 a
)) (nameb (nth 0 b
)))
611 (cond ((not order-groups
)
612 ;; Since we don't care about A and B order, maybe sort.
613 (when sort-alphabetically
614 (string-lessp namea nameb
)))
615 ((eq typea
'custom-group
)
616 ;; If B is also a group, maybe sort. Otherwise, order A and B.
617 (if (eq typeb
'custom-group
)
618 (when sort-alphabetically
619 (string-lessp namea nameb
))
620 (eq order-groups
'first
)))
621 ((eq typeb
'custom-group
)
622 ;; Since A cannot be a group, order A and B.
623 (eq order-groups
'last
))
625 ;; Since A and B cannot be groups, sort.
626 (string-lessp namea nameb
)))))))
628 ;;; Custom Mode Commands.
630 (defvar custom-options nil
631 "Customization widgets in the current buffer.")
634 "Set changes in all modified options."
636 (let ((children custom-options
))
637 (mapc (lambda (child)
638 (when (eq (widget-get child
:custom-state
) 'modified
)
639 (widget-apply child
:custom-set
)))
642 (defun Custom-save ()
643 "Set all modified group members and save them."
645 (let ((children custom-options
))
646 (mapc (lambda (child)
647 (when (memq (widget-get child
:custom-state
)
648 '(modified set changed rogue
))
649 (widget-apply child
:custom-save
)))
653 (defvar custom-reset-menu
654 '(("Current" . Custom-reset-current
)
655 ("Saved" . Custom-reset-saved
)
656 ("Erase Customization (use standard settings)" . Custom-reset-standard
))
657 "Alist of actions for the `Reset' button.
658 The key is a string containing the name of the action, the value is a
659 Lisp function taking the widget as an element which will be called
660 when the action is chosen.")
662 (defun custom-reset (event)
663 "Select item from reset menu."
664 (let* ((completion-ignore-case t
)
665 (answer (widget-choose "Reset to"
671 (defun Custom-reset-current (&rest ignore
)
672 "Reset all modified group members to their current value."
674 (let ((children custom-options
))
675 (mapc (lambda (widget)
676 (if (memq (widget-get widget
:custom-state
)
678 (widget-apply widget
:custom-reset-current
)))
681 (defun Custom-reset-saved (&rest ignore
)
682 "Reset all modified or set group members to their saved value."
684 (let ((children custom-options
))
685 (mapc (lambda (widget)
686 (if (memq (widget-get widget
:custom-state
)
687 '(modified set changed rogue
))
688 (widget-apply widget
:custom-reset-saved
)))
691 (defun Custom-reset-standard (&rest ignore
)
692 "Erase all customization (either current or saved) for the group members.
693 The immediate result is to restore them to their standard settings.
694 This operation eliminates any saved settings for the group members,
695 making them as if they had never been customized at all."
697 (let ((children custom-options
))
698 (mapc (lambda (widget)
699 (and (widget-apply widget
:custom-standard-value
)
700 (if (memq (widget-get widget
:custom-state
)
701 '(modified set changed saved rogue
))
702 (widget-apply widget
:custom-reset-standard
))))
705 ;;; The Customize Commands
707 (defun custom-prompt-variable (prompt-var prompt-val
&optional comment
)
708 "Prompt for a variable and a value and return them as a list.
709 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
710 prompt for the value. The %s escape in PROMPT-VAL is replaced with
711 the name of the variable.
713 If the variable has a `variable-interactive' property, that is used as if
714 it were the arg to `interactive' (which see) to interactively read the value.
716 If the variable has a `custom-type' property, it must be a widget and the
717 `:prompt-value' property of that widget will be used for reading the value.
719 If optional COMMENT argument is non nil, also prompt for a comment and return
720 it as the third element in the list."
721 (let* ((var (read-variable prompt-var
))
722 (minibuffer-help-form '(describe-variable var
))
724 (let ((prop (get var
'variable-interactive
))
725 (type (get var
'custom-type
))
726 (prompt (format prompt-val var
)))
728 (setq type
(list type
)))
730 ;; Use VAR's `variable-interactive' property
731 ;; as an interactive spec for prompting.
732 (call-interactively (list 'lambda
'(arg)
733 (list 'interactive prop
)
736 (widget-prompt-value type
742 (eval-minibuffer prompt
))))))
745 (read-string "Comment: " (get var
'variable-comment
)))
749 (defun customize-set-value (variable value
&optional comment
)
750 "Set VARIABLE to VALUE, and return VALUE. VALUE is a Lisp object.
752 If VARIABLE has a `variable-interactive' property, that is used as if
753 it were the arg to `interactive' (which see) to interactively read the value.
755 If VARIABLE has a `custom-type' property, it must be a widget and the
756 `:prompt-value' property of that widget will be used for reading the value.
758 If given a prefix (or a COMMENT argument), also prompt for a comment."
759 (interactive (custom-prompt-variable "Set variable: "
763 (cond ((string= comment
"")
764 (put variable
'variable-comment nil
))
766 (put variable
'variable-comment comment
)))
767 (set variable value
))
770 (defun customize-set-variable (variable value
&optional comment
)
771 "Set the default for VARIABLE to VALUE, and return VALUE.
772 VALUE is a Lisp object.
774 If VARIABLE has a `custom-set' property, that is used for setting
775 VARIABLE, otherwise `set-default' is used.
777 The `customized-value' property of the VARIABLE will be set to a list
778 with a quoted VALUE as its sole list member.
780 If VARIABLE has a `variable-interactive' property, that is used as if
781 it were the arg to `interactive' (which see) to interactively read the value.
783 If VARIABLE has a `custom-type' property, it must be a widget and the
784 `:prompt-value' property of that widget will be used for reading the value.
786 If given a prefix (or a COMMENT argument), also prompt for a comment."
787 (interactive (custom-prompt-variable "Set variable: "
788 "Set customized value for %s to: "
790 (custom-load-symbol variable
)
791 (funcall (or (get variable
'custom-set
) 'set-default
) variable value
)
792 (put variable
'customized-value
(list (custom-quote value
)))
793 (cond ((string= comment
"")
794 (put variable
'variable-comment nil
)
795 (put variable
'customized-variable-comment nil
))
797 (put variable
'variable-comment comment
)
798 (put variable
'customized-variable-comment comment
)))
802 (defun customize-save-variable (variable value
&optional comment
)
803 "Set the default for VARIABLE to VALUE, and save it for future sessions.
806 If VARIABLE has a `custom-set' property, that is used for setting
807 VARIABLE, otherwise `set-default' is used.
809 The `customized-value' property of the VARIABLE will be set to a list
810 with a quoted VALUE as its sole list member.
812 If VARIABLE has a `variable-interactive' property, that is used as if
813 it were the arg to `interactive' (which see) to interactively read the value.
815 If VARIABLE has a `custom-type' property, it must be a widget and the
816 `:prompt-value' property of that widget will be used for reading the value.
818 If given a prefix (or a COMMENT argument), also prompt for a comment."
819 (interactive (custom-prompt-variable "Set and save variable: "
820 "Set and save value for %s as: "
822 (funcall (or (get variable
'custom-set
) 'set-default
) variable value
)
823 (put variable
'saved-value
(list (custom-quote value
)))
824 (custom-push-theme 'theme-value variable
'user
'set
(list (custom-quote value
)))
825 (cond ((string= comment
"")
826 (put variable
'variable-comment nil
)
827 (put variable
'saved-variable-comment nil
))
829 (put variable
'variable-comment comment
)
830 (put variable
'saved-variable-comment comment
)))
836 "Select a customization buffer which you can use to set user options.
837 User options are structured into \"groups\".
838 Initially the top-level group `Emacs' and its immediate subgroups
839 are shown; the contents of those subgroups are initially hidden."
841 (customize-group 'emacs
))
844 (defun customize-mode (mode)
845 "Customize options related to the current major mode.
846 If a prefix \\[universal-argument] was given (or if the current major mode has no known group),
847 then prompt for the MODE to customize."
850 (let ((completion-regexp-list '("-mode\\'"))
851 (group (custom-group-of-mode major-mode
)))
852 (if (and group
(not current-prefix-arg
))
855 (completing-read (if group
856 (format "Major mode (default %s): " major-mode
)
859 'custom-group-of-mode
860 t nil nil
(if group
(symbol-name major-mode
))))))))
861 (customize-group (custom-group-of-mode mode
)))
865 (defun customize-group (group)
866 "Customize GROUP, which must be a customization group."
867 (interactive (list (let ((completion-ignore-case t
))
868 (completing-read "Customize group: (default emacs) "
871 (or (get symbol
'custom-loads
)
872 (get symbol
'custom-group
)))
874 (when (stringp group
)
875 (if (string-equal "" group
)
877 (setq group
(intern group
))))
878 (let ((name (format "*Customize Group: %s*"
879 (custom-unlispify-tag-name group
))))
880 (if (get-buffer name
)
882 (custom-buffer-create (list (list group
'custom-group
))
884 (concat " for group "
885 (custom-unlispify-tag-name group
))))))
888 (defun customize-group-other-window (group)
889 "Customize GROUP, which must be a customization group."
890 (interactive (list (let ((completion-ignore-case t
))
891 (completing-read "Customize group: (default emacs) "
894 (or (get symbol
'custom-loads
)
895 (get symbol
'custom-group
)))
897 (when (stringp group
)
898 (if (string-equal "" group
)
900 (setq group
(intern group
))))
901 (let ((name (format "*Customize Group: %s*"
902 (custom-unlispify-tag-name group
))))
903 (if (get-buffer name
)
904 (let ((window (selected-window))
905 ;; Copied from `custom-buffer-create-other-window'.
907 (special-display-buffer-names nil
)
908 (special-display-regexps nil
)
909 (same-window-buffer-names nil
)
910 (same-window-regexps nil
))
912 (select-window window
))
913 (custom-buffer-create-other-window
914 (list (list group
'custom-group
))
916 (concat " for group "
917 (custom-unlispify-tag-name group
))))))
920 (defalias 'customize-variable
'customize-option
)
923 (defun customize-option (symbol)
924 "Customize SYMBOL, which must be a user option variable."
925 (interactive (custom-variable-prompt))
926 (custom-buffer-create (list (list symbol
'custom-variable
))
927 (format "*Customize Option: %s*"
928 (custom-unlispify-tag-name symbol
))))
931 (defalias 'customize-variable-other-window
'customize-option-other-window
)
934 (defun customize-option-other-window (symbol)
935 "Customize SYMBOL, which must be a user option variable.
936 Show the buffer in another window, but don't select it."
937 (interactive (custom-variable-prompt))
938 (custom-buffer-create-other-window
939 (list (list symbol
'custom-variable
))
940 (format "*Customize Option: %s*" (custom-unlispify-tag-name symbol
))))
942 (defvar customize-changed-options-previous-release
"20.2"
943 "Version for `customize-changed-options' to refer back to by default.")
946 (defun customize-changed-options (since-version)
947 "Customize all user option variables changed in Emacs itself.
948 This includes new user option variables and faces, and new
949 customization groups, as well as older options and faces whose default
950 values have changed since the previous major Emacs release.
952 With argument SINCE-VERSION (a string), customize all user option
953 variables that were added (or their meanings were changed) since that
956 (interactive "sCustomize options changed, since version (default all versions): ")
957 (if (equal since-version
"")
958 (setq since-version nil
)
959 (unless (condition-case nil
960 (numberp (read since-version
))
962 (signal 'wrong-type-argument
(list 'numberp since-version
))))
963 (unless since-version
964 (setq since-version customize-changed-options-previous-release
))
966 ;; Load the information for versions since since-version. We use
967 ;; custom-load-symbol for this.
968 (put 'custom-versions-load-alist
'custom-loads nil
)
969 (dolist (elt custom-versions-load-alist
)
970 (if (customize-version-lessp since-version
(car elt
))
971 (dolist (load (cdr elt
))
972 (custom-add-load 'custom-versions-load-alist load
))))
973 (custom-load-symbol 'custom-versions-load-alist
)
974 (put 'custom-versions-load-alist
'custom-loads nil
)
979 (let ((version (get symbol
'custom-version
)))
981 (when (customize-version-lessp since-version version
)
982 (if (or (get symbol
'custom-group
)
983 (get symbol
'group-documentation
))
984 (push (list symbol
'custom-group
) found
))
985 (if (custom-variable-p symbol
)
986 (push (list symbol
'custom-variable
) found
))
987 (if (custom-facep symbol
)
988 (push (list symbol
'custom-face
) found
)))))))
990 (custom-buffer-create (custom-sort-items found t
'first
)
991 "*Customize Changed Options*")
992 (error "No user option defaults have been changed since Emacs %s"
995 (defun customize-version-lessp (version1 version2
)
996 ;; Why are the versions strings, and given that they are, why aren't
997 ;; they converted to numbers and compared as such here? -- fx
999 ;; In case someone made a mistake and left out the quotes
1000 ;; in the :version value.
1001 (if (numberp version2
)
1002 (setq version2
(prin1-to-string version2
)))
1003 (let (major1 major2 minor1 minor2
)
1004 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version1
)
1005 (setq major1
(read (or (match-string 1 version1
)
1007 (setq minor1
(read (or (match-string 3 version1
)
1009 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version2
)
1010 (setq major2
(read (or (match-string 1 version2
)
1012 (setq minor2
(read (or (match-string 3 version2
)
1014 (or (< major1 major2
)
1015 (and (= major1 major2
)
1016 (< minor1 minor2
)))))
1019 (defun customize-face (&optional face
)
1020 "Customize SYMBOL, which should be a face name or nil.
1021 If SYMBOL is nil, customize all faces.
1023 Interactively, when point is on text which has a face specified,
1024 suggest to customized that face, if it's customizable."
1026 (list (read-face-name "Customize face" "all faces" t
)))
1027 (if (member face
'(nil ""))
1028 (setq face
(face-list)))
1029 (if (and (listp face
) (null (cdr face
)))
1030 (setq face
(car face
)))
1032 (custom-buffer-create (custom-sort-items
1034 (list s
'custom-face
))
1037 "*Customize Faces*")
1038 (unless (facep face
)
1039 (error "Invalid face %S" face
))
1040 (custom-buffer-create (list (list face
'custom-face
))
1041 (format "*Customize Face: %s*"
1042 (custom-unlispify-tag-name face
)))))
1045 (defun customize-face-other-window (&optional face
)
1046 "Show customization buffer for face SYMBOL in other window.
1048 Interactively, when point is on text which has a face specified,
1049 suggest to customized that face, if it's customizable."
1051 (list (read-face-name "Customize face" "all faces" t
)))
1052 (if (member face
'(nil ""))
1053 (setq face
(face-list)))
1054 (if (and (listp face
) (null (cdr face
)))
1055 (setq face
(car face
)))
1057 (custom-buffer-create-other-window
1060 (list s
'custom-face
))
1063 "*Customize Faces*")
1064 (unless (facep face
)
1065 (error "Invalid face %S" face
))
1066 (custom-buffer-create-other-window
1067 (list (list face
'custom-face
))
1068 (format "*Customize Face: %s*"
1069 (custom-unlispify-tag-name face
)))))
1072 (defun customize-customized ()
1073 "Customize all user options set since the last save in this session."
1076 (mapatoms (lambda (symbol)
1077 (and (or (get symbol
'customized-face
)
1078 (get symbol
'customized-face-comment
))
1079 (custom-facep symbol
)
1080 (push (list symbol
'custom-face
) found
))
1081 (and (or (get symbol
'customized-value
)
1082 (get symbol
'customized-variable-comment
))
1084 (push (list symbol
'custom-variable
) found
))))
1086 (error "No customized user options")
1087 (custom-buffer-create (custom-sort-items found t nil
)
1088 "*Customize Customized*"))))
1091 (defun customize-rogue ()
1092 "Customize all user variable modified outside customize."
1095 (mapatoms (lambda (symbol)
1096 (let ((cval (or (get symbol
'customized-value
)
1097 (get symbol
'saved-value
)
1098 (get symbol
'standard-value
))))
1099 (when (and cval
;Declared with defcustom.
1100 (default-boundp symbol
) ;Has a value.
1101 (not (equal (eval (car cval
))
1102 ;; Which does not match customize.
1103 (default-value symbol
))))
1104 (push (list symbol
'custom-variable
) found
)))))
1106 (error "No rogue user options")
1107 (custom-buffer-create (custom-sort-items found t nil
)
1108 "*Customize Rogue*"))))
1110 (defun customize-saved ()
1111 "Customize all already saved user options."
1114 (mapatoms (lambda (symbol)
1115 (and (or (get symbol
'saved-face
)
1116 (get symbol
'saved-face-comment
))
1117 (custom-facep symbol
)
1118 (push (list symbol
'custom-face
) found
))
1119 (and (or (get symbol
'saved-value
)
1120 (get symbol
'saved-variable-comment
))
1122 (push (list symbol
'custom-variable
) found
))))
1124 (error "No saved user options")
1125 (custom-buffer-create (custom-sort-items found t nil
)
1126 "*Customize Saved*"))))
1129 (defun customize-apropos (regexp &optional all
)
1130 "Customize all user options matching REGEXP.
1131 If ALL is `options', include only options.
1132 If ALL is `faces', include only faces.
1133 If ALL is `groups', include only groups.
1134 If ALL is t (interactively, with prefix arg), include options which are not
1135 user-settable, as well as faces and groups."
1136 (interactive "sCustomize regexp: \nP")
1138 (mapatoms (lambda (symbol)
1139 (when (string-match regexp
(symbol-name symbol
))
1140 (when (and (not (memq all
'(faces options
)))
1141 (get symbol
'custom-group
))
1142 (push (list symbol
'custom-group
) found
))
1143 (when (and (not (memq all
'(options groups
)))
1144 (custom-facep symbol
))
1145 (push (list symbol
'custom-face
) found
))
1146 (when (and (not (memq all
'(groups faces
)))
1148 (or (get symbol
'saved-value
)
1149 (custom-variable-p symbol
)
1150 (if (memq all
'(nil options
))
1151 (user-variable-p symbol
)
1152 (get symbol
'variable-documentation
))))
1153 (push (list symbol
'custom-variable
) found
)))))
1155 (error "No matches")
1156 (custom-buffer-create (custom-sort-items found t
1157 custom-buffer-order-groups
)
1158 "*Customize Apropos*"))))
1161 (defun customize-apropos-options (regexp &optional arg
)
1162 "Customize all user options matching REGEXP.
1163 With prefix arg, include options which are not user-settable."
1164 (interactive "sCustomize regexp: \nP")
1165 (customize-apropos regexp
(or arg
'options
)))
1168 (defun customize-apropos-faces (regexp)
1169 "Customize all user faces matching REGEXP."
1170 (interactive "sCustomize regexp: \n")
1171 (customize-apropos regexp
'faces
))
1174 (defun customize-apropos-groups (regexp)
1175 "Customize all user groups matching REGEXP."
1176 (interactive "sCustomize regexp: \n")
1177 (customize-apropos regexp
'groups
))
1181 (defcustom custom-buffer-style
'links
1182 "Control the presentation style for customization buffers.
1183 The value should be a symbol, one of:
1185 brackets: groups nest within each other with big horizontal brackets.
1186 links: groups have links to subgroups."
1187 :type
'(radio (const brackets
)
1189 :group
'custom-buffer
)
1191 ;; If we pass BUFFER to `bury-buffer', the buffer isn't removed from
1193 (defun custom-bury-buffer (buffer)
1194 (with-current-buffer buffer
1197 (defcustom custom-buffer-done-function
'custom-bury-buffer
1198 "*Function called to remove a Custom buffer when the user is done with it.
1199 Called with one argument, the buffer to remove."
1200 :type
'(choice (function-item :tag
"Bury buffer" custom-bury-buffer
)
1201 (function-item :tag
"Kill buffer" kill-buffer
)
1202 (function :tag
"Other"))
1204 :group
'custom-buffer
)
1206 (defcustom custom-buffer-indent
3
1207 "Number of spaces to indent nested groups."
1209 :group
'custom-buffer
)
1211 (defun custom-get-fresh-buffer (name)
1212 "Get a fresh new buffer with name NAME.
1213 If the buffer already exist, clean it up to be like new.
1214 Beware: it's not quite like new. Good enough for custom, but maybe
1216 ;; To be more complete, we should also kill all permanent-local variables,
1217 ;; but it's not needed for custom.
1218 (let ((buf (get-buffer name
)))
1219 (when (and buf
(buffer-local-value 'buffer-file-name buf
))
1220 ;; This will check if the file is not saved.
1224 (get-buffer-create name
)
1225 (with-current-buffer buf
1226 (kill-all-local-variables)
1227 (run-hooks 'kill-buffer-hook
)
1228 ;; Delete overlays before erasing the buffer so the overlay hooks
1229 ;; don't get run spuriously when we erase the buffer.
1230 (let ((ols (overlay-lists)))
1231 (dolist (ol (nconc (car ols
) (cdr ols
)))
1232 (delete-overlay ol
)))
1237 (defun custom-buffer-create (options &optional name description
)
1238 "Create a buffer containing OPTIONS.
1239 Optional NAME is the name of the buffer.
1240 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1241 SYMBOL is a customization option, and WIDGET is a widget for editing
1243 (pop-to-buffer (custom-get-fresh-buffer (or name
"*Customization*")))
1244 (custom-buffer-create-internal options description
))
1247 (defun custom-buffer-create-other-window (options &optional name description
)
1248 "Create a buffer containing OPTIONS.
1249 Optional NAME is the name of the buffer.
1250 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1251 SYMBOL is a customization option, and WIDGET is a widget for editing
1253 (unless name
(setq name
"*Customization*"))
1254 (let ((window (selected-window))
1256 (special-display-buffer-names nil
)
1257 (special-display-regexps nil
)
1258 (same-window-buffer-names nil
)
1259 (same-window-regexps nil
))
1260 (pop-to-buffer (custom-get-fresh-buffer name
))
1261 (custom-buffer-create-internal options description
)
1262 (select-window window
)))
1264 (defcustom custom-reset-button-menu nil
1265 "If non-nil, only show a single reset button in customize buffers.
1266 This button will have a menu with all three reset operations."
1268 :group
'custom-buffer
)
1270 (defcustom custom-buffer-verbose-help t
1271 "If non-nil, include explanatory text in the customization buffer."
1273 :group
'custom-buffer
)
1275 (defun Custom-buffer-done (&rest ignore
)
1276 "Remove current buffer by calling `custom-buffer-done-function'."
1278 (funcall custom-buffer-done-function
(current-buffer)))
1280 (defcustom custom-raised-buttons
(not (equal (face-valid-attribute-values :box
)
1281 '(("unspecified" . unspecified
))))
1282 "If non-nil, indicate active buttons in a `raised-button' style.
1283 Otherwise use brackets."
1286 :group
'custom-buffer
)
1288 (defun custom-buffer-create-internal (options &optional description
)
1289 (message "Creating customization buffer...")
1291 (if custom-buffer-verbose-help
1293 (widget-insert "This is a customization buffer")
1295 (widget-insert description
))
1296 (widget-insert (format ".
1297 %s show active fields; type RET or click mouse-1
1298 on an active field to invoke its action. Editing an option value
1299 changes the text in the buffer; invoke the State button and
1300 choose the Set operation to set the option value.
1301 Invoke " (if custom-raised-buttons
1303 "Square brackets")))
1304 (widget-create 'info-link
1306 :help-echo
"Read the online help."
1307 "(emacs)Easy Customization")
1308 (widget-insert " for more information.\n\n")
1309 (message "Creating customization buttons...")
1310 (widget-insert "Operate on everything in this buffer:\n "))
1311 (widget-insert " "))
1312 (widget-create 'push-button
1313 :tag
"Set for Current Session"
1315 Make your editing in this buffer take effect for this session."
1316 :action
(lambda (widget &optional event
)
1319 (widget-create 'push-button
1320 :tag
"Save for Future Sessions"
1322 Make your editing in this buffer take effect for future Emacs sessions."
1323 :action
(lambda (widget &optional event
)
1325 (if custom-reset-button-menu
1328 (widget-create 'push-button
1330 :help-echo
"Show a menu with reset operations."
1331 :mouse-down-action
(lambda (&rest junk
) t
)
1332 :action
(lambda (widget &optional event
)
1333 (custom-reset event
))))
1334 (widget-insert "\n ")
1335 (widget-create 'push-button
1338 Reset all edited text in this buffer to reflect current values."
1339 :action
'Custom-reset-current
)
1341 (widget-create 'push-button
1342 :tag
"Reset to Saved"
1344 Reset all values in this buffer to their saved settings."
1345 :action
'Custom-reset-saved
)
1347 (widget-create 'push-button
1348 :tag
"Erase Customization"
1350 Un-customize all values in this buffer. They get their standard settings."
1351 :action
'Custom-reset-standard
))
1352 (if (not custom-buffer-verbose-help
)
1355 (widget-create 'info-link
1357 :help-echo
"Read the online help."
1358 "(emacs)Easy Customization")))
1360 (widget-create 'push-button
1363 (lambda (&rest ignore
)
1365 ((eq custom-buffer-done-function
1366 'custom-bury-buffer
)
1368 ((eq custom-buffer-done-function
'kill-buffer
)
1370 (t "Finish with this buffer")))
1371 :action
#'Custom-buffer-done
)
1372 (widget-insert "\n\n")
1373 (message "Creating customization items...")
1374 (buffer-disable-undo)
1375 (setq custom-options
1376 (if (= (length options
) 1)
1377 (mapcar (lambda (entry)
1378 (widget-create (nth 1 entry
)
1379 :documentation-shown t
1380 :custom-state
'unknown
1381 :tag
(custom-unlispify-tag-name
1383 :value
(nth 0 entry
)))
1386 (length (length options
)))
1387 (mapcar (lambda (entry)
1389 (message "Creating customization items ...%2d%%"
1390 (/ (* 100.0 count
) length
))
1391 (widget-create (nth 1 entry
)
1392 :tag
(custom-unlispify-tag-name
1394 :value
(nth 0 entry
))
1395 (setq count
(1+ count
))
1396 (unless (eq (preceding-char) ?
\n)
1397 (widget-insert "\n"))
1398 (widget-insert "\n")))
1400 (unless (eq (preceding-char) ?
\n)
1401 (widget-insert "\n"))
1402 (message "Creating customization items ...done")
1403 (unless (eq custom-buffer-style
'tree
)
1404 (mapc 'custom-magic-reset custom-options
))
1405 (message "Creating customization setup...")
1407 (buffer-enable-undo)
1408 (goto-char (point-min))
1409 (message "Creating customization buffer...done"))
1411 ;;; The Tree Browser.
1414 (defun customize-browse (&optional group
)
1415 "Create a tree browser for the customize hierarchy."
1418 (setq group
'emacs
))
1419 (let ((name "*Customize Browser*"))
1420 (pop-to-buffer (custom-get-fresh-buffer name
)))
1423 Square brackets show active fields; type RET or click mouse-1
1424 on an active field to invoke its action.
1425 Invoke [+] below to expand a group, and [-] to collapse an expanded group.\n")
1426 (if custom-browse-only-groups
1428 Invoke the [Group] button below to edit that item in another window.\n\n")
1429 (widget-insert "Invoke the ")
1430 (widget-create 'item
1433 :tag-glyph
"folder")
1434 (widget-insert ", ")
1435 (widget-create 'item
1439 (widget-insert ", and ")
1440 (widget-create 'item
1443 :tag-glyph
"option")
1444 (widget-insert " buttons below to edit that
1445 item in another window.\n\n"))
1446 (let ((custom-buffer-style 'tree
))
1447 (widget-create 'custom-group
1449 :custom-state
'unknown
1450 :tag
(custom-unlispify-tag-name group
)
1453 (goto-char (point-min)))
1455 (define-widget 'custom-browse-visibility
'item
1456 "Control visibility of items in the customize tree browser."
1458 :action
'custom-browse-visibility-action
)
1460 (defun custom-browse-visibility-action (widget &rest ignore
)
1461 (let ((custom-buffer-style 'tree
))
1462 (custom-toggle-parent widget
)))
1464 (define-widget 'custom-browse-group-tag
'push-button
1465 "Show parent in other window when activated."
1468 :action
'custom-browse-group-tag-action
)
1470 (defun custom-browse-group-tag-action (widget &rest ignore
)
1471 (let ((parent (widget-get widget
:parent
)))
1472 (customize-group-other-window (widget-value parent
))))
1474 (define-widget 'custom-browse-variable-tag
'push-button
1475 "Show parent in other window when activated."
1478 :action
'custom-browse-variable-tag-action
)
1480 (defun custom-browse-variable-tag-action (widget &rest ignore
)
1481 (let ((parent (widget-get widget
:parent
)))
1482 (customize-variable-other-window (widget-value parent
))))
1484 (define-widget 'custom-browse-face-tag
'push-button
1485 "Show parent in other window when activated."
1488 :action
'custom-browse-face-tag-action
)
1490 (defun custom-browse-face-tag-action (widget &rest ignore
)
1491 (let ((parent (widget-get widget
:parent
)))
1492 (customize-face-other-window (widget-value parent
))))
1494 (defconst custom-browse-alist
'((" " "space")
1500 (defun custom-browse-insert-prefix (prefix)
1501 "Insert PREFIX. On XEmacs convert it to line graphics."
1502 ;; Fixme: do graphics.
1503 (if nil
; (string-match "XEmacs" emacs-version)
1506 (while (not (string-equal prefix
""))
1507 (let ((entry (substring prefix
0 3)))
1508 (setq prefix
(substring prefix
3))
1509 (let ((overlay (make-overlay (1- (point)) (point) nil t nil
))
1510 (name (nth 1 (assoc entry custom-browse-alist
))))
1511 (overlay-put overlay
'end-glyph
(widget-glyph-find name entry
))
1512 (overlay-put overlay
'start-open t
)
1513 (overlay-put overlay
'end-open t
)))))
1516 ;;; Modification of Basic Widgets.
1518 ;; We add extra properties to the basic widgets needed here. This is
1519 ;; fine, as long as we are careful to stay within out own namespace.
1521 ;; We want simple widgets to be displayed by default, but complex
1522 ;; widgets to be hidden.
1524 (widget-put (get 'item
'widget-type
) :custom-show t
)
1525 (widget-put (get 'editable-field
'widget-type
)
1526 :custom-show
(lambda (widget value
)
1527 (let ((pp (pp-to-string value
)))
1528 (cond ((string-match "\n" pp
)
1533 (widget-put (get 'menu-choice
'widget-type
) :custom-show t
)
1535 ;;; The `custom-manual' Widget.
1537 (define-widget 'custom-manual
'info-link
1538 "Link to the manual entry for this customization option."
1539 :help-echo
"Read the manual entry for this option."
1542 ;;; The `custom-magic' Widget.
1544 (defgroup custom-magic-faces nil
1545 "Faces used by the magic button."
1546 :group
'custom-faces
1547 :group
'custom-buffer
)
1549 (defface custom-invalid-face
'((((class color
))
1550 (:foreground
"yellow" :background
"red"))
1552 (:weight bold
:slant italic
:underline t
)))
1553 "Face used when the customize item is invalid."
1554 :group
'custom-magic-faces
)
1556 (defface custom-rogue-face
'((((class color
))
1557 (:foreground
"pink" :background
"black"))
1560 "Face used when the customize item is not defined for customization."
1561 :group
'custom-magic-faces
)
1563 (defface custom-modified-face
'((((class color
))
1564 (:foreground
"white" :background
"blue"))
1566 (:slant italic
:bold
)))
1567 "Face used when the customize item has been modified."
1568 :group
'custom-magic-faces
)
1570 (defface custom-set-face
'((((class color
))
1571 (:foreground
"blue" :background
"white"))
1574 "Face used when the customize item has been set."
1575 :group
'custom-magic-faces
)
1577 (defface custom-changed-face
'((((class color
))
1578 (:foreground
"white" :background
"blue"))
1581 "Face used when the customize item has been changed."
1582 :group
'custom-magic-faces
)
1584 (defface custom-saved-face
'((t (:underline t
)))
1585 "Face used when the customize item has been saved."
1586 :group
'custom-magic-faces
)
1588 (defconst custom-magic-alist
'((nil "#" underline
"\
1589 uninitialized, you should not see this.")
1590 (unknown "?" italic
"\
1591 unknown, you should not see this.")
1592 (hidden "-" default
"\
1593 hidden, invoke \"Show\" in the previous line to show." "\
1594 group now hidden, invoke \"Show\", above, to show contents.")
1595 (invalid "x" custom-invalid-face
"\
1596 the value displayed for this %c is invalid and cannot be set.")
1597 (modified "*" custom-modified-face
"\
1598 you have edited the value as text, but you have not set the %c." "\
1599 you have edited something in this group, but not set it.")
1600 (set "+" custom-set-face
"\
1601 you have set this %c, but not saved it for future sessions." "\
1602 something in this group has been set, but not saved.")
1603 (changed ":" custom-changed-face
"\
1604 this %c has been changed outside the customize buffer." "\
1605 something in this group has been changed outside customize.")
1606 (saved "!" custom-saved-face
"\
1607 this %c has been set and saved." "\
1608 something in this group has been set and saved.")
1609 (rogue "@" custom-rogue-face
"\
1610 this %c has not been changed with customize." "\
1611 something in this group is not prepared for customization.")
1612 (standard " " nil
"\
1613 this %c is unchanged from its standard setting." "\
1614 visible group members are all at standard settings."))
1615 "Alist of customize option states.
1616 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1618 STATE is one of the following symbols:
1621 For internal use, should never occur.
1623 For internal use, should never occur.
1625 This item is not being displayed.
1627 This item is modified, but has an invalid form.
1629 This item is modified, and has a valid form.
1631 This item has been set but not saved.
1633 The current value of this item has been changed temporarily.
1635 This item is marked for saving.
1637 This item has no customization information.
1639 This item is unchanged from the standard setting.
1641 MAGIC is a string used to present that state.
1643 FACE is a face used to present the state.
1645 ITEM-DESC is a string describing the state for options.
1647 GROUP-DESC is a string describing the state for groups. If this is
1648 left out, ITEM-DESC will be used.
1650 The string %c in either description will be replaced with the
1651 category of the item. These are `group'. `option', and `face'.
1653 The list should be sorted most significant first.")
1655 (defcustom custom-magic-show
'long
1656 "If non-nil, show textual description of the state.
1657 If `long', show a full-line description, not just one word."
1658 :type
'(choice (const :tag
"no" nil
)
1660 (other :tag
"short" short
))
1661 :group
'custom-buffer
)
1663 (defcustom custom-magic-show-hidden
'(option face
)
1664 "Control whether the State button is shown for hidden items.
1665 The value should be a list with the custom categories where the State
1666 button should be visible. Possible categories are `group', `option',
1668 :type
'(set (const group
) (const option
) (const face
))
1669 :group
'custom-buffer
)
1671 (defcustom custom-magic-show-button nil
1672 "Show a \"magic\" button indicating the state of each customization option."
1674 :group
'custom-buffer
)
1676 (define-widget 'custom-magic
'default
1677 "Show and manipulate state for a customization option."
1679 :action
'widget-parent-action
1682 :value-create
'custom-magic-value-create
1683 :value-delete
'widget-children-value-delete
)
1685 (defun widget-magic-mouse-down-action (widget &optional event
)
1686 ;; Non-nil unless hidden.
1687 (not (eq (widget-get (widget-get (widget-get widget
:parent
) :parent
)
1691 (defun custom-magic-value-create (widget)
1692 "Create compact status report for WIDGET."
1693 (let* ((parent (widget-get widget
:parent
))
1694 (state (widget-get parent
:custom-state
))
1695 (hidden (eq state
'hidden
))
1696 (entry (assq state custom-magic-alist
))
1697 (magic (nth 1 entry
))
1698 (face (nth 2 entry
))
1699 (category (widget-get parent
:custom-category
))
1700 (text (or (and (eq category
'group
)
1703 (form (widget-get parent
:custom-form
))
1705 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text
)
1706 (setq text
(concat (match-string 1 text
)
1707 (symbol-name category
)
1708 (match-string 2 text
))))
1709 (when (and custom-magic-show
1711 (memq category custom-magic-show-hidden
)))
1713 (when (and (eq category
'group
)
1714 (not (and (eq custom-buffer-style
'links
)
1715 (> (widget-get parent
:custom-level
) 1))))
1716 (insert-char ?\
(* custom-buffer-indent
1717 (widget-get parent
:custom-level
))))
1718 (push (widget-create-child-and-convert
1720 :help-echo
"Change the state of this item."
1721 :format
(if hidden
"%t" "%[%t%]")
1722 :button-prefix
'widget-push-button-prefix
1723 :button-suffix
'widget-push-button-suffix
1724 :mouse-down-action
'widget-magic-mouse-down-action
1728 (let ((start (point)))
1729 (if (eq custom-magic-show
'long
)
1731 (insert (symbol-name state
)))
1732 (cond ((eq form
'lisp
)
1734 ((eq form
'mismatch
)
1735 (insert " (mismatch)")))
1736 (put-text-property start
(point) 'face
'custom-state-face
))
1738 (when (and (eq category
'group
)
1739 (not (and (eq custom-buffer-style
'links
)
1740 (> (widget-get parent
:custom-level
) 1))))
1741 (insert-char ?\
(* custom-buffer-indent
1742 (widget-get parent
:custom-level
))))
1743 (when custom-magic-show-button
1744 (when custom-magic-show
1745 (let ((indent (widget-get parent
:indent
)))
1747 (insert-char ? indent
))))
1748 (push (widget-create-child-and-convert
1750 :mouse-down-action
'widget-magic-mouse-down-action
1754 :help-echo
"Change the state."
1755 :format
(if hidden
"%t" "%[%t%]")
1756 :tag
(if (memq form
'(lisp mismatch
))
1757 (concat "(" magic
")")
1758 (concat "[" magic
"]")))
1761 (widget-put widget
:children children
)))
1763 (defun custom-magic-reset (widget)
1764 "Redraw the :custom-magic property of WIDGET."
1765 (let ((magic (widget-get widget
:custom-magic
)))
1766 (widget-value-set magic
(widget-value magic
))))
1768 ;;; The `custom' Widget.
1770 (defface custom-button-face
1771 '((((type x w32 mac
) (class color
)) ; Like default modeline
1772 (:box
(:line-width
2 :style released-button
)
1773 :background
"lightgrey" :foreground
"black"))
1776 "Face used for buttons in customization buffers."
1778 :group
'custom-faces
)
1780 (defface custom-button-pressed-face
1781 '((((type x w32 mac
) (class color
))
1782 (:box
(:line-width
2 :style pressed-button
)
1783 :background
"lightgrey" :foreground
"black"))
1785 (:inverse-video t
)))
1786 "Face used for buttons in customization buffers."
1788 :group
'custom-faces
)
1790 (defface custom-documentation-face nil
1791 "Face used for documentation strings in customization buffers."
1792 :group
'custom-faces
)
1794 (defface custom-state-face
'((((class color
)
1796 (:foreground
"lime green"))
1799 (:foreground
"dark green"))
1801 "Face used for State descriptions in the customize buffer."
1802 :group
'custom-faces
)
1804 (define-widget 'custom
'default
1805 "Customize a user option."
1807 :convert-widget
'custom-convert-widget
1808 :notify
'custom-notify
1811 :custom-state
'hidden
1812 :documentation-property
'widget-subclass-responsibility
1813 :value-create
'widget-subclass-responsibility
1814 :value-delete
'widget-children-value-delete
1815 :value-get
'widget-value-value-get
1816 :validate
'widget-children-validate
1817 :match
(lambda (widget value
) (symbolp value
)))
1819 (defun custom-convert-widget (widget)
1820 "Initialize :value and :tag from :args in WIDGET."
1821 (let ((args (widget-get widget
:args
)))
1823 (widget-put widget
:value
(widget-apply widget
1824 :value-to-internal
(car args
)))
1825 (widget-put widget
:tag
(custom-unlispify-tag-name (car args
)))
1826 (widget-put widget
:args nil
)))
1829 (defun custom-notify (widget &rest args
)
1830 "Keep track of changes."
1831 (let ((state (widget-get widget
:custom-state
)))
1832 (unless (eq state
'modified
)
1833 (unless (memq state
'(nil unknown hidden
))
1834 (widget-put widget
:custom-state
'modified
))
1835 (custom-magic-reset widget
)
1836 (apply 'widget-default-notify widget args
))))
1838 (defun custom-redraw (widget)
1839 "Redraw WIDGET with current settings."
1840 (let ((line (count-lines (point-min) (point)))
1841 (column (current-column))
1843 (from (marker-position (widget-get widget
:from
)))
1844 (to (marker-position (widget-get widget
:to
))))
1846 (widget-value-set widget
(widget-value widget
))
1847 (custom-redraw-magic widget
))
1848 (when (and (>= pos from
) (<= pos to
))
1853 (goto-line (1+ line
)))
1854 (move-to-column column
))
1857 (defun custom-redraw-magic (widget)
1858 "Redraw WIDGET state with current settings."
1860 (let ((magic (widget-get widget
:custom-magic
)))
1862 (widget-value-set magic
(widget-value magic
))
1863 (when (setq widget
(widget-get widget
:group
))
1864 (custom-group-state-update widget
)))
1866 (setq widget nil
)))))
1869 (defun custom-show (widget value
)
1870 "Non-nil if WIDGET should be shown with VALUE by default."
1871 (let ((show (widget-get widget
:custom-show
)))
1877 (funcall show widget value
)))))
1879 (defun custom-load-widget (widget)
1880 "Load all dependencies for WIDGET."
1881 (custom-load-symbol (widget-value widget
)))
1883 (defun custom-unloaded-symbol-p (symbol)
1884 "Return non-nil if the dependencies of SYMBOL has not yet been loaded."
1886 (loads (get symbol
'custom-loads
))
1889 (setq load
(car loads
)
1891 (cond ((symbolp load
)
1892 (unless (featurep load
)
1894 ((assoc load load-history
))
1895 ((assoc (locate-library load
) load-history
)
1901 (defun custom-unloaded-widget-p (widget)
1902 "Return non-nil if the dependencies of WIDGET has not yet been loaded."
1903 (custom-unloaded-symbol-p (widget-value widget
)))
1905 (defun custom-toggle-hide (widget)
1906 "Toggle visibility of WIDGET."
1907 (custom-load-widget widget
)
1908 (let ((state (widget-get widget
:custom-state
)))
1909 (cond ((memq state
'(invalid modified
))
1910 (error "There are unset changes"))
1912 (widget-put widget
:custom-state
'unknown
))
1914 (widget-put widget
:documentation-shown nil
)
1915 (widget-put widget
:custom-state
'hidden
)))
1916 (custom-redraw widget
)
1919 (defun custom-toggle-parent (widget &rest ignore
)
1920 "Toggle visibility of parent of WIDGET."
1921 (custom-toggle-hide (widget-get widget
:parent
)))
1923 (defun custom-add-see-also (widget &optional prefix
)
1924 "Add `See also ...' to WIDGET if there are any links.
1925 Insert PREFIX first if non-nil."
1926 (let* ((symbol (widget-get widget
:value
))
1927 (links (get symbol
'custom-links
))
1928 (many (> (length links
) 2))
1929 (buttons (widget-get widget
:buttons
))
1930 (indent (widget-get widget
:indent
)))
1933 (insert-char ?\ indent
))
1936 (insert "See also ")
1938 (push (widget-create-child-and-convert widget
(car links
))
1940 (setq links
(cdr links
))
1949 (widget-put widget
:buttons buttons
))))
1951 (defun custom-add-parent-links (widget &optional initial-string
)
1952 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
1953 The value if non-nil if any parents were found.
1954 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
1955 (let ((name (widget-value widget
))
1956 (type (widget-type widget
))
1957 (buttons (widget-get widget
:buttons
))
1960 (insert (or initial-string
"Parent groups:"))
1961 (mapatoms (lambda (symbol)
1962 (let ((entry (assq name
(get symbol
'custom-group
))))
1963 (when (eq (nth 1 entry
) type
)
1965 (push (widget-create-child-and-convert
1966 widget
'custom-group-link
1967 :tag
(custom-unlispify-tag-name symbol
)
1970 (setq parents
(cons symbol parents
))))))
1971 (and (null (get symbol
'custom-links
)) ;No links of its own.
1972 (= (length parents
) 1) ;A single parent.
1973 (let* ((links (get (car parents
) 'custom-links
))
1974 (many (> (length links
) 2)))
1976 (insert "\nParent documentation: ")
1978 (push (widget-create-child-and-convert widget
(car links
))
1980 (setq links
(cdr links
))
1991 (delete-region start
(point)))
1992 (widget-put widget
:buttons buttons
)
1995 ;;; The `custom-comment' Widget.
1997 ;; like the editable field
1998 (defface custom-comment-face
'((((class grayscale color
)
2000 (:background
"gray85"))
2001 (((class grayscale color
)
2003 (:background
"dim gray"))
2006 "Face used for comments on variables or faces"
2008 :group
'custom-faces
)
2010 ;; like font-lock-comment-face
2011 (defface custom-comment-tag-face
2012 '((((class color
) (background dark
)) (:foreground
"gray80"))
2013 (((class color
) (background light
)) (:foreground
"blue4"))
2014 (((class grayscale
) (background light
))
2015 (:foreground
"DimGray" :weight bold
:slant italic
))
2016 (((class grayscale
) (background dark
))
2017 (:foreground
"LightGray" :weight bold
:slant italic
))
2019 "Face used for variables or faces comment tags"
2020 :group
'custom-faces
)
2022 (define-widget 'custom-comment
'string
2025 :help-echo
"Edit a comment here."
2026 :sample-face
'custom-comment-tag-face
2027 :value-face
'custom-comment-face
2029 :create
'custom-comment-create
)
2031 (defun custom-comment-create (widget)
2032 (let* ((null-comment (equal "" (widget-value widget
))))
2033 (if (or (widget-get (widget-get widget
:parent
) :comment-shown
)
2035 (widget-default-create widget
)
2036 ;; `widget-default-delete' expects markers in these slots --
2037 ;; maybe it shouldn't.
2038 (widget-put widget
:from
(point-marker))
2039 (widget-put widget
:to
(point-marker)))))
2041 (defun custom-comment-hide (widget)
2042 (widget-put (widget-get widget
:parent
) :comment-shown nil
))
2044 ;; Those functions are for the menu. WIDGET is NOT the comment widget. It's
2045 ;; the global custom one
2046 (defun custom-comment-show (widget)
2047 (widget-put widget
:comment-shown t
)
2048 (custom-redraw widget
)
2051 (defun custom-comment-invisible-p (widget)
2052 (let ((val (widget-value (widget-get widget
:comment-widget
))))
2054 (not (widget-get widget
:comment-shown
)))))
2056 ;;; The `custom-variable' Widget.
2058 ;; When this was underlined blue, users confused it with a
2059 ;; Mosaic-style hyperlink...
2060 (defface custom-variable-tag-face
2063 (:foreground
"light blue" :weight bold
:height
1.2 :inherit variable-pitch
))
2066 (:foreground
"blue" :weight bold
:height
1.2 :inherit variable-pitch
))
2068 "Face used for unpushable variable tags."
2069 :group
'custom-faces
)
2071 (defface custom-variable-button-face
'((t (:underline t
:weight bold
)))
2072 "Face used for pushable variable tags."
2073 :group
'custom-faces
)
2075 (defcustom custom-variable-default-form
'edit
2076 "Default form of displaying variable values."
2077 :type
'(choice (const edit
)
2079 :group
'custom-buffer
2082 (define-widget 'custom-variable
'custom
2083 "Customize variable."
2085 :help-echo
"Set or reset this variable."
2086 :documentation-property
'variable-documentation
2087 :custom-category
'option
2089 :custom-menu
'custom-variable-menu-create
2090 :custom-form nil
; defaults to value of `custom-variable-default-form'
2091 :value-create
'custom-variable-value-create
2092 :action
'custom-variable-action
2093 :custom-set
'custom-variable-set
2094 :custom-save
'custom-variable-save
2095 :custom-reset-current
'custom-redraw
2096 :custom-reset-saved
'custom-variable-reset-saved
2097 :custom-reset-standard
'custom-variable-reset-standard
2098 :custom-standard-value
'custom-variable-standard-value
)
2100 (defun custom-variable-type (symbol)
2101 "Return a widget suitable for editing the value of SYMBOL.
2102 If SYMBOL has a `custom-type' property, use that.
2103 Otherwise, look up symbol in `custom-guess-type-alist'."
2104 (let* ((type (or (get symbol
'custom-type
)
2105 (and (not (get symbol
'standard-value
))
2106 (custom-guess-type symbol
))
2108 (options (get symbol
'custom-options
))
2109 (tmp (if (listp type
)
2110 (copy-sequence type
)
2113 (widget-put tmp
:options options
))
2116 (defun custom-variable-value-create (widget)
2117 "Here is where you edit the variable's value."
2118 (custom-load-widget widget
)
2119 (unless (widget-get widget
:custom-form
)
2120 (widget-put widget
:custom-form custom-variable-default-form
))
2121 (let* ((buttons (widget-get widget
:buttons
))
2122 (children (widget-get widget
:children
))
2123 (form (widget-get widget
:custom-form
))
2124 (state (widget-get widget
:custom-state
))
2125 (symbol (widget-get widget
:value
))
2126 (tag (widget-get widget
:tag
))
2127 (type (custom-variable-type symbol
))
2128 (conv (widget-convert type
))
2129 (get (or (get symbol
'custom-get
) 'default-value
))
2130 (prefix (widget-get widget
:custom-prefix
))
2131 (last (widget-get widget
:custom-last
))
2132 (value (if (default-boundp symbol
)
2133 (funcall get symbol
)
2134 (widget-get conv
:value
))))
2135 ;; If the widget is new, the child determines whether it is hidden.
2137 ((custom-show type value
)
2138 (setq state
'unknown
))
2140 (setq state
'hidden
)))
2141 ;; If we don't know the state, see if we need to edit it in lisp form.
2142 (when (eq state
'unknown
)
2143 (unless (widget-apply conv
:match value
)
2144 ;; (widget-apply (widget-convert type) :match value)
2145 (setq form
'mismatch
)))
2146 ;; Now we can create the child widget.
2147 (cond ((eq custom-buffer-style
'tree
)
2148 (insert prefix
(if last
" `--- " " |--- "))
2149 (push (widget-create-child-and-convert
2150 widget
'custom-browse-variable-tag
)
2152 (insert " " tag
"\n")
2153 (widget-put widget
:buttons buttons
))
2155 ;; Indicate hidden value.
2156 (push (widget-create-child-and-convert
2159 :sample-face
'custom-variable-tag-face
2163 (push (widget-create-child-and-convert
2165 :help-echo
"Show the value of this option."
2167 :action
'custom-toggle-parent
2170 ((memq form
'(lisp mismatch
))
2171 ;; In lisp mode edit the saved value when possible.
2172 (let* ((value (cond ((get symbol
'saved-value
)
2173 (car (get symbol
'saved-value
)))
2174 ((get symbol
'standard-value
)
2175 (car (get symbol
'standard-value
)))
2176 ((default-boundp symbol
)
2177 (custom-quote (funcall get symbol
)))
2179 (custom-quote (widget-get conv
:value
))))))
2180 (insert (symbol-name symbol
) ": ")
2181 (push (widget-create-child-and-convert
2183 :help-echo
"Hide the value of this option."
2186 :action
'custom-toggle-parent
2190 (push (widget-create-child-and-convert
2192 :button-face
'custom-variable-button-face
2194 :tag
(symbol-name symbol
)
2200 (let* ((format (widget-get type
:format
))
2201 tag-format value-format
)
2202 (unless (string-match ":" format
)
2203 (error "Bad format"))
2204 (setq tag-format
(substring format
0 (match-end 0)))
2205 (setq value-format
(substring format
(match-end 0)))
2206 (push (widget-create-child-and-convert
2209 :action
'custom-tag-action
2210 :help-echo
"Change value of this option."
2211 :mouse-down-action
'custom-tag-mouse-down-action
2212 :button-face
'custom-variable-button-face
2213 :sample-face
'custom-variable-tag-face
2217 (push (widget-create-child-and-convert
2219 :help-echo
"Hide the value of this option."
2222 :action
'custom-toggle-parent
2225 (push (widget-create-child-and-convert
2227 :format value-format
2230 (unless (eq custom-buffer-style
'tree
)
2231 (unless (eq (preceding-char) ?
\n)
2232 (widget-insert "\n"))
2233 ;; Create the magic button.
2234 (let ((magic (widget-create-child-and-convert
2235 widget
'custom-magic nil
)))
2236 (widget-put widget
:custom-magic magic
)
2237 (push magic buttons
))
2238 ;; ### NOTE: this is ugly!!!! I need to update the :buttons property
2239 ;; before the call to `widget-default-format-handler'. Otherwise, I
2240 ;; loose my current `buttons'. This function shouldn't be called like
2241 ;; this anyway. The doc string widget should be added like the others.
2243 (widget-put widget
:buttons buttons
)
2245 ;; Insert documentation.
2246 (widget-default-format-handler widget ?h
)
2248 ;; The comment field
2249 (unless (eq state
'hidden
)
2250 (let* ((comment (get symbol
'variable-comment
))
2252 (widget-create-child-and-convert
2253 widget
'custom-comment
2255 :value
(or comment
""))))
2256 (widget-put widget
:comment-widget comment-widget
)
2257 ;; Don't push it !!! Custom assumes that the first child is the
2259 (setq children
(append children
(list comment-widget
)))))
2260 ;; Update the rest of the properties properties.
2261 (widget-put widget
:custom-form form
)
2262 (widget-put widget
:children children
)
2263 ;; Now update the state.
2264 (if (eq state
'hidden
)
2265 (widget-put widget
:custom-state state
)
2266 (custom-variable-state-set widget
))
2268 (unless (eq state
'hidden
)
2269 (when (eq (widget-get widget
:custom-level
) 1)
2270 (custom-add-parent-links widget
))
2271 (custom-add-see-also widget
)))))
2273 (defun custom-tag-action (widget &rest args
)
2274 "Pass :action to first child of WIDGET's parent."
2275 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2278 (defun custom-tag-mouse-down-action (widget &rest args
)
2279 "Pass :mouse-down-action to first child of WIDGET's parent."
2280 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2281 :mouse-down-action args
))
2283 (defun custom-variable-state-set (widget)
2284 "Set the state of WIDGET."
2285 (let* ((symbol (widget-value widget
))
2286 (get (or (get symbol
'custom-get
) 'default-value
))
2287 (value (if (default-boundp symbol
)
2288 (funcall get symbol
)
2289 (widget-get widget
:value
)))
2290 (comment (get symbol
'variable-comment
))
2293 (state (cond ((progn (setq tmp
(get symbol
'customized-value
))
2295 (get symbol
'customized-variable-comment
))
2297 (if (condition-case nil
2298 (and (equal value
(eval (car tmp
)))
2299 (equal comment temp
))
2303 ((progn (setq tmp
(get symbol
'saved-value
))
2304 (setq temp
(get symbol
'saved-variable-comment
))
2306 (if (condition-case nil
2307 (and (equal value
(eval (car tmp
)))
2308 (equal comment temp
))
2312 ((setq tmp
(get symbol
'standard-value
))
2313 (if (condition-case nil
2314 (and (equal value
(eval (car tmp
)))
2315 (equal comment nil
))
2320 (widget-put widget
:custom-state state
)))
2322 (defun custom-variable-standard-value (widget)
2323 (get (widget-value widget
) 'standard-value
))
2325 (defvar custom-variable-menu
2326 '(("Set for Current Session" custom-variable-set
2328 (eq (widget-get widget
:custom-state
) 'modified
)))
2329 ("Save for Future Sessions" custom-variable-save
2331 (memq (widget-get widget
:custom-state
) '(modified set changed rogue
))))
2332 ("Reset to Current" custom-redraw
2334 (and (default-boundp (widget-value widget
))
2335 (memq (widget-get widget
:custom-state
) '(modified changed
)))))
2336 ("Reset to Saved" custom-variable-reset-saved
2338 (and (or (get (widget-value widget
) 'saved-value
)
2339 (get (widget-value widget
) 'saved-variable-comment
))
2340 (memq (widget-get widget
:custom-state
)
2341 '(modified set changed rogue
)))))
2342 ("Erase Customization" custom-variable-reset-standard
2344 (and (get (widget-value widget
) 'standard-value
)
2345 (memq (widget-get widget
:custom-state
)
2346 '(modified set changed saved rogue
)))))
2347 ("Use Backup Value" custom-variable-reset-backup
2349 (get (widget-value widget
) 'backup-value
)))
2350 ("---" ignore ignore
)
2351 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
2352 ("---" ignore ignore
)
2353 ("Don't show as Lisp expression" custom-variable-edit
2355 (eq (widget-get widget
:custom-form
) 'lisp
)))
2356 ("Show initial Lisp expression" custom-variable-edit-lisp
2358 (eq (widget-get widget
:custom-form
) 'edit
))))
2359 "Alist of actions for the `custom-variable' widget.
2360 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2361 the menu entry, ACTION is the function to call on the widget when the
2362 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2363 widget as an argument, and returns non-nil if ACTION is valid on that
2364 widget. If FILTER is nil, ACTION is always valid.")
2366 (defun custom-variable-action (widget &optional event
)
2367 "Show the menu for `custom-variable' WIDGET.
2368 Optional EVENT is the location for the menu."
2369 (if (eq (widget-get widget
:custom-state
) 'hidden
)
2370 (custom-toggle-hide widget
)
2371 (unless (eq (widget-get widget
:custom-state
) 'modified
)
2372 (custom-variable-state-set widget
))
2373 (custom-redraw-magic widget
)
2374 (let* ((completion-ignore-case t
)
2375 (answer (widget-choose (concat "Operation on "
2376 (custom-unlispify-tag-name
2377 (widget-get widget
:value
)))
2378 (custom-menu-filter custom-variable-menu
2382 (funcall answer widget
)))))
2384 (defun custom-variable-edit (widget)
2385 "Edit value of WIDGET."
2386 (widget-put widget
:custom-state
'unknown
)
2387 (widget-put widget
:custom-form
'edit
)
2388 (custom-redraw widget
))
2390 (defun custom-variable-edit-lisp (widget)
2391 "Edit the Lisp representation of the value of WIDGET."
2392 (widget-put widget
:custom-state
'unknown
)
2393 (widget-put widget
:custom-form
'lisp
)
2394 (custom-redraw widget
))
2396 (defun custom-variable-set (widget)
2397 "Set the current value for the variable being edited by WIDGET."
2398 (let* ((form (widget-get widget
:custom-form
))
2399 (state (widget-get widget
:custom-state
))
2400 (child (car (widget-get widget
:children
)))
2401 (symbol (widget-value widget
))
2402 (set (or (get symbol
'custom-set
) 'set-default
))
2403 (comment-widget (widget-get widget
:comment-widget
))
2404 (comment (widget-value comment-widget
))
2406 (cond ((eq state
'hidden
)
2407 (error "Cannot set hidden variable"))
2408 ((setq val
(widget-apply child
:validate
))
2409 (goto-char (widget-get val
:from
))
2410 (error "%s" (widget-get val
:error
)))
2411 ((memq form
'(lisp mismatch
))
2412 (when (equal comment
"")
2414 ;; Make the comment invisible by hand if it's empty
2415 (custom-comment-hide comment-widget
))
2416 (custom-variable-backup-value widget
)
2417 (funcall set symbol
(eval (setq val
(widget-value child
))))
2418 (put symbol
'customized-value
(list val
))
2419 (put symbol
'variable-comment comment
)
2420 (put symbol
'customized-variable-comment comment
))
2422 (when (equal comment
"")
2424 ;; Make the comment invisible by hand if it's empty
2425 (custom-comment-hide comment-widget
))
2426 (custom-variable-backup-value widget
)
2427 (funcall set symbol
(setq val
(widget-value child
)))
2428 (put symbol
'customized-value
(list (custom-quote val
)))
2429 (put symbol
'variable-comment comment
)
2430 (put symbol
'customized-variable-comment comment
)))
2431 (custom-variable-state-set widget
)
2432 (custom-redraw-magic widget
)))
2434 (defun custom-variable-save (widget)
2435 "Set and save the value for the variable being edited by WIDGET."
2436 (let* ((form (widget-get widget
:custom-form
))
2437 (state (widget-get widget
:custom-state
))
2438 (child (car (widget-get widget
:children
)))
2439 (symbol (widget-value widget
))
2440 (set (or (get symbol
'custom-set
) 'set-default
))
2441 (comment-widget (widget-get widget
:comment-widget
))
2442 (comment (widget-value comment-widget
))
2444 (cond ((eq state
'hidden
)
2445 (error "Cannot set hidden variable"))
2446 ((setq val
(widget-apply child
:validate
))
2447 (goto-char (widget-get val
:from
))
2448 (error "Saving %s: %s" symbol
(widget-get val
:error
)))
2449 ((memq form
'(lisp mismatch
))
2450 (when (equal comment
"")
2452 ;; Make the comment invisible by hand if it's empty
2453 (custom-comment-hide comment-widget
))
2454 (put symbol
'saved-value
(list (widget-value child
)))
2455 (custom-push-theme 'theme-value symbol
'user
2456 'set
(list (widget-value child
)))
2457 (funcall set symbol
(eval (widget-value child
)))
2458 (put symbol
'variable-comment comment
)
2459 (put symbol
'saved-variable-comment comment
))
2461 (when (equal comment
"")
2463 ;; Make the comment invisible by hand if it's empty
2464 (custom-comment-hide comment-widget
))
2465 (put symbol
'saved-value
2466 (list (custom-quote (widget-value child
))))
2467 (custom-push-theme 'theme-value symbol
'user
2468 'set
(list (custom-quote (widget-value
2470 (funcall set symbol
(widget-value child
))
2471 (put symbol
'variable-comment comment
)
2472 (put symbol
'saved-variable-comment comment
)))
2473 (put symbol
'customized-value nil
)
2474 (put symbol
'customized-variable-comment nil
)
2476 (custom-variable-state-set widget
)
2477 (custom-redraw-magic widget
)))
2479 (defun custom-variable-reset-saved (widget)
2480 "Restore the saved value for the variable being edited by WIDGET.
2481 The value that was current before this operation
2482 becomes the backup value, so you can get it again."
2483 (let* ((symbol (widget-value widget
))
2484 (set (or (get symbol
'custom-set
) 'set-default
))
2485 (value (get symbol
'saved-value
))
2486 (comment (get symbol
'saved-variable-comment
)))
2487 (cond ((or value comment
)
2488 (put symbol
'variable-comment comment
)
2489 (custom-variable-backup-value widget
)
2491 (funcall set symbol
(eval (car value
)))
2494 (error "No saved value for %s" symbol
)))
2495 (put symbol
'customized-value nil
)
2496 (put symbol
'customized-variable-comment nil
)
2497 (widget-put widget
:custom-state
'unknown
)
2498 ;; This call will possibly make the comment invisible
2499 (custom-redraw widget
)))
2501 (defun custom-variable-reset-standard (widget)
2502 "Restore the standard setting for the variable being edited by WIDGET.
2503 This operation eliminates any saved setting for the variable,
2504 restoring it to the state of a variable that has never been customized.
2505 The value that was current before this operation
2506 becomes the backup value, so you can get it again."
2507 (let* ((symbol (widget-value widget
))
2508 (set (or (get symbol
'custom-set
) 'set-default
)))
2509 (if (get symbol
'standard-value
)
2511 (custom-variable-backup-value widget
)
2512 (funcall set symbol
(eval (car (get symbol
'standard-value
)))))
2513 (error "No standard setting known for %S" symbol
))
2514 (put symbol
'variable-comment nil
)
2515 (put symbol
'customized-value nil
)
2516 (put symbol
'customized-variable-comment nil
)
2517 (when (or (get symbol
'saved-value
) (get symbol
'saved-variable-comment
))
2518 (put symbol
'saved-value nil
)
2519 (custom-push-theme 'theme-value symbol
'user
'reset
'standard
)
2520 ;; As a special optimizations we do not (explictly)
2521 ;; save resets to standard when no theme set the value.
2522 (if (null (cdr (get symbol
'theme-value
)))
2523 (put symbol
'theme-value nil
))
2524 (put symbol
'saved-variable-comment nil
)
2526 (widget-put widget
:custom-state
'unknown
)
2527 ;; This call will possibly make the comment invisible
2528 (custom-redraw widget
)))
2530 (defun custom-variable-backup-value (widget)
2531 "Back up the current value for WIDGET's variable.
2532 The backup value is kept in the car of the `backup-value' property."
2533 (let* ((symbol (widget-value widget
))
2534 (get (or (get symbol
'custom-get
) 'default-value
))
2535 (type (custom-variable-type symbol
))
2536 (conv (widget-convert type
))
2537 (value (if (default-boundp symbol
)
2538 (funcall get symbol
)
2539 (widget-get conv
:value
))))
2540 (put symbol
'backup-value
(list value
))))
2542 (defun custom-variable-reset-backup (widget)
2543 "Restore the backup value for the variable being edited by WIDGET.
2544 The value that was current before this operation
2545 becomes the backup value, so you can use this operation repeatedly
2546 to switch between two values."
2547 (let* ((symbol (widget-value widget
))
2548 (set (or (get symbol
'custom-set
) 'set-default
))
2549 (value (get symbol
'backup-value
))
2550 (comment-widget (widget-get widget
:comment-widget
))
2551 (comment (widget-value comment-widget
)))
2554 (custom-variable-backup-value widget
)
2556 (funcall set symbol
(car value
))
2558 (error "No backup value for %s" symbol
))
2559 (put symbol
'customized-value
(list (car value
)))
2560 (put symbol
'variable-comment comment
)
2561 (put symbol
'customized-variable-comment comment
)
2562 (custom-variable-state-set widget
)
2563 ;; This call will possibly make the comment invisible
2564 (custom-redraw widget
)))
2566 ;;; The `custom-face-edit' Widget.
2568 (define-widget 'custom-face-edit
'checklist
2569 "Edit face attributes."
2573 :button-args
'(:help-echo
"Control whether this attribute has any effect.")
2574 :value-to-internal
'custom-face-edit-fix-value
2575 :match
(lambda (widget value
)
2576 (widget-checklist-match widget
2577 (custom-face-edit-fix-value widget value
)))
2578 :convert-widget
'custom-face-edit-convert-widget
2579 :args
(mapcar (lambda (att)
2582 :sibling-args
(widget-get (nth 1 att
) :sibling-args
)
2583 (list 'const
:format
"" :value
(nth 0 att
))
2585 custom-face-attributes
))
2587 (defun custom-face-edit-fix-value (widget value
)
2588 "Ignoring WIDGET, convert :bold and :italic in VALUE to new form.
2589 Also change :reverse-video to :inverse-video."
2593 (let ((key (car value
))
2594 (val (car (cdr value
))))
2595 (cond ((eq key
:italic
)
2596 (push :slant result
)
2597 (push (if val
'italic
'normal
) result
))
2599 (push :weight result
)
2600 (push (if val
'bold
'normal
) result
))
2601 ((eq key
:reverse-video
)
2602 (push :inverse-video result
)
2606 (push val result
))))
2607 (setq value
(cdr (cdr value
))))
2608 (setq result
(nreverse result
))
2612 (defun custom-face-edit-convert-widget (widget)
2613 "Convert :args as widget types in WIDGET."
2616 :args
(mapcar (lambda (arg)
2618 :deactivate
'custom-face-edit-deactivate
2619 :activate
'custom-face-edit-activate
2620 :delete
'custom-face-edit-delete
))
2621 (widget-get widget
:args
)))
2624 (defun custom-face-edit-deactivate (widget)
2625 "Make face widget WIDGET inactive for user modifications."
2626 (unless (widget-get widget
:inactive
)
2627 (let ((tag (custom-face-edit-attribute-tag widget
))
2628 (from (copy-marker (widget-get widget
:from
)))
2629 (value (widget-value widget
))
2630 (inhibit-read-only t
)
2631 (inhibit-modification-hooks t
))
2634 (widget-default-delete widget
)
2635 (insert tag
": *\n")
2636 (widget-put widget
:inactive
2637 (cons value
(cons from
(- (point) from
))))))))
2639 (defun custom-face-edit-activate (widget)
2640 "Make face widget WIDGET inactive for user modifications."
2641 (let ((inactive (widget-get widget
:inactive
))
2642 (inhibit-read-only t
)
2643 (inhibit-modification-hooks t
))
2644 (when (consp inactive
)
2646 (goto-char (car (cdr inactive
)))
2647 (delete-region (point) (+ (point) (cdr (cdr inactive
))))
2648 (widget-put widget
:inactive nil
)
2649 (widget-apply widget
:create
)
2650 (widget-value-set widget
(car inactive
))
2653 (defun custom-face-edit-delete (widget)
2654 "Remove widget from the buffer."
2655 (let ((inactive (widget-get widget
:inactive
))
2656 (inhibit-read-only t
)
2657 (inhibit-modification-hooks t
))
2659 ;; Widget is alive, we don't have to do anything special
2660 (widget-default-delete widget
)
2661 ;; WIDGET is already deleted because we did so to inactivate it;
2662 ;; now just get rid of the label we put in its place.
2663 (delete-region (car (cdr inactive
))
2664 (+ (car (cdr inactive
)) (cdr (cdr inactive
))))
2665 (widget-put widget
:inactive nil
))))
2668 (defun custom-face-edit-attribute-tag (widget)
2669 "Returns the first :tag property in WIDGET or one of its children."
2670 (let ((tag (widget-get widget
:tag
)))
2671 (or (and (not (equal tag
"")) tag
)
2672 (let ((children (widget-get widget
:children
)))
2673 (while (and (null tag
) children
)
2674 (setq tag
(custom-face-edit-attribute-tag (pop children
))))
2677 ;;; The `custom-display' Widget.
2679 (define-widget 'custom-display
'menu-choice
2680 "Select a display type."
2683 :help-echo
"Specify frames where the face attributes should be used."
2684 :args
'((const :tag
"all" t
)
2688 :args
((group :sibling-args
(:help-echo
"\
2689 Only match the specified window systems.")
2690 (const :format
"Type: "
2692 (checklist :inline t
2695 :sibling-args
(:help-echo
"\
2696 The X11 Window System.")
2698 (const :format
"PM "
2699 :sibling-args
(:help-echo
"\
2700 OS/2 Presentation Manager.")
2702 (const :format
"W32 "
2703 :sibling-args
(:help-echo
"\
2706 (const :format
"MAC "
2707 :sibling-args
(:help-echo
"\
2710 (const :format
"DOS "
2711 :sibling-args
(:help-echo
"\
2714 (const :format
"TTY%n"
2715 :sibling-args
(:help-echo
"\
2716 Plain text terminals.")
2718 (group :sibling-args
(:help-echo
"\
2719 Only match the frames with the specified color support.")
2720 (const :format
"Class: "
2722 (checklist :inline t
2724 (const :format
"Color "
2725 :sibling-args
(:help-echo
"\
2726 Match color frames.")
2728 (const :format
"Grayscale "
2729 :sibling-args
(:help-echo
"\
2730 Match grayscale frames.")
2732 (const :format
"Monochrome%n"
2733 :sibling-args
(:help-echo
"\
2734 Match frames with no color support.")
2736 (group :sibling-args
(:help-echo
"\
2737 Only match frames with the specified intensity.")
2739 Background brightness: "
2741 (checklist :inline t
2743 (const :format
"Light "
2744 :sibling-args
(:help-echo
"\
2745 Match frames with light backgrounds.")
2747 (const :format
"Dark\n"
2748 :sibling-args
(:help-echo
"\
2749 Match frames with dark backgrounds.")
2751 (group :sibling-args
(:help-echo
"\
2752 Only match frames that support the specified face attributes.")
2753 (const :format
"Supports attributes:" supports
)
2754 (custom-face-edit :inline t
:format
"%n%v"))))))
2756 ;;; The `custom-face' Widget.
2758 (defface custom-face-tag-face
2759 `((t (:weight bold
:height
1.2 :inherit variable-pitch
)))
2760 "Face used for face tags."
2761 :group
'custom-faces
)
2763 (defcustom custom-face-default-form
'selected
2764 "Default form of displaying face definition."
2765 :type
'(choice (const all
)
2768 :group
'custom-buffer
2771 (define-widget 'custom-face
'custom
2773 :sample-face
'custom-face-tag-face
2774 :help-echo
"Set or reset this face."
2775 :documentation-property
#'face-doc-string
2776 :value-create
'custom-face-value-create
2777 :action
'custom-face-action
2778 :custom-category
'face
2779 :custom-form nil
; defaults to value of `custom-face-default-form'
2780 :custom-set
'custom-face-set
2781 :custom-save
'custom-face-save
2782 :custom-reset-current
'custom-redraw
2783 :custom-reset-saved
'custom-face-reset-saved
2784 :custom-reset-standard
'custom-face-reset-standard
2785 :custom-standard-value
'custom-face-standard-value
2786 :custom-menu
'custom-face-menu-create
)
2788 (define-widget 'custom-face-all
'editable-list
2789 "An editable list of display specifications and attributes."
2790 :entry-format
"%i %d %v"
2791 :insert-button-args
'(:help-echo
"Insert new display specification here.")
2792 :append-button-args
'(:help-echo
"Append new display specification here.")
2793 :delete-button-args
'(:help-echo
"Delete this display specification.")
2794 :args
'((group :format
"%v" custom-display custom-face-edit
)))
2796 (defconst custom-face-all
(widget-convert 'custom-face-all
)
2797 "Converted version of the `custom-face-all' widget.")
2799 (define-widget 'custom-display-unselected
'item
2800 "A display specification that doesn't match the selected display."
2801 :match
'custom-display-unselected-match
)
2803 (defun custom-display-unselected-match (widget value
)
2804 "Non-nil if VALUE is an unselected display specification."
2805 (not (face-spec-set-match-display value
(selected-frame))))
2807 (define-widget 'custom-face-selected
'group
2808 "Edit the attributes of the selected display in a face specification."
2809 :args
'((repeat :format
""
2811 (group custom-display-unselected sexp
))
2812 (group (sexp :format
"") custom-face-edit
)
2817 (defconst custom-face-selected
(widget-convert 'custom-face-selected
)
2818 "Converted version of the `custom-face-selected' widget.")
2820 (defun custom-filter-face-spec (spec filter-index
&optional default-filter
)
2821 "Return a canonicalized version of SPEC using.
2822 FILTER-INDEX is the index in the entry for each attribute in
2823 `custom-face-attributes' at which the appropriate filter function can be
2824 found, and DEFAULT-FILTER is the filter to apply for attributes that
2826 (mapcar (lambda (entry)
2827 ;; Filter a single face-spec entry
2828 (let ((tests (car entry
))
2830 ;; Handle both old- and new-style attribute syntax
2831 (if (listp (car (cdr entry
)))
2834 (filtered-attrs nil
))
2835 ;; Filter each face attribute
2836 (while unfiltered-attrs
2837 (let* ((attr (pop unfiltered-attrs
))
2838 (pre-filtered-value (pop unfiltered-attrs
))
2840 (or (nth filter-index
(assq attr custom-face-attributes
))
2844 (funcall filter pre-filtered-value
)
2845 pre-filtered-value
)))
2846 (push filtered-value filtered-attrs
)
2847 (push attr filtered-attrs
)))
2849 (list tests filtered-attrs
)))
2852 (defun custom-pre-filter-face-spec (spec)
2853 "Return SPEC changed as necessary for editing by the face customization widget.
2854 SPEC must be a full face spec."
2855 (custom-filter-face-spec spec
2))
2857 (defun custom-post-filter-face-spec (spec)
2858 "Return the customized SPEC in a form suitable for setting the face."
2859 (custom-filter-face-spec spec
3))
2861 (defun custom-face-value-create (widget)
2862 "Create a list of the display specifications for WIDGET."
2863 (let ((buttons (widget-get widget
:buttons
))
2865 (symbol (widget-get widget
:value
))
2866 (tag (widget-get widget
:tag
))
2867 (state (widget-get widget
:custom-state
))
2869 (is-last (widget-get widget
:custom-last
))
2870 (prefix (widget-get widget
:custom-prefix
)))
2872 (setq tag
(prin1-to-string symbol
)))
2873 (cond ((eq custom-buffer-style
'tree
)
2874 (insert prefix
(if is-last
" `--- " " |--- "))
2875 (push (widget-create-child-and-convert
2876 widget
'custom-browse-face-tag
)
2878 (insert " " tag
"\n")
2879 (widget-put widget
:buttons buttons
))
2883 (widget-specify-sample widget begin
(point))
2884 (if (eq custom-buffer-style
'face
)
2886 (if (string-match "face\\'" tag
)
2888 (insert " face: ")))
2890 (push (widget-create-child-and-convert widget
'item
2897 (push (widget-create-child-and-convert
2899 :help-echo
"Hide or show this face."
2902 :action
'custom-toggle-parent
2903 (not (eq state
'hidden
)))
2907 (let ((magic (widget-create-child-and-convert
2908 widget
'custom-magic nil
)))
2909 (widget-put widget
:custom-magic magic
)
2910 (push magic buttons
))
2912 (widget-put widget
:buttons buttons
)
2913 ;; Insert documentation.
2914 (widget-default-format-handler widget ?h
)
2915 ;; The comment field
2916 (unless (eq state
'hidden
)
2917 (let* ((comment (get symbol
'face-comment
))
2919 (widget-create-child-and-convert
2920 widget
'custom-comment
2922 :value
(or comment
""))))
2923 (widget-put widget
:comment-widget comment-widget
)
2924 (push comment-widget children
)))
2926 (unless (eq state
'hidden
)
2927 (when (eq (widget-get widget
:custom-level
) 1)
2928 (custom-add-parent-links widget
))
2929 (custom-add-see-also widget
))
2931 (unless (eq (preceding-char) ?
\n)
2933 (unless (eq state
'hidden
)
2934 (message "Creating face editor...")
2935 (custom-load-widget widget
)
2936 (unless (widget-get widget
:custom-form
)
2937 (widget-put widget
:custom-form custom-face-default-form
))
2938 (let* ((symbol (widget-value widget
))
2939 (spec (or (get symbol
'customized-face
)
2940 (get symbol
'saved-face
)
2941 (get symbol
'face-defface-spec
)
2942 ;; Attempt to construct it.
2943 (list (list t
(custom-face-attributes-get
2944 symbol
(selected-frame))))))
2945 (form (widget-get widget
:custom-form
))
2946 (indent (widget-get widget
:indent
))
2948 ;; If the user has changed this face in some other way,
2949 ;; edit it as the user has specified it.
2950 (if (not (face-spec-match-p symbol spec
(selected-frame)))
2951 (setq spec
(list (list t
(face-attr-construct symbol
(selected-frame))))))
2952 (setq spec
(custom-pre-filter-face-spec spec
))
2953 (setq edit
(widget-create-child-and-convert
2955 (cond ((and (eq form
'selected
)
2956 (widget-apply custom-face-selected
2958 (when indent
(insert-char ?\ indent
))
2959 'custom-face-selected
)
2960 ((and (not (eq form
'lisp
))
2961 (widget-apply custom-face-all
2965 (when indent
(insert-char ?\ indent
))
2968 (custom-face-state-set widget
)
2969 (push edit children
)
2970 (widget-put widget
:children children
))
2971 (message "Creating face editor...done"))))))
2973 (defvar custom-face-menu
2974 '(("Set for Current Session" custom-face-set
)
2975 ("Save for Future Sessions" custom-face-save-command
)
2976 ("Reset to Saved" custom-face-reset-saved
2978 (or (get (widget-value widget
) 'saved-face
)
2979 (get (widget-value widget
) 'saved-face-comment
))))
2980 ("Erase Customization" custom-face-reset-standard
2982 (get (widget-value widget
) 'face-defface-spec
)))
2983 ("---" ignore ignore
)
2984 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
2985 ("---" ignore ignore
)
2986 ("Show all display specs" custom-face-edit-all
2988 (not (eq (widget-get widget
:custom-form
) 'all
))))
2989 ("Just current attributes" custom-face-edit-selected
2991 (not (eq (widget-get widget
:custom-form
) 'selected
))))
2992 ("Show as Lisp expression" custom-face-edit-lisp
2994 (not (eq (widget-get widget
:custom-form
) 'lisp
)))))
2995 "Alist of actions for the `custom-face' widget.
2996 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2997 the menu entry, ACTION is the function to call on the widget when the
2998 menu is selected, and FILTER is a predicate which takes a `custom-face'
2999 widget as an argument, and returns non-nil if ACTION is valid on that
3000 widget. If FILTER is nil, ACTION is always valid.")
3002 (defun custom-face-edit-selected (widget)
3003 "Edit selected attributes of the value of WIDGET."
3004 (widget-put widget
:custom-state
'unknown
)
3005 (widget-put widget
:custom-form
'selected
)
3006 (custom-redraw widget
))
3008 (defun custom-face-edit-all (widget)
3009 "Edit all attributes of the value of WIDGET."
3010 (widget-put widget
:custom-state
'unknown
)
3011 (widget-put widget
:custom-form
'all
)
3012 (custom-redraw widget
))
3014 (defun custom-face-edit-lisp (widget)
3015 "Edit the Lisp representation of the value of WIDGET."
3016 (widget-put widget
:custom-state
'unknown
)
3017 (widget-put widget
:custom-form
'lisp
)
3018 (custom-redraw widget
))
3020 (defun custom-face-state-set (widget)
3021 "Set the state of WIDGET."
3022 (let* ((symbol (widget-value widget
))
3023 (comment (get symbol
'face-comment
))
3027 (setq tmp
(get symbol
'customized-face
))
3028 (setq temp
(get symbol
'customized-face-comment
))
3030 (if (equal temp comment
)
3034 (setq tmp
(get symbol
'saved-face
))
3035 (setq temp
(get symbol
'saved-face-comment
))
3037 (if (equal temp comment
)
3040 ((get symbol
'face-defface-spec
)
3041 (if (equal comment nil
)
3046 ;; If the user called set-face-attribute to change the default
3047 ;; for new frames, this face is "set outside of Customize".
3048 (if (and (not (eq state
'rogue
))
3049 (get symbol
'face-modified
))
3050 (setq state
'changed
))
3051 (widget-put widget
:custom-state state
)))
3053 (defun custom-face-action (widget &optional event
)
3054 "Show the menu for `custom-face' WIDGET.
3055 Optional EVENT is the location for the menu."
3056 (if (eq (widget-get widget
:custom-state
) 'hidden
)
3057 (custom-toggle-hide widget
)
3058 (let* ((completion-ignore-case t
)
3059 (symbol (widget-get widget
:value
))
3060 (answer (widget-choose (concat "Operation on "
3061 (custom-unlispify-tag-name symbol
))
3062 (custom-menu-filter custom-face-menu
3066 (funcall answer widget
)))))
3068 (defun custom-face-set (widget)
3069 "Make the face attributes in WIDGET take effect."
3070 (let* ((symbol (widget-value widget
))
3071 (child (car (widget-get widget
:children
)))
3072 (value (custom-post-filter-face-spec (widget-value child
)))
3073 (comment-widget (widget-get widget
:comment-widget
))
3074 (comment (widget-value comment-widget
)))
3075 (when (equal comment
"")
3077 ;; Make the comment invisible by hand if it's empty
3078 (custom-comment-hide comment-widget
))
3079 (put symbol
'customized-face value
)
3080 (if (face-spec-choose value
)
3081 (face-spec-set symbol value
)
3082 ;; face-set-spec ignores empty attribute lists, so just give it
3083 ;; something harmless instead.
3084 (face-spec-set symbol
'((t :foreground unspecified
))))
3085 (put symbol
'customized-face-comment comment
)
3086 (put symbol
'face-comment comment
)
3087 (custom-face-state-set widget
)
3088 (custom-redraw-magic widget
)))
3090 (defun custom-face-save-command (widget)
3091 "Save in `.emacs' the face attributes in WIDGET."
3092 (custom-face-save widget
)
3095 (defun custom-face-save (widget)
3096 "Prepare for saving WIDGET's face attributes, but don't write `.emacs'."
3097 (let* ((symbol (widget-value widget
))
3098 (child (car (widget-get widget
:children
)))
3099 (value (custom-post-filter-face-spec (widget-value child
)))
3100 (comment-widget (widget-get widget
:comment-widget
))
3101 (comment (widget-value comment-widget
)))
3102 (when (equal comment
"")
3104 ;; Make the comment invisible by hand if it's empty
3105 (custom-comment-hide comment-widget
))
3106 (if (face-spec-choose value
)
3107 (face-spec-set symbol value
)
3108 ;; face-set-spec ignores empty attribute lists, so just give it
3109 ;; something harmless instead.
3110 (face-spec-set symbol
'((t :foreground unspecified
))))
3111 (unless (eq (widget-get widget
:custom-state
) 'standard
)
3112 (put symbol
'saved-face value
))
3113 (custom-push-theme 'theme-face symbol
'user
'set value
)
3114 (put symbol
'customized-face nil
)
3115 (put symbol
'face-comment comment
)
3116 (put symbol
'customized-face-comment nil
)
3117 (put symbol
'saved-face-comment comment
)
3119 (custom-face-state-set widget
)
3120 (custom-redraw-magic widget
)))
3122 (defun custom-face-reset-saved (widget)
3123 "Restore WIDGET to the face's default attributes."
3124 (let* ((symbol (widget-value widget
))
3125 (child (car (widget-get widget
:children
)))
3126 (value (get symbol
'saved-face
))
3127 (comment (get symbol
'saved-face-comment
))
3128 (comment-widget (widget-get widget
:comment-widget
)))
3129 (unless (or value comment
)
3130 (error "No saved value for this face"))
3131 (put symbol
'customized-face nil
)
3132 (put symbol
'customized-face-comment nil
)
3133 (face-spec-set symbol value
)
3134 (put symbol
'face-comment comment
)
3135 (widget-value-set child value
)
3136 ;; This call manages the comment visibility
3137 (widget-value-set comment-widget
(or comment
""))
3138 (custom-face-state-set widget
)
3139 (custom-redraw-magic widget
)))
3141 (defun custom-face-standard-value (widget)
3142 (get (widget-value widget
) 'face-defface-spec
))
3144 (defun custom-face-reset-standard (widget)
3145 "Restore WIDGET to the face's standard settings.
3146 This operation eliminates any saved setting for the face,
3147 restoring it to the state of a face that has never been customized."
3148 (let* ((symbol (widget-value widget
))
3149 (child (car (widget-get widget
:children
)))
3150 (value (get symbol
'face-defface-spec
))
3151 (comment-widget (widget-get widget
:comment-widget
)))
3153 (error "No standard setting for this face"))
3154 (put symbol
'customized-face nil
)
3155 (put symbol
'customized-face-comment nil
)
3156 (when (or (get symbol
'saved-face
) (get symbol
'saved-face-comment
))
3157 (put symbol
'saved-face nil
)
3158 (custom-push-theme 'theme-face symbol
'user
'reset
'standard
)
3159 ;; Do not explictly save resets to standards without themes.
3160 (if (null (cdr (get symbol
'theme-face
)))
3161 (put symbol
'theme-face nil
))
3162 (put symbol
'saved-face-comment nil
)
3164 (face-spec-set symbol value
)
3165 (put symbol
'face-comment nil
)
3166 (widget-value-set child value
)
3167 ;; This call manages the comment visibility
3168 (widget-value-set comment-widget
"")
3169 (custom-face-state-set widget
)
3170 (custom-redraw-magic widget
)))
3172 ;;; The `face' Widget.
3174 (define-widget 'face
'default
3175 "Select and customize a face."
3176 :convert-widget
'widget-value-convert-widget
3177 :button-prefix
'widget-push-button-prefix
3178 :button-suffix
'widget-push-button-suffix
3179 :format
"%{%t%}: %[select face%] %v"
3182 :value-create
'widget-face-value-create
3183 :value-delete
'widget-face-value-delete
3184 :value-get
'widget-value-value-get
3185 :validate
'widget-children-validate
3186 :action
'widget-face-action
3187 :match
(lambda (widget value
) (symbolp value
)))
3189 (defun widget-face-value-create (widget)
3190 "Create a `custom-face' child."
3191 (let* ((symbol (widget-value widget
))
3192 (custom-buffer-style 'face
)
3193 (child (widget-create-child-and-convert
3197 (custom-magic-reset child
)
3198 (setq custom-options
(cons child custom-options
))
3199 (widget-put widget
:children
(list child
))))
3201 (defun widget-face-value-delete (widget)
3202 "Remove the child from the options."
3203 (let ((child (car (widget-get widget
:children
))))
3204 (setq custom-options
(delq child custom-options
))
3205 (widget-children-value-delete widget
)))
3207 (defvar face-history nil
3208 "History of entered face names.")
3210 (defun widget-face-action (widget &optional event
)
3211 "Prompt for a face."
3212 (let ((answer (completing-read "Face: "
3213 (mapcar (lambda (face)
3214 (list (symbol-name face
)))
3218 (unless (zerop (length answer
))
3219 (widget-value-set widget
(intern answer
))
3220 (widget-apply widget
:notify widget event
)
3223 ;;; The `hook' Widget.
3225 (define-widget 'hook
'list
3227 :value-to-internal
(lambda (widget value
)
3228 (if (and value
(symbolp value
))
3231 :match
(lambda (widget value
)
3233 (widget-group-match widget value
)))
3234 ;; Avoid adding undefined functions to the hook, especially for
3235 ;; things like `find-file-hook' or even more basic ones, to avoid
3237 :set
(lambda (symbol value
)
3240 (add-hook symbol elt
))))
3241 :convert-widget
'custom-hook-convert-widget
3244 (defun custom-hook-convert-widget (widget)
3245 ;; Handle `:options'.
3246 (let* ((options (widget-get widget
:options
))
3247 (other `(editable-list :inline t
3248 :entry-format
"%i %d%v"
3249 (function :format
" %v")))
3251 (list `(checklist :inline t
3252 ,@(mapcar (lambda (entry)
3253 `(function-item ,entry
))
3257 (widget-put widget
:args args
)
3260 ;;; The `custom-group-link' Widget.
3262 (define-widget 'custom-group-link
'link
3263 "Show parent in other window when activated."
3264 :help-echo
"Create customization buffer for this group."
3265 :action
'custom-group-link-action
)
3267 (defun custom-group-link-action (widget &rest ignore
)
3268 (customize-group (widget-value widget
)))
3270 ;;; The `custom-group' Widget.
3272 (defcustom custom-group-tag-faces nil
3273 ;; In XEmacs, this ought to play games with font size.
3274 ;; Fixme: make it do so in Emacs.
3275 "Face used for group tags.
3276 The first member is used for level 1 groups, the second for level 2,
3277 and so forth. The remaining group tags are shown with
3278 `custom-group-tag-face'."
3279 :type
'(repeat face
)
3280 :group
'custom-faces
)
3282 (defface custom-group-tag-face-1
3285 (:foreground
"pink" :weight bold
:height
1.2 :inherit variable-pitch
))
3288 (:foreground
"red" :weight bold
:height
1.2 :inherit variable-pitch
))
3290 "Face used for group tags."
3291 :group
'custom-faces
)
3293 (defface custom-group-tag-face
3296 (:foreground
"light blue" :weight bold
:height
1.2))
3299 (:foreground
"blue" :weight bold
:height
1.2))
3301 "Face used for low level group tags."
3302 :group
'custom-faces
)
3304 (define-widget 'custom-group
'custom
3307 :sample-face-get
'custom-group-sample-face-get
3308 :documentation-property
'group-documentation
3309 :help-echo
"Set or reset all members of this group."
3310 :value-create
'custom-group-value-create
3311 :action
'custom-group-action
3312 :custom-category
'group
3313 :custom-set
'custom-group-set
3314 :custom-save
'custom-group-save
3315 :custom-reset-current
'custom-group-reset-current
3316 :custom-reset-saved
'custom-group-reset-saved
3317 :custom-reset-standard
'custom-group-reset-standard
3318 :custom-menu
'custom-group-menu-create
)
3320 (defun custom-group-sample-face-get (widget)
3321 ;; Use :sample-face.
3322 (or (nth (1- (widget-get widget
:custom-level
)) custom-group-tag-faces
)
3323 'custom-group-tag-face
))
3325 (define-widget 'custom-group-visibility
'visibility
3326 "An indicator and manipulator for hidden group contents."
3327 :create
'custom-group-visibility-create
)
3329 (defun custom-group-visibility-create (widget)
3330 (let ((visible (widget-value widget
)))
3332 (insert "--------")))
3333 (widget-default-create widget
))
3335 (defun custom-group-members (symbol groups-only
)
3336 "Return SYMBOL's custom group members.
3337 If GROUPS-ONLY non-nil, return only those members that are groups."
3338 (if (not groups-only
)
3339 (get symbol
'custom-group
)
3341 (dolist (entry (get symbol
'custom-group
))
3342 (when (eq (nth 1 entry
) 'custom-group
)
3343 (push entry members
)))
3344 (nreverse members
))))
3346 (defun custom-group-value-create (widget)
3347 "Insert a customize group for WIDGET in the current buffer."
3348 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
3349 (custom-load-widget widget
))
3350 (let* ((state (widget-get widget
:custom-state
))
3351 (level (widget-get widget
:custom-level
))
3352 ;; (indent (widget-get widget :indent))
3353 (prefix (widget-get widget
:custom-prefix
))
3354 (buttons (widget-get widget
:buttons
))
3355 (tag (widget-get widget
:tag
))
3356 (symbol (widget-value widget
))
3357 (members (custom-group-members symbol
3358 (and (eq custom-buffer-style
'tree
)
3359 custom-browse-only-groups
))))
3360 (cond ((and (eq custom-buffer-style
'tree
)
3362 (or members
(custom-unloaded-widget-p widget
)))
3363 (custom-browse-insert-prefix prefix
)
3364 (push (widget-create-child-and-convert
3365 widget
'custom-browse-visibility
3366 ;; :tag-glyph "plus"
3370 ;; (widget-glyph-insert nil "-- " "horizontal")
3371 (push (widget-create-child-and-convert
3372 widget
'custom-browse-group-tag
)
3374 (insert " " tag
"\n")
3375 (widget-put widget
:buttons buttons
))
3376 ((and (eq custom-buffer-style
'tree
)
3377 (zerop (length members
)))
3378 (custom-browse-insert-prefix prefix
)
3380 ;; (widget-glyph-insert nil "[ ]" "empty")
3381 ;; (widget-glyph-insert nil "-- " "horizontal")
3382 (push (widget-create-child-and-convert
3383 widget
'custom-browse-group-tag
)
3385 (insert " " tag
"\n")
3386 (widget-put widget
:buttons buttons
))
3387 ((eq custom-buffer-style
'tree
)
3388 (custom-browse-insert-prefix prefix
)
3389 (if (zerop (length members
))
3391 (custom-browse-insert-prefix prefix
)
3393 ;; (widget-glyph-insert nil "[ ]" "empty")
3394 ;; (widget-glyph-insert nil "-- " "horizontal")
3395 (push (widget-create-child-and-convert
3396 widget
'custom-browse-group-tag
)
3398 (insert " " tag
"\n")
3399 (widget-put widget
:buttons buttons
))
3400 (push (widget-create-child-and-convert
3401 widget
'custom-browse-visibility
3402 ;; :tag-glyph "minus"
3406 ;; (widget-glyph-insert nil "-\\ " "top")
3407 (push (widget-create-child-and-convert
3408 widget
'custom-browse-group-tag
)
3410 (insert " " tag
"\n")
3411 (widget-put widget
:buttons buttons
)
3412 (message "Creating group...")
3413 (let* ((members (custom-sort-items members
3414 custom-browse-sort-alphabetically
3415 custom-browse-order-groups
))
3416 (prefixes (widget-get widget
:custom-prefixes
))
3417 (custom-prefix-list (custom-prefix-add symbol prefixes
))
3418 (extra-prefix (if (widget-get widget
:custom-last
)
3421 (prefix (concat prefix extra-prefix
))
3424 (setq entry
(car members
)
3425 members
(cdr members
))
3426 (push (widget-create-child-and-convert
3427 widget
(nth 1 entry
)
3429 :tag
(custom-unlispify-tag-name (nth 0 entry
))
3430 :custom-prefixes custom-prefix-list
3431 :custom-level
(1+ level
)
3432 :custom-last
(null members
)
3433 :value
(nth 0 entry
)
3434 :custom-prefix prefix
)
3436 (widget-put widget
:children
(reverse children
)))
3437 (message "Creating group...done")))
3440 ;; Create level indicator.
3441 (unless (eq custom-buffer-style
'links
)
3442 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3445 (let ((begin (point)))
3447 (widget-specify-sample widget begin
(point)))
3449 ;; Create link/visibility indicator.
3450 (if (eq custom-buffer-style
'links
)
3451 (push (widget-create-child-and-convert
3452 widget
'custom-group-link
3456 (push (widget-create-child-and-convert
3457 widget
'custom-group-visibility
3458 :help-echo
"Show members of this group."
3459 :action
'custom-toggle-parent
3460 (not (eq state
'hidden
)))
3463 ;; Create magic button.
3464 (let ((magic (widget-create-child-and-convert
3465 widget
'custom-magic nil
)))
3466 (widget-put widget
:custom-magic magic
)
3467 (push magic buttons
))
3469 (widget-put widget
:buttons buttons
)
3470 ;; Insert documentation.
3471 (if (and (eq custom-buffer-style
'links
) (> level
1))
3472 (widget-put widget
:documentation-indent
0))
3473 (widget-default-format-handler widget ?h
))
3476 ;; Add parent groups references above the group.
3477 (if t
;;; This should test that the buffer
3478 ;;; was made to display a group.
3480 (if (custom-add-parent-links widget
3481 "Go to parent group:")
3483 ;; Create level indicator.
3484 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3487 (let ((start (point)))
3489 (widget-specify-sample widget start
(point)))
3491 ;; Create visibility indicator.
3492 (unless (eq custom-buffer-style
'links
)
3494 (push (widget-create-child-and-convert
3496 :help-echo
"Hide members of this group."
3497 :action
'custom-toggle-parent
3498 (not (eq state
'hidden
)))
3501 ;; Create more dashes.
3502 ;; Use 76 instead of 75 to compensate for the temporary "<"
3503 ;; added by `widget-insert'.
3504 (insert-char ?-
(- 76 (current-column)
3505 (* custom-buffer-indent level
)))
3507 ;; Create magic button.
3508 (let ((magic (widget-create-child-and-convert
3509 widget
'custom-magic
3512 (widget-put widget
:custom-magic magic
)
3513 (push magic buttons
))
3515 (widget-put widget
:buttons buttons
)
3516 ;; Insert documentation.
3517 (widget-default-format-handler widget ?h
)
3519 (if nil
;;; This should test that the buffer
3520 ;;; was not made to display a group.
3522 (insert-char ?\ custom-buffer-indent
)
3523 (custom-add-parent-links widget
)))
3524 (custom-add-see-also widget
3525 (make-string (* custom-buffer-indent level
)
3528 (message "Creating group...")
3529 (let* ((members (custom-sort-items members
3530 custom-buffer-sort-alphabetically
3531 custom-buffer-order-groups
))
3532 (prefixes (widget-get widget
:custom-prefixes
))
3533 (custom-prefix-list (custom-prefix-add symbol prefixes
))
3534 (length (length members
))
3536 (children (mapcar (lambda (entry)
3537 (widget-insert "\n")
3539 Creating group members... %2d%%"
3540 (/ (* 100.0 count
) length
))
3541 (setq count
(1+ count
))
3543 (widget-create-child-and-convert
3544 widget
(nth 1 entry
)
3546 :tag
(custom-unlispify-tag-name
3548 :custom-prefixes custom-prefix-list
3549 :custom-level
(1+ level
)
3550 :value
(nth 0 entry
))
3551 (unless (eq (preceding-char) ?
\n)
3552 (widget-insert "\n"))))
3554 (message "Creating group magic...")
3555 (mapc 'custom-magic-reset children
)
3556 (message "Creating group state...")
3557 (widget-put widget
:children children
)
3558 (custom-group-state-update widget
)
3559 (message "Creating group... done"))
3562 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3563 (insert "\\- " (widget-get widget
:tag
) " group end ")
3564 (insert-char ?-
(- 75 (current-column) (* custom-buffer-indent level
)))
3567 (defvar custom-group-menu
3568 '(("Set for Current Session" custom-group-set
3570 (eq (widget-get widget
:custom-state
) 'modified
)))
3571 ("Save for Future Sessions" custom-group-save
3573 (memq (widget-get widget
:custom-state
) '(modified set
))))
3574 ("Reset to Current" custom-group-reset-current
3576 (memq (widget-get widget
:custom-state
) '(modified))))
3577 ("Reset to Saved" custom-group-reset-saved
3579 (memq (widget-get widget
:custom-state
) '(modified set
))))
3580 ("Reset to standard setting" custom-group-reset-standard
3582 (memq (widget-get widget
:custom-state
) '(modified set saved
)))))
3583 "Alist of actions for the `custom-group' widget.
3584 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3585 the menu entry, ACTION is the function to call on the widget when the
3586 menu is selected, and FILTER is a predicate which takes a `custom-group'
3587 widget as an argument, and returns non-nil if ACTION is valid on that
3588 widget. If FILTER is nil, ACTION is always valid.")
3590 (defun custom-group-action (widget &optional event
)
3591 "Show the menu for `custom-group' WIDGET.
3592 Optional EVENT is the location for the menu."
3593 (if (eq (widget-get widget
:custom-state
) 'hidden
)
3594 (custom-toggle-hide widget
)
3595 (let* ((completion-ignore-case t
)
3596 (answer (widget-choose (concat "Operation on "
3597 (custom-unlispify-tag-name
3598 (widget-get widget
:value
)))
3599 (custom-menu-filter custom-group-menu
3603 (funcall answer widget
)))))
3605 (defun custom-group-set (widget)
3606 "Set changes in all modified group members."
3607 (let ((children (widget-get widget
:children
)))
3608 (mapc (lambda (child)
3609 (when (eq (widget-get child
:custom-state
) 'modified
)
3610 (widget-apply child
:custom-set
)))
3613 (defun custom-group-save (widget)
3614 "Save all modified group members."
3615 (let ((children (widget-get widget
:children
)))
3616 (mapc (lambda (child)
3617 (when (memq (widget-get child
:custom-state
) '(modified set
))
3618 (widget-apply child
:custom-save
)))
3621 (defun custom-group-reset-current (widget)
3622 "Reset all modified group members."
3623 (let ((children (widget-get widget
:children
)))
3624 (mapc (lambda (child)
3625 (when (eq (widget-get child
:custom-state
) 'modified
)
3626 (widget-apply child
:custom-reset-current
)))
3629 (defun custom-group-reset-saved (widget)
3630 "Reset all modified or set group members."
3631 (let ((children (widget-get widget
:children
)))
3632 (mapc (lambda (child)
3633 (when (memq (widget-get child
:custom-state
) '(modified set
))
3634 (widget-apply child
:custom-reset-saved
)))
3637 (defun custom-group-reset-standard (widget)
3638 "Reset all modified, set, or saved group members."
3639 (let ((children (widget-get widget
:children
)))
3640 (mapc (lambda (child)
3641 (when (memq (widget-get child
:custom-state
)
3642 '(modified set saved
))
3643 (widget-apply child
:custom-reset-standard
)))
3646 (defun custom-group-state-update (widget)
3648 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
3649 (let* ((children (widget-get widget
:children
))
3650 (states (mapcar (lambda (child)
3651 (widget-get child
:custom-state
))
3653 (magics custom-magic-alist
)
3656 (let ((magic (car (car magics
))))
3657 (if (and (not (eq magic
'hidden
))
3658 (memq magic states
))
3661 (setq magics
(cdr magics
)))))
3662 (widget-put widget
:custom-state found
)))
3663 (custom-magic-reset widget
))
3665 ;;; The `custom-save-all' Function.
3667 (defcustom custom-file nil
3668 "File used for storing customization information.
3669 The default is nil, which means to use your init file
3670 as specified by `user-init-file'. If you specify some other file,
3671 you need to explicitly load that file for the settings to take effect.
3673 When you change this variable, look in the previous custom file
3674 \(usually your init file) for the forms `(custom-set-variables ...)'
3675 and `(custom-set-faces ...)', and copy them (whichever ones you find)
3676 to the new custom file. This will preserve your existing customizations."
3677 :type
'(choice (const :tag
"Your Emacs init file" nil
) file
)
3680 (defun custom-file ()
3681 "Return the file name for saving customizations."
3684 (let ((user-init-file user-init-file
)
3686 (if (eq system-type
'ms-dos
) "~/_emacs" "~/.emacs")))
3687 (when (null user-init-file
)
3688 (if (or (file-exists-p default-init-file
)
3689 (and (eq system-type
'windows-nt
)
3690 (file-exists-p "~/_emacs")))
3691 ;; Started with -q, i.e. the file containing
3692 ;; Custom settings hasn't been read. Saving
3693 ;; settings there would overwrite other settings.
3694 (error "Saving settings from \"emacs -q\" would overwrite existing customizations"))
3695 (setq user-init-file default-init-file
))
3698 (defun custom-save-delete (symbol)
3699 "Visit `custom-file' and delete all calls to SYMBOL from it.
3700 Leave point at the old location of the first such call,
3701 or (if there were none) at the end of the buffer."
3702 (let ((default-major-mode 'emacs-lisp-mode
))
3703 (set-buffer (find-file-noselect (custom-file))))
3704 (goto-char (point-min))
3705 ;; Skip all whitespace and comments.
3706 (while (forward-comment 1))
3708 (save-excursion (forward-sexp (buffer-size)))) ; Test for scan errors.
3711 (while t
;; We exit this loop only via throw.
3712 ;; Skip all whitespace and comments.
3713 (while (forward-comment 1))
3714 (let ((start (point))
3715 (sexp (condition-case nil
3716 (read (current-buffer))
3717 (end-of-file (throw 'found nil
)))))
3718 (when (and (listp sexp
)
3719 (eq (car sexp
) symbol
))
3720 (delete-region start
(point))
3722 (setq first
(point)))))))
3725 ;; Move in front of local variables, otherwise long Custom
3726 ;; entries would make them ineffective.
3727 (let ((pos (point-max))
3728 (case-fold-search t
))
3730 (goto-char (point-max))
3731 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
3733 (when (search-forward "Local Variables:" nil t
)
3734 (setq pos
(line-beginning-position))))
3737 (defun custom-save-variables ()
3738 "Save all customized variables in `custom-file'."
3740 (custom-save-delete 'custom-load-themes
)
3741 (custom-save-delete 'custom-reset-variables
)
3742 (custom-save-delete 'custom-set-variables
)
3743 (custom-save-loaded-themes)
3744 (custom-save-resets 'theme-value
'custom-reset-variables nil
)
3745 (let ((standard-output (current-buffer))
3746 (saved-list (make-list 1 0))
3748 ;; First create a sorted list of saved variables.
3751 (if (get symbol
'saved-value
)
3752 (nconc saved-list
(list symbol
)))))
3753 (setq saved-list
(sort (cdr saved-list
) 'string
<))
3756 (princ "(custom-set-variables
3757 ;; custom-set-variables was added by Custom.
3758 ;; If you edit it by hand, you could mess it up, so be careful.
3759 ;; Your init file should contain only one such instance.
3760 ;; If there is more than one, they won't work right.\n")
3761 (dolist (symbol saved-list
)
3762 (let ((spec (car-safe (get symbol
'theme-value
)))
3763 (value (get symbol
'saved-value
))
3764 (requests (get symbol
'custom-requests
))
3765 (now (not (or (custom-variable-p symbol
)
3766 (and (not (boundp symbol
))
3767 (not (eq (get symbol
'force-value
)
3769 (comment (get symbol
'saved-variable-comment
)))
3770 ;; Check `requests'.
3771 (dolist (request requests
)
3772 (when (and (symbolp request
) (not (featurep request
)))
3773 (message "Unknown requested feature: %s" request
)
3774 (setq requests
(delq request requests
))))
3776 (eq (nth 0 spec
) 'user
)
3777 (eq (nth 1 spec
) 'set
))
3779 (and (null spec
) (get symbol
'saved-value
)))
3786 (when (or now requests comment
)
3789 (when (or requests comment
)
3799 (unless (looking-at "\n")
3802 (defun custom-save-faces ()
3803 "Save all customized faces in `custom-file'."
3805 (custom-save-delete 'custom-reset-faces
)
3806 (custom-save-delete 'custom-set-faces
)
3807 (custom-save-resets 'theme-face
'custom-reset-faces
'(default))
3808 (let ((standard-output (current-buffer))
3809 (saved-list (make-list 1 0))
3811 ;; First create a sorted list of saved faces.
3814 (if (get symbol
'saved-face
)
3815 (nconc saved-list
(list symbol
)))))
3816 (setq saved-list
(sort (cdr saved-list
) 'string
<))
3817 ;; The default face must be first, since it affects the others.
3818 (if (memq 'default saved-list
)
3819 (setq saved-list
(cons 'default
(delq 'default saved-list
))))
3822 (princ "(custom-set-faces
3823 ;; custom-set-faces was added by Custom.
3824 ;; If you edit it by hand, you could mess it up, so be careful.
3825 ;; Your init file should contain only one such instance.
3826 ;; If there is more than one, they won't work right.\n")
3827 (dolist (symbol saved-list
)
3828 (let ((spec (car-safe (get symbol
'theme-face
)))
3829 (value (get symbol
'saved-face
))
3830 (now (not (or (get symbol
'face-defface-spec
)
3831 (and (not (custom-facep symbol
))
3832 (not (get symbol
'force-face
))))))
3833 (comment (get symbol
'saved-face-comment
)))
3835 (eq (nth 0 spec
) 'user
)
3836 (eq (nth 1 spec
) 'set
))
3838 (and (null spec
) (get symbol
'saved-face
)))
3839 ;; Don't print default face here.
3846 (when (or now comment
)
3856 (unless (looking-at "\n")
3859 (defun custom-save-resets (property setter special
)
3860 (let (started-writing ignored-special
)
3861 ;; (custom-save-delete setter) Done by caller
3862 (let ((standard-output (current-buffer))
3863 (mapper `(lambda (object)
3864 (let ((spec (car-safe (get object
(quote ,property
)))))
3865 (when (and (not (memq object ignored-special
))
3866 (eq (nth 0 spec
) 'user
)
3867 (eq (nth 1 spec
) 'reset
))
3868 ;; Do not write reset statements unless necessary.
3869 (unless started-writing
3870 (setq started-writing t
)
3874 (princ (quote ,setter
))
3878 (prin1 (nth 3 spec
))
3880 (mapc mapper special
)
3881 (setq ignored-special special
)
3883 (when started-writing
3886 (defun custom-save-loaded-themes ()
3887 (let ((themes (reverse (get 'user
'theme-loads-themes
)))
3888 (standard-output (current-buffer)))
3890 (unless (bolp) (princ "\n"))
3891 (princ "(custom-load-themes")
3892 (mapc (lambda (theme)
3894 (prin1 theme
)) themes
)
3898 (defun customize-save-customized ()
3899 "Save all user options which have been set in this session."
3901 (mapatoms (lambda (symbol)
3902 (let ((face (get symbol
'customized-face
))
3903 (value (get symbol
'customized-value
))
3904 (face-comment (get symbol
'customized-face-comment
))
3906 (get symbol
'customized-variable-comment
)))
3908 (put symbol
'saved-face face
)
3909 (custom-push-theme 'theme-face symbol
'user
'set value
)
3910 (put symbol
'customized-face nil
))
3912 (put symbol
'saved-value value
)
3913 (custom-push-theme 'theme-value symbol
'user
'set value
)
3914 (put symbol
'customized-value nil
))
3915 (when variable-comment
3916 (put symbol
'saved-variable-comment variable-comment
)
3917 (put symbol
'customized-variable-comment nil
))
3919 (put symbol
'saved-face-comment face-comment
)
3920 (put symbol
'customized-face-comment nil
)))))
3921 ;; We really should update all custom buffers here.
3925 (defun custom-save-all ()
3926 "Save all customizations in `custom-file'."
3927 (let ((inhibit-read-only t
))
3928 (custom-save-variables)
3931 (let ((default-major-mode nil
))
3932 (set-buffer (find-file-noselect (custom-file))))
3933 (let ((file-precious-flag t
))
3936 ;;; The Customize Menu.
3940 (defcustom custom-menu-nesting
2
3941 "Maximum nesting in custom menus."
3943 :group
'custom-menu
)
3945 (defun custom-face-menu-create (widget symbol
)
3946 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
3947 (vector (custom-unlispify-menu-entry symbol
)
3948 `(customize-face ',symbol
)
3951 (defun custom-variable-menu-create (widget symbol
)
3952 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
3953 (let ((type (get symbol
'custom-type
)))
3954 (unless (listp type
)
3955 (setq type
(list type
)))
3956 (if (and type
(widget-get type
:custom-menu
))
3957 (widget-apply type
:custom-menu symbol
)
3958 (vector (custom-unlispify-menu-entry symbol
)
3959 `(customize-variable ',symbol
)
3962 ;; Add checkboxes to boolean variable entries.
3963 (widget-put (get 'boolean
'widget-type
)
3964 :custom-menu
(lambda (widget symbol
)
3965 (vector (custom-unlispify-menu-entry symbol
)
3966 `(customize-variable ',symbol
)
3968 ':selected symbol
)))
3970 (defun custom-group-menu-create (widget symbol
)
3971 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
3972 `( ,(custom-unlispify-menu-entry symbol t
)
3973 :filter
(lambda (&rest junk
)
3974 (let ((menu (custom-menu-create ',symbol
)))
3975 (if (consp menu
) (cdr menu
) menu
)))))
3978 (defun custom-menu-create (symbol)
3979 "Create menu for customization group SYMBOL.
3980 The menu is in a format applicable to `easy-menu-define'."
3981 (let* ((item (vector (custom-unlispify-menu-entry symbol
)
3982 `(customize-group ',symbol
)
3984 (if (and (or (not (boundp 'custom-menu-nesting
))
3985 (>= custom-menu-nesting
0))
3987 (custom-load-symbol symbol
)
3988 (< (length (get symbol
'custom-group
)) widget-menu-max-size
)))
3989 (let ((custom-prefix-list (custom-prefix-add symbol
3990 custom-prefix-list
))
3991 (members (custom-sort-items (get symbol
'custom-group
)
3992 custom-menu-sort-alphabetically
3993 custom-menu-order-groups
)))
3994 `(,(custom-unlispify-menu-entry symbol t
)
3997 ,@(mapcar (lambda (entry)
3998 (widget-apply (if (listp (nth 1 entry
))
4000 (list (nth 1 entry
)))
4001 :custom-menu
(nth 0 entry
)))
4006 (defun customize-menu-create (symbol &optional name
)
4007 "Return a customize menu for customization group SYMBOL.
4008 If optional NAME is given, use that as the name of the menu.
4009 Otherwise the menu will be named `Customize'.
4010 The format is suitable for use with `easy-menu-define'."
4012 (setq name
"Customize"))
4014 :filter
(lambda (&rest junk
)
4015 (let ((menu (custom-menu-create ',symbol
)))
4016 (if (consp menu
) (cdr menu
) menu
)))))
4018 ;;; The Custom Mode.
4020 (defvar custom-mode-map nil
4021 "Keymap for `custom-mode'.")
4023 (unless custom-mode-map
4024 ;; This keymap should be dense, but a dense keymap would prevent inheriting
4025 ;; "\r" bindings from the parent map.
4026 (setq custom-mode-map
(make-sparse-keymap))
4027 (set-keymap-parent custom-mode-map widget-keymap
)
4028 (suppress-keymap custom-mode-map
)
4029 (define-key custom-mode-map
" " 'scroll-up
)
4030 (define-key custom-mode-map
"\177" 'scroll-down
)
4031 (define-key custom-mode-map
"q" 'Custom-buffer-done
)
4032 (define-key custom-mode-map
"u" 'Custom-goto-parent
)
4033 (define-key custom-mode-map
"n" 'widget-forward
)
4034 (define-key custom-mode-map
"p" 'widget-backward
)
4035 (define-key custom-mode-map
[mouse-1
] 'Custom-move-and-invoke
))
4037 (defun Custom-move-and-invoke (event)
4038 "Move to where you click, and if it is an active field, invoke it."
4040 (mouse-set-point event
)
4041 (if (widget-event-point event
)
4042 (let* ((pos (widget-event-point event
))
4043 (button (get-char-property pos
'button
)))
4045 (widget-button-click event
)))))
4047 (easy-menu-define Custom-mode-menu
4049 "Menu used in customization buffers."
4051 ,(customize-menu-create 'customize
)
4052 ["Set" Custom-set t
]
4053 ["Save" Custom-save t
]
4054 ["Reset to Current" Custom-reset-current t
]
4055 ["Reset to Saved" Custom-reset-saved t
]
4056 ["Reset to Standard Settings" Custom-reset-standard t
]
4057 ["Info" (Info-goto-node "(emacs)Easy Customization") t
]))
4059 (defun Custom-goto-parent ()
4060 "Go to the parent group listed at the top of this buffer.
4061 If several parents are listed, go to the first of them."
4064 (goto-char (point-min))
4065 (if (search-forward "\nGo to parent group: " nil t
)
4066 (let* ((button (get-char-property (point) 'button
))
4067 (parent (downcase (widget-get button
:tag
))))
4068 (customize-group parent
)))))
4070 (defcustom custom-mode-hook nil
4071 "Hook called when entering Custom mode."
4073 :group
'custom-buffer
)
4075 (defun custom-state-buffer-message (widget)
4076 (if (eq (widget-get (widget-get widget
:parent
) :custom-state
) 'modified
)
4077 (message "To install your edits, invoke [State] and choose the Set operation")))
4079 (defun custom-mode ()
4080 "Major mode for editing customization buffers.
4082 The following commands are available:
4084 Move to next button or editable field. \\[widget-forward]
4085 Move to previous button or editable field. \\[widget-backward]
4086 \\<widget-field-keymap>\
4087 Complete content of editable text field. \\[widget-complete]
4088 \\<custom-mode-map>\
4089 Invoke button under the mouse pointer. \\[Custom-move-and-invoke]
4090 Invoke button under point. \\[widget-button-press]
4091 Set all modifications. \\[Custom-set]
4092 Make all modifications default. \\[Custom-save]
4093 Reset all modified options. \\[Custom-reset-current]
4094 Reset all modified or set options. \\[Custom-reset-saved]
4095 Reset all options. \\[Custom-reset-standard]
4097 Entry to this mode calls the value of `custom-mode-hook'
4098 if that value is non-nil."
4099 (kill-all-local-variables)
4100 (setq major-mode
'custom-mode
4102 (use-local-map custom-mode-map
)
4103 (easy-menu-add Custom-mode-menu
)
4104 (make-local-variable 'custom-options
)
4105 (make-local-variable 'custom-local-buffer
)
4106 (make-local-variable 'widget-documentation-face
)
4107 (setq widget-documentation-face
'custom-documentation-face
)
4108 (make-local-variable 'widget-button-face
)
4109 (setq widget-button-face
'custom-button-face
)
4110 (set (make-local-variable 'widget-button-pressed-face
)
4111 'custom-button-pressed-face
)
4112 (set (make-local-variable 'widget-mouse-face
)
4113 'custom-button-pressed-face
) ; buttons `depress' when moused
4114 ;; When possible, use relief for buttons, not bracketing. This test
4115 ;; may not be optimal.
4116 (when custom-raised-buttons
4117 (set (make-local-variable 'widget-push-button-prefix
) "")
4118 (set (make-local-variable 'widget-push-button-suffix
) "")
4119 (set (make-local-variable 'widget-link-prefix
) "")
4120 (set (make-local-variable 'widget-link-suffix
) ""))
4121 (add-hook 'widget-edit-functions
'custom-state-buffer-message nil t
)
4122 (run-hooks 'custom-mode-hook
))
4124 (put 'custom-mode
'mode-class
'special
)
4127 'debug-ignored-errors
4128 "^No user options have changed defaults in recent Emacs versions$")
4134 ;;; arch-tag: 64533aa4-1b1a-48c3-8812-f9dc718e8a6f
4135 ;;; cus-edit.el ends here