1 ;;; cus-edit.el --- tools for customizing Emacs and Lisp packages
3 ;; Copyright (C) 1996,97,1999,2000,01,02,03,2004 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."
289 (defgroup editing-basics nil
290 "Most basic editing facilities."
293 (defgroup display nil
294 "How characters are displayed in buffers."
297 (defgroup execute nil
298 "Executing external commands."
301 (defgroup installation nil
302 "The Emacs installation."
310 "Internal Emacs limits."
314 "Debugging Emacs itself."
317 (defgroup minibuffer nil
318 "Controling the behaviour of the minibuffer."
319 :link
'(custom-manual "(emacs)Minibuffer")
322 (defgroup keyboard nil
323 "Input from the keyboard."
327 "Input from the mouse."
331 "Input from the menus."
334 (defgroup auto-save nil
335 "Preventing accidential loss of data."
338 (defgroup processes-basics nil
339 "Basic stuff dealing with processes."
343 "MULE Emacs internationalization."
346 (defgroup windows nil
347 "Windows within a frame."
348 :link
'(custom-manual "(emacs)Windows")
353 (defun custom-quote (sexp)
354 "Quote SEXP iff it is not self quoting."
355 (if (or (memq sexp
'(t nil
))
358 (memq (car sexp
) '(lambda)))
362 ;;; (and (fboundp 'characterp)
363 ;;; (characterp sexp))
368 (defun custom-split-regexp-maybe (regexp)
369 "If REGEXP is a string, split it to a list at `\\|'.
370 You can get the original back with from the result with:
371 (mapconcat 'identity result \"\\|\")
373 IF REGEXP is not a string, return it unchanged."
377 (while (string-match "\\\\|" regexp start
)
378 (setq all
(cons (substring regexp start
(match-beginning 0)) all
)
379 start
(match-end 0)))
380 (nreverse (cons (substring regexp start
) all
)))
383 (defun custom-variable-prompt ()
384 "Prompt for a custom variable, defaulting to the variable at point.
385 Return a list suitable for use in `interactive'."
386 (let ((v (variable-at-point))
387 (enable-recursive-minibuffers t
)
389 (setq val
(completing-read
390 (if (and (symbolp v
) (custom-variable-p v
))
391 (format "Customize option: (default %s) " v
)
392 "Customize option: ")
393 obarray
'custom-variable-p t
))
394 (list (if (equal val
"")
395 (if (symbolp v
) v nil
)
398 (defun custom-menu-filter (menu widget
)
399 "Convert MENU to the form used by `widget-choose'.
400 MENU should be in the same format as `custom-variable-menu'.
401 WIDGET is the widget to apply the filter entries of MENU on."
403 current name action filter
)
405 (setq current
(car menu
)
407 action
(nth 1 current
)
408 filter
(nth 2 current
)
410 (if (or (null filter
) (funcall filter widget
))
411 (push (cons name action
) result
)
417 (defvar custom-prefix-list nil
418 "List of prefixes that should be ignored by `custom-unlispify'.")
420 (defcustom custom-unlispify-menu-entries t
421 "Display menu entries as words instead of symbols if non nil."
425 (defcustom custom-unlispify-remove-prefixes nil
426 "Non-nil means remove group prefixes from option names in buffer."
428 :group
'custom-buffer
431 (defun custom-unlispify-menu-entry (symbol &optional no-suffix
)
432 "Convert SYMBOL into a menu entry."
433 (cond ((not custom-unlispify-menu-entries
)
434 (symbol-name symbol
))
435 ((get symbol
'custom-tag
)
437 (get symbol
'custom-tag
)
438 (concat (get symbol
'custom-tag
) "...")))
440 (with-current-buffer (get-buffer-create " *Custom-Work*")
442 (princ symbol
(current-buffer))
443 (goto-char (point-min))
444 ;; FIXME: Boolean variables are not predicates, so they shouldn't
445 ;; end with `-p'. -stef
446 ;; (when (and (eq (get symbol 'custom-type) 'boolean)
447 ;; (re-search-forward "-p\\'" nil t))
448 ;; (replace-match "" t t)
449 ;; (goto-char (point-min)))
450 (if custom-unlispify-remove-prefixes
451 (let ((prefixes custom-prefix-list
)
454 (setq prefix
(car prefixes
))
455 (if (search-forward prefix
(+ (point) (length prefix
)) t
)
458 (delete-region (point-min) (point)))
459 (setq prefixes
(cdr prefixes
))))))
460 (subst-char-in-region (point-min) (point-max) ?- ?\ t
)
461 (capitalize-region (point-min) (point-max))
463 (goto-char (point-max))
467 (defcustom custom-unlispify-tag-names t
468 "Display tag names as words instead of symbols if non nil."
469 :group
'custom-buffer
472 (defun custom-unlispify-tag-name (symbol)
473 "Convert SYMBOL into a menu entry."
474 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names
))
475 (custom-unlispify-menu-entry symbol t
)))
477 (defun custom-prefix-add (symbol prefixes
)
478 "Add SYMBOL to list of ignored PREFIXES."
479 (cons (or (get symbol
'custom-prefix
)
480 (concat (symbol-name symbol
) "-"))
485 (defcustom custom-guess-name-alist
490 ("-function\\'" function
)
491 ("-functions\\'" (repeat function
))
492 ("-list\\'" (repeat sexp
))
493 ("-alist\\'" (repeat (cons sexp sexp
))))
494 "Alist of (MATCH TYPE).
496 MATCH should be a regexp matching the name of a symbol, and TYPE should
497 be a widget suitable for editing the value of that symbol. The TYPE
498 of the first entry where MATCH matches the name of the symbol will be
501 This is used for guessing the type of variables not declared with
503 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
506 (defcustom custom-guess-doc-alist
507 '(("\\`\\*?Non-nil " boolean
))
508 "Alist of (MATCH TYPE).
510 MATCH should be a regexp matching a documentation string, and TYPE
511 should be a widget suitable for editing the value of a variable with
512 that documentation string. The TYPE of the first entry where MATCH
513 matches the name of the symbol will be used.
515 This is used for guessing the type of variables not declared with
517 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
520 (defun custom-guess-type (symbol)
521 "Guess a widget suitable for editing the value of SYMBOL.
522 This is done by matching SYMBOL with `custom-guess-name-alist' and
523 if that fails, the doc string with `custom-guess-doc-alist'."
524 (let ((name (symbol-name symbol
))
525 (names custom-guess-name-alist
)
528 (setq current
(car names
)
530 (when (string-match (nth 0 current
) name
)
531 (setq found
(nth 1 current
)
534 (let ((doc (documentation-property symbol
'variable-documentation
))
535 (docs custom-guess-doc-alist
))
538 (setq current
(car docs
)
540 (when (string-match (nth 0 current
) doc
)
541 (setq found
(nth 1 current
)
547 (defcustom custom-browse-sort-alphabetically nil
548 "If non-nil, sort members of each customization group alphabetically."
550 :group
'custom-browse
)
552 (defcustom custom-browse-order-groups nil
553 "If non-nil, order group members within each customization group.
554 If `first', order groups before non-groups.
555 If `last', order groups after non-groups."
556 :type
'(choice (const first
)
558 (const :tag
"none" nil
))
559 :group
'custom-browse
)
561 (defcustom custom-browse-only-groups nil
562 "If non-nil, show group members only within each customization group."
564 :group
'custom-browse
)
566 (defcustom custom-buffer-sort-alphabetically nil
567 "If non-nil, sort members of each customization group alphabetically."
569 :group
'custom-buffer
)
571 (defcustom custom-buffer-order-groups
'last
572 "If non-nil, order group members within each customization group.
573 If `first', order groups before non-groups.
574 If `last', order groups after non-groups."
575 :type
'(choice (const first
)
577 (const :tag
"none" nil
))
578 :group
'custom-buffer
)
580 (defcustom custom-menu-sort-alphabetically nil
581 "If non-nil, sort members of each customization group alphabetically."
585 (defcustom custom-menu-order-groups
'first
586 "If non-nil, order group members within each customization group.
587 If `first', order groups before non-groups.
588 If `last', order groups after non-groups."
589 :type
'(choice (const first
)
591 (const :tag
"none" nil
))
594 ;;;###autoload (add-hook 'same-window-regexps "\\`\\*Customiz.*\\*\\'")
596 (defun custom-sort-items (items sort-alphabetically order-groups
)
597 "Return a sorted copy of ITEMS.
598 ITEMS should be a `custom-group' property.
599 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
600 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
601 groups after non-groups, if nil do not order groups at all."
602 (sort (copy-sequence items
)
604 (let ((typea (nth 1 a
)) (typeb (nth 1 b
))
605 (namea (nth 0 a
)) (nameb (nth 0 b
)))
606 (cond ((not order-groups
)
607 ;; Since we don't care about A and B order, maybe sort.
608 (when sort-alphabetically
609 (string-lessp namea nameb
)))
610 ((eq typea
'custom-group
)
611 ;; If B is also a group, maybe sort. Otherwise, order A and B.
612 (if (eq typeb
'custom-group
)
613 (when sort-alphabetically
614 (string-lessp namea nameb
))
615 (eq order-groups
'first
)))
616 ((eq typeb
'custom-group
)
617 ;; Since A cannot be a group, order A and B.
618 (eq order-groups
'last
))
620 ;; Since A and B cannot be groups, sort.
621 (string-lessp namea nameb
)))))))
623 ;;; Custom Mode Commands.
625 (defvar custom-options nil
626 "Customization widgets in the current buffer.")
629 "Set changes in all modified options."
631 (let ((children custom-options
))
632 (mapc (lambda (child)
633 (when (eq (widget-get child
:custom-state
) 'modified
)
634 (widget-apply child
:custom-set
)))
637 (defun Custom-save ()
638 "Set all modified group members and save them."
640 (let ((children custom-options
))
641 (mapc (lambda (child)
642 (when (memq (widget-get child
:custom-state
)
643 '(modified set changed rogue
))
644 (widget-apply child
:custom-save
)))
648 (defvar custom-reset-menu
649 '(("Current" . Custom-reset-current
)
650 ("Saved" . Custom-reset-saved
)
651 ("Erase Customization (use standard settings)" . Custom-reset-standard
))
652 "Alist of actions for the `Reset' button.
653 The key is a string containing the name of the action, the value is a
654 Lisp function taking the widget as an element which will be called
655 when the action is chosen.")
657 (defun custom-reset (event)
658 "Select item from reset menu."
659 (let* ((completion-ignore-case t
)
660 (answer (widget-choose "Reset to"
666 (defun Custom-reset-current (&rest ignore
)
667 "Reset all modified group members to their current value."
669 (let ((children custom-options
))
670 (mapc (lambda (widget)
671 (if (memq (widget-get widget
:custom-state
)
673 (widget-apply widget
:custom-reset-current
)))
676 (defun Custom-reset-saved (&rest ignore
)
677 "Reset all modified or set group members to their saved value."
679 (let ((children custom-options
))
680 (mapc (lambda (widget)
681 (if (memq (widget-get widget
:custom-state
)
682 '(modified set changed rogue
))
683 (widget-apply widget
:custom-reset-saved
)))
686 (defun Custom-reset-standard (&rest ignore
)
687 "Erase all customization (either current or saved) for the group members.
688 The immediate result is to restore them to their standard settings.
689 This operation eliminates any saved settings for the group members,
690 making them as if they had never been customized at all."
692 (let ((children custom-options
))
693 (mapc (lambda (widget)
694 (and (widget-apply widget
:custom-standard-value
)
695 (if (memq (widget-get widget
:custom-state
)
696 '(modified set changed saved rogue
))
697 (widget-apply widget
:custom-reset-standard
))))
700 ;;; The Customize Commands
702 (defun custom-prompt-variable (prompt-var prompt-val
&optional comment
)
703 "Prompt for a variable and a value and return them as a list.
704 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
705 prompt for the value. The %s escape in PROMPT-VAL is replaced with
706 the name of the variable.
708 If the variable has a `variable-interactive' property, that is used as if
709 it were the arg to `interactive' (which see) to interactively read the value.
711 If the variable has a `custom-type' property, it must be a widget and the
712 `:prompt-value' property of that widget will be used for reading the value.
714 If optional COMMENT argument is non nil, also prompt for a comment and return
715 it as the third element in the list."
716 (let* ((var (read-variable prompt-var
))
717 (minibuffer-help-form '(describe-variable var
))
719 (let ((prop (get var
'variable-interactive
))
720 (type (get var
'custom-type
))
721 (prompt (format prompt-val var
)))
723 (setq type
(list type
)))
725 ;; Use VAR's `variable-interactive' property
726 ;; as an interactive spec for prompting.
727 (call-interactively (list 'lambda
'(arg)
728 (list 'interactive prop
)
731 (widget-prompt-value type
737 (eval-minibuffer prompt
))))))
740 (read-string "Comment: " (get var
'variable-comment
)))
744 (defun customize-set-value (variable value
&optional comment
)
745 "Set VARIABLE to VALUE, and return VALUE. VALUE is a Lisp object.
747 If VARIABLE has a `variable-interactive' property, that is used as if
748 it were the arg to `interactive' (which see) to interactively read the value.
750 If VARIABLE has a `custom-type' property, it must be a widget and the
751 `:prompt-value' property of that widget will be used for reading the value.
753 If given a prefix (or a COMMENT argument), also prompt for a comment."
754 (interactive (custom-prompt-variable "Set variable: "
758 (cond ((string= comment
"")
759 (put variable
'variable-comment nil
))
761 (put variable
'variable-comment comment
)))
762 (set variable value
))
765 (defun customize-set-variable (variable value
&optional comment
)
766 "Set the default for VARIABLE to VALUE, and return VALUE.
767 VALUE is a Lisp object.
769 If VARIABLE has a `custom-set' property, that is used for setting
770 VARIABLE, otherwise `set-default' is used.
772 The `customized-value' property of the VARIABLE will be set to a list
773 with a quoted VALUE as its sole list member.
775 If VARIABLE has a `variable-interactive' property, that is used as if
776 it were the arg to `interactive' (which see) to interactively read the value.
778 If VARIABLE has a `custom-type' property, it must be a widget and the
779 `:prompt-value' property of that widget will be used for reading the value.
781 If given a prefix (or a COMMENT argument), also prompt for a comment."
782 (interactive (custom-prompt-variable "Set variable: "
783 "Set customized value for %s to: "
785 (custom-load-symbol variable
)
786 (funcall (or (get variable
'custom-set
) 'set-default
) variable value
)
787 (put variable
'customized-value
(list (custom-quote value
)))
788 (cond ((string= comment
"")
789 (put variable
'variable-comment nil
)
790 (put variable
'customized-variable-comment nil
))
792 (put variable
'variable-comment comment
)
793 (put variable
'customized-variable-comment comment
)))
797 (defun customize-save-variable (variable value
&optional comment
)
798 "Set the default for VARIABLE to VALUE, and save it for future sessions.
801 If VARIABLE has a `custom-set' property, that is used for setting
802 VARIABLE, otherwise `set-default' is used.
804 The `customized-value' property of the VARIABLE will be set to a list
805 with a quoted VALUE as its sole list member.
807 If VARIABLE has a `variable-interactive' property, that is used as if
808 it were the arg to `interactive' (which see) to interactively read the value.
810 If VARIABLE has a `custom-type' property, it must be a widget and the
811 `:prompt-value' property of that widget will be used for reading the value.
813 If given a prefix (or a COMMENT argument), also prompt for a comment."
814 (interactive (custom-prompt-variable "Set and save variable: "
815 "Set and save value for %s as: "
817 (funcall (or (get variable
'custom-set
) 'set-default
) variable value
)
818 (put variable
'saved-value
(list (custom-quote value
)))
819 (custom-push-theme 'theme-value variable
'user
'set
(list (custom-quote value
)))
820 (cond ((string= comment
"")
821 (put variable
'variable-comment nil
)
822 (put variable
'saved-variable-comment nil
))
824 (put variable
'variable-comment comment
)
825 (put variable
'saved-variable-comment comment
)))
831 "Select a customization buffer which you can use to set user options.
832 User options are structured into \"groups\".
833 Initially the top-level group `Emacs' and its immediate subgroups
834 are shown; the contents of those subgroups are initially hidden."
836 (customize-group 'emacs
))
839 (defun customize-mode (mode)
840 "Customize options related to the current major mode.
841 If a prefix \\[universal-argument] was given (or if the current major mode has no known group),
842 then prompt for the MODE to customize."
845 (let ((completion-regexp-list '("-mode\\'"))
846 (group (custom-group-of-mode major-mode
)))
847 (if (and group
(not current-prefix-arg
))
850 (completing-read (if group
851 (format "Major mode (default %s): " major-mode
)
854 'custom-group-of-mode
855 t nil nil
(if group
(symbol-name major-mode
))))))))
856 (customize-group (custom-group-of-mode mode
)))
860 (defun customize-group (group)
861 "Customize GROUP, which must be a customization group."
862 (interactive (list (let ((completion-ignore-case t
))
863 (completing-read "Customize group: (default emacs) "
866 (or (get symbol
'custom-loads
)
867 (get symbol
'custom-group
)))
869 (when (stringp group
)
870 (if (string-equal "" group
)
872 (setq group
(intern group
))))
873 (let ((name (format "*Customize Group: %s*"
874 (custom-unlispify-tag-name group
))))
875 (if (get-buffer name
)
877 (custom-buffer-create (list (list group
'custom-group
))
879 (concat " for group "
880 (custom-unlispify-tag-name group
))))))
883 (defun customize-group-other-window (group)
884 "Customize GROUP, which must be a customization group."
885 (interactive (list (let ((completion-ignore-case t
))
886 (completing-read "Customize group: (default emacs) "
889 (or (get symbol
'custom-loads
)
890 (get symbol
'custom-group
)))
892 (when (stringp group
)
893 (if (string-equal "" group
)
895 (setq group
(intern group
))))
896 (let ((name (format "*Customize Group: %s*"
897 (custom-unlispify-tag-name group
))))
898 (if (get-buffer name
)
900 ;; Copied from `custom-buffer-create-other-window'.
902 (special-display-buffer-names nil
)
903 (special-display-regexps nil
)
904 (same-window-buffer-names nil
)
905 (same-window-regexps nil
))
906 (pop-to-buffer name
))
907 (custom-buffer-create-other-window
908 (list (list group
'custom-group
))
910 (concat " for group "
911 (custom-unlispify-tag-name group
))))))
914 (defalias 'customize-variable
'customize-option
)
917 (defun customize-option (symbol)
918 "Customize SYMBOL, which must be a user option variable."
919 (interactive (custom-variable-prompt))
920 (custom-buffer-create (list (list symbol
'custom-variable
))
921 (format "*Customize Option: %s*"
922 (custom-unlispify-tag-name symbol
))))
925 (defalias 'customize-variable-other-window
'customize-option-other-window
)
928 (defun customize-option-other-window (symbol)
929 "Customize SYMBOL, which must be a user option variable.
930 Show the buffer in another window, but don't select it."
931 (interactive (custom-variable-prompt))
932 (custom-buffer-create-other-window
933 (list (list symbol
'custom-variable
))
934 (format "*Customize Option: %s*" (custom-unlispify-tag-name symbol
))))
936 (defvar customize-changed-options-previous-release
"20.2"
937 "Version for `customize-changed-options' to refer back to by default.")
940 (defun customize-changed-options (since-version)
941 "Customize all user option variables changed in Emacs itself.
942 This includes new user option variables and faces, and new
943 customization groups, as well as older options and faces whose default
944 values have changed since the previous major Emacs release.
946 With argument SINCE-VERSION (a string), customize all user option
947 variables that were added (or their meanings were changed) since that
950 (interactive "sCustomize options changed, since version (default all versions): ")
951 (if (equal since-version
"")
952 (setq since-version nil
)
953 (unless (condition-case nil
954 (numberp (read since-version
))
956 (signal 'wrong-type-argument
(list 'numberp since-version
))))
957 (unless since-version
958 (setq since-version customize-changed-options-previous-release
))
960 ;; Load the information for versions since since-version. We use
961 ;; custom-load-symbol for this.
962 (put 'custom-versions-load-alist
'custom-loads nil
)
963 (dolist (elt custom-versions-load-alist
)
964 (if (customize-version-lessp since-version
(car elt
))
965 (dolist (load (cdr elt
))
966 (custom-add-load 'custom-versions-load-alist load
))))
967 (custom-load-symbol 'custom-versions-load-alist
)
968 (put 'custom-versions-load-alist
'custom-loads nil
)
973 (let ((version (get symbol
'custom-version
)))
975 (when (customize-version-lessp since-version version
)
976 (if (or (get symbol
'custom-group
)
977 (get symbol
'group-documentation
))
978 (push (list symbol
'custom-group
) found
))
979 (if (custom-variable-p symbol
)
980 (push (list symbol
'custom-variable
) found
))
981 (if (custom-facep symbol
)
982 (push (list symbol
'custom-face
) found
)))))))
984 (custom-buffer-create (custom-sort-items found t
'first
)
985 "*Customize Changed Options*")
986 (error "No user option defaults have been changed since Emacs %s"
989 (defun customize-version-lessp (version1 version2
)
990 ;; Why are the versions strings, and given that they are, why aren't
991 ;; they converted to numbers and compared as such here? -- fx
993 ;; In case someone made a mistake and left out the quotes
994 ;; in the :version value.
995 (if (numberp version2
)
996 (setq version2
(prin1-to-string version2
)))
997 (let (major1 major2 minor1 minor2
)
998 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version1
)
999 (setq major1
(read (or (match-string 1 version1
)
1001 (setq minor1
(read (or (match-string 3 version1
)
1003 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version2
)
1004 (setq major2
(read (or (match-string 1 version2
)
1006 (setq minor2
(read (or (match-string 3 version2
)
1008 (or (< major1 major2
)
1009 (and (= major1 major2
)
1010 (< minor1 minor2
)))))
1013 (defun customize-face (&optional face
)
1014 "Customize FACE, which should be a face name or nil.
1015 If FACE is nil, customize all faces.
1017 Interactively, when point is on text which has a face specified,
1018 suggest to customize that face, if it's customizable."
1020 (list (read-face-name "Customize face" "all faces" t
)))
1021 (if (member face
'(nil ""))
1022 (setq face
(face-list)))
1023 (if (and (listp face
) (null (cdr face
)))
1024 (setq face
(car face
)))
1026 (custom-buffer-create (custom-sort-items
1028 (list s
'custom-face
))
1031 "*Customize Faces*")
1032 (unless (facep face
)
1033 (error "Invalid face %S" face
))
1034 (custom-buffer-create (list (list face
'custom-face
))
1035 (format "*Customize Face: %s*"
1036 (custom-unlispify-tag-name face
)))))
1039 (defun customize-face-other-window (&optional face
)
1040 "Show customization buffer for face FACE in other window.
1042 Interactively, when point is on text which has a face specified,
1043 suggest to customize that face, if it's customizable."
1045 (list (read-face-name "Customize face" "all faces" t
)))
1046 (if (member face
'(nil ""))
1047 (setq face
(face-list)))
1048 (if (and (listp face
) (null (cdr face
)))
1049 (setq face
(car face
)))
1051 (custom-buffer-create-other-window
1054 (list s
'custom-face
))
1057 "*Customize Faces*")
1058 (unless (facep face
)
1059 (error "Invalid face %S" face
))
1060 (custom-buffer-create-other-window
1061 (list (list face
'custom-face
))
1062 (format "*Customize Face: %s*"
1063 (custom-unlispify-tag-name face
)))))
1066 (defun customize-customized ()
1067 "Customize all user options set since the last save in this session."
1070 (mapatoms (lambda (symbol)
1071 (and (or (get symbol
'customized-face
)
1072 (get symbol
'customized-face-comment
))
1073 (custom-facep symbol
)
1074 (push (list symbol
'custom-face
) found
))
1075 (and (or (get symbol
'customized-value
)
1076 (get symbol
'customized-variable-comment
))
1078 (push (list symbol
'custom-variable
) found
))))
1080 (error "No customized user options")
1081 (custom-buffer-create (custom-sort-items found t nil
)
1082 "*Customize Customized*"))))
1085 (defun customize-rogue ()
1086 "Customize all user variable modified outside customize."
1089 (mapatoms (lambda (symbol)
1090 (let ((cval (or (get symbol
'customized-value
)
1091 (get symbol
'saved-value
)
1092 (get symbol
'standard-value
))))
1093 (when (and cval
;Declared with defcustom.
1094 (default-boundp symbol
) ;Has a value.
1095 (not (equal (eval (car cval
))
1096 ;; Which does not match customize.
1097 (default-value symbol
))))
1098 (push (list symbol
'custom-variable
) found
)))))
1100 (error "No rogue user options")
1101 (custom-buffer-create (custom-sort-items found t nil
)
1102 "*Customize Rogue*"))))
1104 (defun customize-saved ()
1105 "Customize all already saved user options."
1108 (mapatoms (lambda (symbol)
1109 (and (or (get symbol
'saved-face
)
1110 (get symbol
'saved-face-comment
))
1111 (custom-facep symbol
)
1112 (push (list symbol
'custom-face
) found
))
1113 (and (or (get symbol
'saved-value
)
1114 (get symbol
'saved-variable-comment
))
1116 (push (list symbol
'custom-variable
) found
))))
1118 (error "No saved user options")
1119 (custom-buffer-create (custom-sort-items found t nil
)
1120 "*Customize Saved*"))))
1123 (defun customize-apropos (regexp &optional all
)
1124 "Customize all user options matching REGEXP.
1125 If ALL is `options', include only options.
1126 If ALL is `faces', include only faces.
1127 If ALL is `groups', include only groups.
1128 If ALL is t (interactively, with prefix arg), include options which are not
1129 user-settable, as well as faces and groups."
1130 (interactive "sCustomize regexp: \nP")
1132 (mapatoms (lambda (symbol)
1133 (when (string-match regexp
(symbol-name symbol
))
1134 (when (and (not (memq all
'(faces options
)))
1135 (get symbol
'custom-group
))
1136 (push (list symbol
'custom-group
) found
))
1137 (when (and (not (memq all
'(options groups
)))
1138 (custom-facep symbol
))
1139 (push (list symbol
'custom-face
) found
))
1140 (when (and (not (memq all
'(groups faces
)))
1142 (or (get symbol
'saved-value
)
1143 (custom-variable-p symbol
)
1144 (if (memq all
'(nil options
))
1145 (user-variable-p symbol
)
1146 (get symbol
'variable-documentation
))))
1147 (push (list symbol
'custom-variable
) found
)))))
1149 (error "No matches")
1150 (custom-buffer-create (custom-sort-items found t
1151 custom-buffer-order-groups
)
1152 "*Customize Apropos*"))))
1155 (defun customize-apropos-options (regexp &optional arg
)
1156 "Customize all user options matching REGEXP.
1157 With prefix arg, include options which are not user-settable."
1158 (interactive "sCustomize regexp: \nP")
1159 (customize-apropos regexp
(or arg
'options
)))
1162 (defun customize-apropos-faces (regexp)
1163 "Customize all user faces matching REGEXP."
1164 (interactive "sCustomize regexp: \n")
1165 (customize-apropos regexp
'faces
))
1168 (defun customize-apropos-groups (regexp)
1169 "Customize all user groups matching REGEXP."
1170 (interactive "sCustomize regexp: \n")
1171 (customize-apropos regexp
'groups
))
1175 (defcustom custom-buffer-style
'links
1176 "Control the presentation style for customization buffers.
1177 The value should be a symbol, one of:
1179 brackets: groups nest within each other with big horizontal brackets.
1180 links: groups have links to subgroups."
1181 :type
'(radio (const brackets
)
1183 :group
'custom-buffer
)
1185 ;; If we pass BUFFER to `bury-buffer', the buffer isn't removed from
1187 (defun custom-bury-buffer (buffer)
1188 (with-current-buffer buffer
1191 (defcustom custom-buffer-done-function
'custom-bury-buffer
1192 "*Function called to remove a Custom buffer when the user is done with it.
1193 Called with one argument, the buffer to remove."
1194 :type
'(choice (function-item :tag
"Bury buffer" custom-bury-buffer
)
1195 (function-item :tag
"Kill buffer" kill-buffer
)
1196 (function :tag
"Other"))
1198 :group
'custom-buffer
)
1200 (defcustom custom-buffer-indent
3
1201 "Number of spaces to indent nested groups."
1203 :group
'custom-buffer
)
1205 (defun custom-get-fresh-buffer (name)
1206 "Get a fresh new buffer with name NAME.
1207 If the buffer already exist, clean it up to be like new.
1208 Beware: it's not quite like new. Good enough for custom, but maybe
1210 ;; To be more complete, we should also kill all permanent-local variables,
1211 ;; but it's not needed for custom.
1212 (let ((buf (get-buffer name
)))
1213 (when (and buf
(buffer-local-value 'buffer-file-name buf
))
1214 ;; This will check if the file is not saved.
1218 (get-buffer-create name
)
1219 (with-current-buffer buf
1220 (kill-all-local-variables)
1221 (run-hooks 'kill-buffer-hook
)
1222 ;; Delete overlays before erasing the buffer so the overlay hooks
1223 ;; don't get run spuriously when we erase the buffer.
1224 (let ((ols (overlay-lists)))
1225 (dolist (ol (nconc (car ols
) (cdr ols
)))
1226 (delete-overlay ol
)))
1231 (defun custom-buffer-create (options &optional name description
)
1232 "Create a buffer containing OPTIONS.
1233 Optional NAME is the name of the buffer.
1234 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1235 SYMBOL is a customization option, and WIDGET is a widget for editing
1237 (pop-to-buffer (custom-get-fresh-buffer (or name
"*Customization*")))
1238 (custom-buffer-create-internal options description
))
1241 (defun custom-buffer-create-other-window (options &optional name description
)
1242 "Create a buffer containing OPTIONS, and display it in another window.
1243 The result includes selecting that window.
1244 Optional NAME is the name of the buffer.
1245 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1246 SYMBOL is a customization option, and WIDGET is a widget for editing
1248 (unless name
(setq name
"*Customization*"))
1249 (let ((pop-up-windows t
)
1250 (special-display-buffer-names nil
)
1251 (special-display-regexps nil
)
1252 (same-window-buffer-names nil
)
1253 (same-window-regexps nil
))
1254 (pop-to-buffer (custom-get-fresh-buffer name
))
1255 (custom-buffer-create-internal options description
)))
1257 (defcustom custom-reset-button-menu nil
1258 "If non-nil, only show a single reset button in customize buffers.
1259 This button will have a menu with all three reset operations."
1261 :group
'custom-buffer
)
1263 (defcustom custom-buffer-verbose-help t
1264 "If non-nil, include explanatory text in the customization buffer."
1266 :group
'custom-buffer
)
1268 (defun Custom-buffer-done (&rest ignore
)
1269 "Remove current buffer by calling `custom-buffer-done-function'."
1271 (funcall custom-buffer-done-function
(current-buffer)))
1273 (defcustom custom-raised-buttons
(not (equal (face-valid-attribute-values :box
)
1274 '(("unspecified" . unspecified
))))
1275 "If non-nil, indicate active buttons in a `raised-button' style.
1276 Otherwise use brackets."
1279 :group
'custom-buffer
)
1281 (defun custom-buffer-create-internal (options &optional description
)
1282 (message "Creating customization buffer...")
1284 (if custom-buffer-verbose-help
1286 (widget-insert "This is a customization buffer")
1288 (widget-insert description
))
1289 (widget-insert (format ".
1290 %s show active fields; type RET or click mouse-1
1291 on an active field to invoke its action. Editing an option value
1292 changes the text in the buffer; invoke the State button and
1293 choose the Set operation to set the option value.
1294 Invoke " (if custom-raised-buttons
1296 "Square brackets")))
1297 (widget-create 'info-link
1299 :help-echo
"Read the online help."
1300 "(emacs)Easy Customization")
1301 (widget-insert " for more information.\n\n")
1302 (message "Creating customization buttons...")
1303 (widget-insert "Operate on everything in this buffer:\n "))
1304 (widget-insert " "))
1305 (widget-create 'push-button
1306 :tag
"Set for Current Session"
1308 Make your editing in this buffer take effect for this session."
1309 :action
(lambda (widget &optional event
)
1312 (widget-create 'push-button
1313 :tag
"Save for Future Sessions"
1315 Make your editing in this buffer take effect for future Emacs sessions."
1316 :action
(lambda (widget &optional event
)
1318 (if custom-reset-button-menu
1321 (widget-create 'push-button
1323 :help-echo
"Show a menu with reset operations."
1324 :mouse-down-action
(lambda (&rest junk
) t
)
1325 :action
(lambda (widget &optional event
)
1326 (custom-reset event
))))
1327 (widget-insert "\n ")
1328 (widget-create 'push-button
1331 Reset all edited text in this buffer to reflect current values."
1332 :action
'Custom-reset-current
)
1334 (widget-create 'push-button
1335 :tag
"Reset to Saved"
1337 Reset all values in this buffer to their saved settings."
1338 :action
'Custom-reset-saved
)
1340 (widget-create 'push-button
1341 :tag
"Erase Customization"
1343 Un-customize all values in this buffer. They get their standard settings."
1344 :action
'Custom-reset-standard
))
1345 (if (not custom-buffer-verbose-help
)
1348 (widget-create 'info-link
1350 :help-echo
"Read the online help."
1351 "(emacs)Easy Customization")))
1353 (widget-create 'push-button
1356 (lambda (&rest ignore
)
1358 ((eq custom-buffer-done-function
1359 'custom-bury-buffer
)
1361 ((eq custom-buffer-done-function
'kill-buffer
)
1363 (t "Finish with this buffer")))
1364 :action
#'Custom-buffer-done
)
1365 (widget-insert "\n\n")
1366 (message "Creating customization items...")
1367 (buffer-disable-undo)
1368 (setq custom-options
1369 (if (= (length options
) 1)
1370 (mapcar (lambda (entry)
1371 (widget-create (nth 1 entry
)
1372 :documentation-shown t
1373 :custom-state
'unknown
1374 :tag
(custom-unlispify-tag-name
1376 :value
(nth 0 entry
)))
1379 (length (length options
)))
1380 (mapcar (lambda (entry)
1382 (message "Creating customization items ...%2d%%"
1383 (/ (* 100.0 count
) length
))
1384 (widget-create (nth 1 entry
)
1385 :tag
(custom-unlispify-tag-name
1387 :value
(nth 0 entry
))
1388 (setq count
(1+ count
))
1389 (unless (eq (preceding-char) ?
\n)
1390 (widget-insert "\n"))
1391 (widget-insert "\n")))
1393 (unless (eq (preceding-char) ?
\n)
1394 (widget-insert "\n"))
1395 (message "Creating customization items ...done")
1396 (unless (eq custom-buffer-style
'tree
)
1397 (mapc 'custom-magic-reset custom-options
))
1398 (message "Creating customization setup...")
1400 (buffer-enable-undo)
1401 (goto-char (point-min))
1402 (message "Creating customization buffer...done"))
1404 ;;; The Tree Browser.
1407 (defun customize-browse (&optional group
)
1408 "Create a tree browser for the customize hierarchy."
1411 (setq group
'emacs
))
1412 (let ((name "*Customize Browser*"))
1413 (pop-to-buffer (custom-get-fresh-buffer name
)))
1416 Square brackets show active fields; type RET or click mouse-1
1417 on an active field to invoke its action.
1418 Invoke [+] below to expand a group, and [-] to collapse an expanded group.\n")
1419 (if custom-browse-only-groups
1421 Invoke the [Group] button below to edit that item in another window.\n\n")
1422 (widget-insert "Invoke the ")
1423 (widget-create 'item
1426 :tag-glyph
"folder")
1427 (widget-insert ", ")
1428 (widget-create 'item
1432 (widget-insert ", and ")
1433 (widget-create 'item
1436 :tag-glyph
"option")
1437 (widget-insert " buttons below to edit that
1438 item in another window.\n\n"))
1439 (let ((custom-buffer-style 'tree
))
1440 (widget-create 'custom-group
1442 :custom-state
'unknown
1443 :tag
(custom-unlispify-tag-name group
)
1446 (goto-char (point-min)))
1448 (define-widget 'custom-browse-visibility
'item
1449 "Control visibility of items in the customize tree browser."
1451 :action
'custom-browse-visibility-action
)
1453 (defun custom-browse-visibility-action (widget &rest ignore
)
1454 (let ((custom-buffer-style 'tree
))
1455 (custom-toggle-parent widget
)))
1457 (define-widget 'custom-browse-group-tag
'push-button
1458 "Show parent in other window when activated."
1461 :action
'custom-browse-group-tag-action
)
1463 (defun custom-browse-group-tag-action (widget &rest ignore
)
1464 (let ((parent (widget-get widget
:parent
)))
1465 (customize-group-other-window (widget-value parent
))))
1467 (define-widget 'custom-browse-variable-tag
'push-button
1468 "Show parent in other window when activated."
1471 :action
'custom-browse-variable-tag-action
)
1473 (defun custom-browse-variable-tag-action (widget &rest ignore
)
1474 (let ((parent (widget-get widget
:parent
)))
1475 (customize-variable-other-window (widget-value parent
))))
1477 (define-widget 'custom-browse-face-tag
'push-button
1478 "Show parent in other window when activated."
1481 :action
'custom-browse-face-tag-action
)
1483 (defun custom-browse-face-tag-action (widget &rest ignore
)
1484 (let ((parent (widget-get widget
:parent
)))
1485 (customize-face-other-window (widget-value parent
))))
1487 (defconst custom-browse-alist
'((" " "space")
1493 (defun custom-browse-insert-prefix (prefix)
1494 "Insert PREFIX. On XEmacs convert it to line graphics."
1495 ;; Fixme: do graphics.
1496 (if nil
; (string-match "XEmacs" emacs-version)
1499 (while (not (string-equal prefix
""))
1500 (let ((entry (substring prefix
0 3)))
1501 (setq prefix
(substring prefix
3))
1502 (let ((overlay (make-overlay (1- (point)) (point) nil t nil
))
1503 (name (nth 1 (assoc entry custom-browse-alist
))))
1504 (overlay-put overlay
'end-glyph
(widget-glyph-find name entry
))
1505 (overlay-put overlay
'start-open t
)
1506 (overlay-put overlay
'end-open t
)))))
1509 ;;; Modification of Basic Widgets.
1511 ;; We add extra properties to the basic widgets needed here. This is
1512 ;; fine, as long as we are careful to stay within out own namespace.
1514 ;; We want simple widgets to be displayed by default, but complex
1515 ;; widgets to be hidden.
1517 (widget-put (get 'item
'widget-type
) :custom-show t
)
1518 (widget-put (get 'editable-field
'widget-type
)
1519 :custom-show
(lambda (widget value
)
1520 (let ((pp (pp-to-string value
)))
1521 (cond ((string-match "\n" pp
)
1526 (widget-put (get 'menu-choice
'widget-type
) :custom-show t
)
1528 ;;; The `custom-manual' Widget.
1530 (define-widget 'custom-manual
'info-link
1531 "Link to the manual entry for this customization option."
1532 :help-echo
"Read the manual entry for this option."
1535 ;;; The `custom-magic' Widget.
1537 (defgroup custom-magic-faces nil
1538 "Faces used by the magic button."
1539 :group
'custom-faces
1540 :group
'custom-buffer
)
1542 (defface custom-invalid-face
'((((class color
))
1543 (:foreground
"yellow" :background
"red"))
1545 (:weight bold
:slant italic
:underline t
)))
1546 "Face used when the customize item is invalid."
1547 :group
'custom-magic-faces
)
1549 (defface custom-rogue-face
'((((class color
))
1550 (:foreground
"pink" :background
"black"))
1553 "Face used when the customize item is not defined for customization."
1554 :group
'custom-magic-faces
)
1556 (defface custom-modified-face
'((((class color
))
1557 (:foreground
"white" :background
"blue"))
1559 (:slant italic
:bold
)))
1560 "Face used when the customize item has been modified."
1561 :group
'custom-magic-faces
)
1563 (defface custom-set-face
'((((class color
))
1564 (:foreground
"blue" :background
"white"))
1567 "Face used when the customize item has been set."
1568 :group
'custom-magic-faces
)
1570 (defface custom-changed-face
'((((class color
))
1571 (:foreground
"white" :background
"blue"))
1574 "Face used when the customize item has been changed."
1575 :group
'custom-magic-faces
)
1577 (defface custom-saved-face
'((t (:underline t
)))
1578 "Face used when the customize item has been saved."
1579 :group
'custom-magic-faces
)
1581 (defconst custom-magic-alist
'((nil "#" underline
"\
1582 uninitialized, you should not see this.")
1583 (unknown "?" italic
"\
1584 unknown, you should not see this.")
1585 (hidden "-" default
"\
1586 hidden, invoke \"Show\" in the previous line to show." "\
1587 group now hidden, invoke \"Show\", above, to show contents.")
1588 (invalid "x" custom-invalid-face
"\
1589 the value displayed for this %c is invalid and cannot be set.")
1590 (modified "*" custom-modified-face
"\
1591 you have edited the value as text, but you have not set the %c." "\
1592 you have edited something in this group, but not set it.")
1593 (set "+" custom-set-face
"\
1594 you have set this %c, but not saved it for future sessions." "\
1595 something in this group has been set, but not saved.")
1596 (changed ":" custom-changed-face
"\
1597 this %c has been changed outside the customize buffer." "\
1598 something in this group has been changed outside customize.")
1599 (saved "!" custom-saved-face
"\
1600 this %c has been set and saved." "\
1601 something in this group has been set and saved.")
1602 (rogue "@" custom-rogue-face
"\
1603 this %c has not been changed with customize." "\
1604 something in this group is not prepared for customization.")
1605 (standard " " nil
"\
1606 this %c is unchanged from its standard setting." "\
1607 visible group members are all at standard settings."))
1608 "Alist of customize option states.
1609 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1611 STATE is one of the following symbols:
1614 For internal use, should never occur.
1616 For internal use, should never occur.
1618 This item is not being displayed.
1620 This item is modified, but has an invalid form.
1622 This item is modified, and has a valid form.
1624 This item has been set but not saved.
1626 The current value of this item has been changed temporarily.
1628 This item is marked for saving.
1630 This item has no customization information.
1632 This item is unchanged from the standard setting.
1634 MAGIC is a string used to present that state.
1636 FACE is a face used to present the state.
1638 ITEM-DESC is a string describing the state for options.
1640 GROUP-DESC is a string describing the state for groups. If this is
1641 left out, ITEM-DESC will be used.
1643 The string %c in either description will be replaced with the
1644 category of the item. These are `group'. `option', and `face'.
1646 The list should be sorted most significant first.")
1648 (defcustom custom-magic-show
'long
1649 "If non-nil, show textual description of the state.
1650 If `long', show a full-line description, not just one word."
1651 :type
'(choice (const :tag
"no" nil
)
1653 (other :tag
"short" short
))
1654 :group
'custom-buffer
)
1656 (defcustom custom-magic-show-hidden
'(option face
)
1657 "Control whether the State button is shown for hidden items.
1658 The value should be a list with the custom categories where the State
1659 button should be visible. Possible categories are `group', `option',
1661 :type
'(set (const group
) (const option
) (const face
))
1662 :group
'custom-buffer
)
1664 (defcustom custom-magic-show-button nil
1665 "Show a \"magic\" button indicating the state of each customization option."
1667 :group
'custom-buffer
)
1669 (define-widget 'custom-magic
'default
1670 "Show and manipulate state for a customization option."
1672 :action
'widget-parent-action
1675 :value-create
'custom-magic-value-create
1676 :value-delete
'widget-children-value-delete
)
1678 (defun widget-magic-mouse-down-action (widget &optional event
)
1679 ;; Non-nil unless hidden.
1680 (not (eq (widget-get (widget-get (widget-get widget
:parent
) :parent
)
1684 (defun custom-magic-value-create (widget)
1685 "Create compact status report for WIDGET."
1686 (let* ((parent (widget-get widget
:parent
))
1687 (state (widget-get parent
:custom-state
))
1688 (hidden (eq state
'hidden
))
1689 (entry (assq state custom-magic-alist
))
1690 (magic (nth 1 entry
))
1691 (face (nth 2 entry
))
1692 (category (widget-get parent
:custom-category
))
1693 (text (or (and (eq category
'group
)
1696 (form (widget-get parent
:custom-form
))
1698 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text
)
1699 (setq text
(concat (match-string 1 text
)
1700 (symbol-name category
)
1701 (match-string 2 text
))))
1702 (when (and custom-magic-show
1704 (memq category custom-magic-show-hidden
)))
1706 (when (and (eq category
'group
)
1707 (not (and (eq custom-buffer-style
'links
)
1708 (> (widget-get parent
:custom-level
) 1))))
1709 (insert-char ?\
(* custom-buffer-indent
1710 (widget-get parent
:custom-level
))))
1711 (push (widget-create-child-and-convert
1713 :help-echo
"Change the state of this item."
1714 :format
(if hidden
"%t" "%[%t%]")
1715 :button-prefix
'widget-push-button-prefix
1716 :button-suffix
'widget-push-button-suffix
1717 :mouse-down-action
'widget-magic-mouse-down-action
1721 (let ((start (point)))
1722 (if (eq custom-magic-show
'long
)
1724 (insert (symbol-name state
)))
1725 (cond ((eq form
'lisp
)
1727 ((eq form
'mismatch
)
1728 (insert " (mismatch)")))
1729 (put-text-property start
(point) 'face
'custom-state-face
))
1731 (when (and (eq category
'group
)
1732 (not (and (eq custom-buffer-style
'links
)
1733 (> (widget-get parent
:custom-level
) 1))))
1734 (insert-char ?\
(* custom-buffer-indent
1735 (widget-get parent
:custom-level
))))
1736 (when custom-magic-show-button
1737 (when custom-magic-show
1738 (let ((indent (widget-get parent
:indent
)))
1740 (insert-char ? indent
))))
1741 (push (widget-create-child-and-convert
1743 :mouse-down-action
'widget-magic-mouse-down-action
1747 :help-echo
"Change the state."
1748 :format
(if hidden
"%t" "%[%t%]")
1749 :tag
(if (memq form
'(lisp mismatch
))
1750 (concat "(" magic
")")
1751 (concat "[" magic
"]")))
1754 (widget-put widget
:children children
)))
1756 (defun custom-magic-reset (widget)
1757 "Redraw the :custom-magic property of WIDGET."
1758 (let ((magic (widget-get widget
:custom-magic
)))
1759 (widget-value-set magic
(widget-value magic
))))
1761 ;;; The `custom' Widget.
1763 (defface custom-button-face
1764 '((((type x w32 mac
) (class color
)) ; Like default modeline
1765 (:box
(:line-width
2 :style released-button
)
1766 :background
"lightgrey" :foreground
"black"))
1769 "Face used for buttons in customization buffers."
1771 :group
'custom-faces
)
1773 (defface custom-button-pressed-face
1774 '((((type x w32 mac
) (class color
))
1775 (:box
(:line-width
2 :style pressed-button
)
1776 :background
"lightgrey" :foreground
"black"))
1778 (:inverse-video t
)))
1779 "Face used for buttons in customization buffers."
1781 :group
'custom-faces
)
1783 (defface custom-documentation-face nil
1784 "Face used for documentation strings in customization buffers."
1785 :group
'custom-faces
)
1787 (defface custom-state-face
'((((class color
)
1789 (:foreground
"lime green"))
1792 (:foreground
"dark green"))
1794 "Face used for State descriptions in the customize buffer."
1795 :group
'custom-faces
)
1797 (define-widget 'custom
'default
1798 "Customize a user option."
1800 :convert-widget
'custom-convert-widget
1801 :notify
'custom-notify
1804 :custom-state
'hidden
1805 :documentation-property
'widget-subclass-responsibility
1806 :value-create
'widget-subclass-responsibility
1807 :value-delete
'widget-children-value-delete
1808 :value-get
'widget-value-value-get
1809 :validate
'widget-children-validate
1810 :match
(lambda (widget value
) (symbolp value
)))
1812 (defun custom-convert-widget (widget)
1813 "Initialize :value and :tag from :args in WIDGET."
1814 (let ((args (widget-get widget
:args
)))
1816 (widget-put widget
:value
(widget-apply widget
1817 :value-to-internal
(car args
)))
1818 (widget-put widget
:tag
(custom-unlispify-tag-name (car args
)))
1819 (widget-put widget
:args nil
)))
1822 (defun custom-notify (widget &rest args
)
1823 "Keep track of changes."
1824 (let ((state (widget-get widget
:custom-state
)))
1825 (unless (eq state
'modified
)
1826 (unless (memq state
'(nil unknown hidden
))
1827 (widget-put widget
:custom-state
'modified
))
1828 (custom-magic-reset widget
)
1829 (apply 'widget-default-notify widget args
))))
1831 (defun custom-redraw (widget)
1832 "Redraw WIDGET with current settings."
1833 (let ((line (count-lines (point-min) (point)))
1834 (column (current-column))
1836 (from (marker-position (widget-get widget
:from
)))
1837 (to (marker-position (widget-get widget
:to
))))
1839 (widget-value-set widget
(widget-value widget
))
1840 (custom-redraw-magic widget
))
1841 (when (and (>= pos from
) (<= pos to
))
1846 (goto-line (1+ line
)))
1847 (move-to-column column
))
1850 (defun custom-redraw-magic (widget)
1851 "Redraw WIDGET state with current settings."
1853 (let ((magic (widget-get widget
:custom-magic
)))
1855 (widget-value-set magic
(widget-value magic
))
1856 (when (setq widget
(widget-get widget
:group
))
1857 (custom-group-state-update widget
)))
1859 (setq widget nil
)))))
1862 (defun custom-show (widget value
)
1863 "Non-nil if WIDGET should be shown with VALUE by default."
1864 (let ((show (widget-get widget
:custom-show
)))
1870 (funcall show widget value
)))))
1872 (defun custom-load-widget (widget)
1873 "Load all dependencies for WIDGET."
1874 (custom-load-symbol (widget-value widget
)))
1876 (defun custom-unloaded-symbol-p (symbol)
1877 "Return non-nil if the dependencies of SYMBOL have not yet been loaded."
1879 (loads (get symbol
'custom-loads
))
1882 (setq load
(car loads
)
1884 (cond ((symbolp load
)
1885 (unless (featurep load
)
1887 ((assoc load load-history
))
1888 ((assoc (locate-library load
) load-history
)
1894 (defun custom-unloaded-widget-p (widget)
1895 "Return non-nil if the dependencies of WIDGET have not yet been loaded."
1896 (custom-unloaded-symbol-p (widget-value widget
)))
1898 (defun custom-toggle-hide (widget)
1899 "Toggle visibility of WIDGET."
1900 (custom-load-widget widget
)
1901 (let ((state (widget-get widget
:custom-state
)))
1902 (cond ((memq state
'(invalid modified
))
1903 (error "There are unset changes"))
1905 (widget-put widget
:custom-state
'unknown
))
1907 (widget-put widget
:documentation-shown nil
)
1908 (widget-put widget
:custom-state
'hidden
)))
1909 (custom-redraw widget
)
1912 (defun custom-toggle-parent (widget &rest ignore
)
1913 "Toggle visibility of parent of WIDGET."
1914 (custom-toggle-hide (widget-get widget
:parent
)))
1916 (defun custom-add-see-also (widget &optional prefix
)
1917 "Add `See also ...' to WIDGET if there are any links.
1918 Insert PREFIX first if non-nil."
1919 (let* ((symbol (widget-get widget
:value
))
1920 (links (get symbol
'custom-links
))
1921 (many (> (length links
) 2))
1922 (buttons (widget-get widget
:buttons
))
1923 (indent (widget-get widget
:indent
)))
1926 (insert-char ?\ indent
))
1929 (insert "See also ")
1931 (push (widget-create-child-and-convert widget
(car links
))
1933 (setq links
(cdr links
))
1942 (widget-put widget
:buttons buttons
))))
1944 (defun custom-add-parent-links (widget &optional initial-string
)
1945 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
1946 The value if non-nil if any parents were found.
1947 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
1948 (let ((name (widget-value widget
))
1949 (type (widget-type widget
))
1950 (buttons (widget-get widget
:buttons
))
1953 (insert (or initial-string
"Parent groups:"))
1954 (mapatoms (lambda (symbol)
1955 (let ((entry (assq name
(get symbol
'custom-group
))))
1956 (when (eq (nth 1 entry
) type
)
1958 (push (widget-create-child-and-convert
1959 widget
'custom-group-link
1960 :tag
(custom-unlispify-tag-name symbol
)
1963 (setq parents
(cons symbol parents
))))))
1964 (and (null (get name
'custom-links
)) ;No links of its own.
1965 (= (length parents
) 1) ;A single parent.
1966 (let* ((links (get (car parents
) 'custom-links
))
1967 (many (> (length links
) 2)))
1969 (insert "\nParent documentation: ")
1971 (push (widget-create-child-and-convert widget
(car links
))
1973 (setq links
(cdr links
))
1984 (delete-region start
(point)))
1985 (widget-put widget
:buttons buttons
)
1988 ;;; The `custom-comment' Widget.
1990 ;; like the editable field
1991 (defface custom-comment-face
'((((class grayscale color
)
1993 (:background
"gray85"))
1994 (((class grayscale color
)
1996 (:background
"dim gray"))
1999 "Face used for comments on variables or faces"
2001 :group
'custom-faces
)
2003 ;; like font-lock-comment-face
2004 (defface custom-comment-tag-face
2005 '((((class color
) (background dark
)) (:foreground
"gray80"))
2006 (((class color
) (background light
)) (:foreground
"blue4"))
2007 (((class grayscale
) (background light
))
2008 (:foreground
"DimGray" :weight bold
:slant italic
))
2009 (((class grayscale
) (background dark
))
2010 (:foreground
"LightGray" :weight bold
:slant italic
))
2012 "Face used for variables or faces comment tags"
2013 :group
'custom-faces
)
2015 (define-widget 'custom-comment
'string
2018 :help-echo
"Edit a comment here."
2019 :sample-face
'custom-comment-tag-face
2020 :value-face
'custom-comment-face
2022 :create
'custom-comment-create
)
2024 (defun custom-comment-create (widget)
2025 (let* ((null-comment (equal "" (widget-value widget
))))
2026 (if (or (widget-get (widget-get widget
:parent
) :comment-shown
)
2028 (widget-default-create widget
)
2029 ;; `widget-default-delete' expects markers in these slots --
2030 ;; maybe it shouldn't.
2031 (widget-put widget
:from
(point-marker))
2032 (widget-put widget
:to
(point-marker)))))
2034 (defun custom-comment-hide (widget)
2035 (widget-put (widget-get widget
:parent
) :comment-shown nil
))
2037 ;; Those functions are for the menu. WIDGET is NOT the comment widget. It's
2038 ;; the global custom one
2039 (defun custom-comment-show (widget)
2040 (widget-put widget
:comment-shown t
)
2041 (custom-redraw widget
)
2044 (defun custom-comment-invisible-p (widget)
2045 (let ((val (widget-value (widget-get widget
:comment-widget
))))
2047 (not (widget-get widget
:comment-shown
)))))
2049 ;;; The `custom-variable' Widget.
2051 ;; When this was underlined blue, users confused it with a
2052 ;; Mosaic-style hyperlink...
2053 (defface custom-variable-tag-face
2056 (:foreground
"light blue" :weight bold
:height
1.2 :inherit variable-pitch
))
2059 (:foreground
"blue" :weight bold
:height
1.2 :inherit variable-pitch
))
2061 "Face used for unpushable variable tags."
2062 :group
'custom-faces
)
2064 (defface custom-variable-button-face
'((t (:underline t
:weight bold
)))
2065 "Face used for pushable variable tags."
2066 :group
'custom-faces
)
2068 (defcustom custom-variable-default-form
'edit
2069 "Default form of displaying variable values."
2070 :type
'(choice (const edit
)
2072 :group
'custom-buffer
2075 (defun custom-variable-documentation (variable)
2076 "Return documentation of VARIABLE for use in Custom buffer.
2077 Normally just return the docstring. But if VARIABLE automatically
2078 becomes buffer local when set, append a message to that effect."
2079 (if (and (local-variable-if-set-p variable
)
2080 (or (not (local-variable-p variable
))
2082 (local-variable-if-set-p variable
))))
2083 (concat (documentation-property variable
'variable-documentation
)
2085 This variable automatically becomes buffer-local when set outside Custom.
2086 However, setting it through Custom sets the default value.")
2087 (documentation-property variable
'variable-documentation
)))
2089 (define-widget 'custom-variable
'custom
2090 "Customize variable."
2092 :help-echo
"Set or reset this variable."
2093 :documentation-property
#'custom-variable-documentation
2094 :custom-category
'option
2096 :custom-menu
'custom-variable-menu-create
2097 :custom-form nil
; defaults to value of `custom-variable-default-form'
2098 :value-create
'custom-variable-value-create
2099 :action
'custom-variable-action
2100 :custom-set
'custom-variable-set
2101 :custom-save
'custom-variable-save
2102 :custom-reset-current
'custom-redraw
2103 :custom-reset-saved
'custom-variable-reset-saved
2104 :custom-reset-standard
'custom-variable-reset-standard
2105 :custom-standard-value
'custom-variable-standard-value
)
2107 (defun custom-variable-type (symbol)
2108 "Return a widget suitable for editing the value of SYMBOL.
2109 If SYMBOL has a `custom-type' property, use that.
2110 Otherwise, look up symbol in `custom-guess-type-alist'."
2111 (let* ((type (or (get symbol
'custom-type
)
2112 (and (not (get symbol
'standard-value
))
2113 (custom-guess-type symbol
))
2115 (options (get symbol
'custom-options
))
2116 (tmp (if (listp type
)
2117 (copy-sequence type
)
2120 (widget-put tmp
:options options
))
2123 (defun custom-variable-value-create (widget)
2124 "Here is where you edit the variable's value."
2125 (custom-load-widget widget
)
2126 (unless (widget-get widget
:custom-form
)
2127 (widget-put widget
:custom-form custom-variable-default-form
))
2128 (let* ((buttons (widget-get widget
:buttons
))
2129 (children (widget-get widget
:children
))
2130 (form (widget-get widget
:custom-form
))
2131 (state (widget-get widget
:custom-state
))
2132 (symbol (widget-get widget
:value
))
2133 (tag (widget-get widget
:tag
))
2134 (type (custom-variable-type symbol
))
2135 (conv (widget-convert type
))
2136 (get (or (get symbol
'custom-get
) 'default-value
))
2137 (prefix (widget-get widget
:custom-prefix
))
2138 (last (widget-get widget
:custom-last
))
2139 (value (if (default-boundp symbol
)
2140 (funcall get symbol
)
2141 (widget-get conv
:value
))))
2142 ;; If the widget is new, the child determines whether it is hidden.
2144 ((custom-show type value
)
2145 (setq state
'unknown
))
2147 (setq state
'hidden
)))
2148 ;; If we don't know the state, see if we need to edit it in lisp form.
2149 (when (eq state
'unknown
)
2150 (unless (widget-apply conv
:match value
)
2151 ;; (widget-apply (widget-convert type) :match value)
2152 (setq form
'mismatch
)))
2153 ;; Now we can create the child widget.
2154 (cond ((eq custom-buffer-style
'tree
)
2155 (insert prefix
(if last
" `--- " " |--- "))
2156 (push (widget-create-child-and-convert
2157 widget
'custom-browse-variable-tag
)
2159 (insert " " tag
"\n")
2160 (widget-put widget
:buttons buttons
))
2162 ;; Indicate hidden value.
2163 (push (widget-create-child-and-convert
2166 :sample-face
'custom-variable-tag-face
2170 (push (widget-create-child-and-convert
2172 :help-echo
"Show the value of this option."
2174 :action
'custom-toggle-parent
2177 ((memq form
'(lisp mismatch
))
2178 ;; In lisp mode edit the saved value when possible.
2179 (let* ((value (cond ((get symbol
'saved-value
)
2180 (car (get symbol
'saved-value
)))
2181 ((get symbol
'standard-value
)
2182 (car (get symbol
'standard-value
)))
2183 ((default-boundp symbol
)
2184 (custom-quote (funcall get symbol
)))
2186 (custom-quote (widget-get conv
:value
))))))
2187 (insert (symbol-name symbol
) ": ")
2188 (push (widget-create-child-and-convert
2190 :help-echo
"Hide the value of this option."
2193 :action
'custom-toggle-parent
2197 (push (widget-create-child-and-convert
2199 :button-face
'custom-variable-button-face
2201 :tag
(symbol-name symbol
)
2207 (let* ((format (widget-get type
:format
))
2208 tag-format value-format
)
2209 (unless (string-match ":" format
)
2210 (error "Bad format"))
2211 (setq tag-format
(substring format
0 (match-end 0)))
2212 (setq value-format
(substring format
(match-end 0)))
2213 (push (widget-create-child-and-convert
2216 :action
'custom-tag-action
2217 :help-echo
"Change value of this option."
2218 :mouse-down-action
'custom-tag-mouse-down-action
2219 :button-face
'custom-variable-button-face
2220 :sample-face
'custom-variable-tag-face
2224 (push (widget-create-child-and-convert
2226 :help-echo
"Hide the value of this option."
2229 :action
'custom-toggle-parent
2232 (push (widget-create-child-and-convert
2234 :format value-format
2237 (unless (eq custom-buffer-style
'tree
)
2238 (unless (eq (preceding-char) ?
\n)
2239 (widget-insert "\n"))
2240 ;; Create the magic button.
2241 (let ((magic (widget-create-child-and-convert
2242 widget
'custom-magic nil
)))
2243 (widget-put widget
:custom-magic magic
)
2244 (push magic buttons
))
2245 ;; ### NOTE: this is ugly!!!! I need to update the :buttons property
2246 ;; before the call to `widget-default-format-handler'. Otherwise, I
2247 ;; loose my current `buttons'. This function shouldn't be called like
2248 ;; this anyway. The doc string widget should be added like the others.
2250 (widget-put widget
:buttons buttons
)
2252 ;; Insert documentation.
2253 (widget-default-format-handler widget ?h
)
2255 ;; The comment field
2256 (unless (eq state
'hidden
)
2257 (let* ((comment (get symbol
'variable-comment
))
2259 (widget-create-child-and-convert
2260 widget
'custom-comment
2262 :value
(or comment
""))))
2263 (widget-put widget
:comment-widget comment-widget
)
2264 ;; Don't push it !!! Custom assumes that the first child is the
2266 (setq children
(append children
(list comment-widget
)))))
2267 ;; Update the rest of the properties properties.
2268 (widget-put widget
:custom-form form
)
2269 (widget-put widget
:children children
)
2270 ;; Now update the state.
2271 (if (eq state
'hidden
)
2272 (widget-put widget
:custom-state state
)
2273 (custom-variable-state-set widget
))
2275 (unless (eq state
'hidden
)
2276 (when (eq (widget-get widget
:custom-level
) 1)
2277 (custom-add-parent-links widget
))
2278 (custom-add-see-also widget
)))))
2280 (defun custom-tag-action (widget &rest args
)
2281 "Pass :action to first child of WIDGET's parent."
2282 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2285 (defun custom-tag-mouse-down-action (widget &rest args
)
2286 "Pass :mouse-down-action to first child of WIDGET's parent."
2287 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2288 :mouse-down-action args
))
2290 (defun custom-variable-state-set (widget)
2291 "Set the state of WIDGET."
2292 (let* ((symbol (widget-value widget
))
2293 (get (or (get symbol
'custom-get
) 'default-value
))
2294 (value (if (default-boundp symbol
)
2295 (funcall get symbol
)
2296 (widget-get widget
:value
)))
2297 (comment (get symbol
'variable-comment
))
2300 (state (cond ((progn (setq tmp
(get symbol
'customized-value
))
2302 (get symbol
'customized-variable-comment
))
2304 (if (condition-case nil
2305 (and (equal value
(eval (car tmp
)))
2306 (equal comment temp
))
2310 ((progn (setq tmp
(get symbol
'saved-value
))
2311 (setq temp
(get symbol
'saved-variable-comment
))
2313 (if (condition-case nil
2314 (and (equal value
(eval (car tmp
)))
2315 (equal comment temp
))
2319 ((setq tmp
(get symbol
'standard-value
))
2320 (if (condition-case nil
2321 (and (equal value
(eval (car tmp
)))
2322 (equal comment nil
))
2327 (widget-put widget
:custom-state state
)))
2329 (defun custom-variable-standard-value (widget)
2330 (get (widget-value widget
) 'standard-value
))
2332 (defvar custom-variable-menu
2333 '(("Set for Current Session" custom-variable-set
2335 (eq (widget-get widget
:custom-state
) 'modified
)))
2336 ("Save for Future Sessions" custom-variable-save
2338 (memq (widget-get widget
:custom-state
) '(modified set changed rogue
))))
2339 ("Reset to Current" custom-redraw
2341 (and (default-boundp (widget-value widget
))
2342 (memq (widget-get widget
:custom-state
) '(modified changed
)))))
2343 ("Reset to Saved" custom-variable-reset-saved
2345 (and (or (get (widget-value widget
) 'saved-value
)
2346 (get (widget-value widget
) 'saved-variable-comment
))
2347 (memq (widget-get widget
:custom-state
)
2348 '(modified set changed rogue
)))))
2349 ("Erase Customization" custom-variable-reset-standard
2351 (and (get (widget-value widget
) 'standard-value
)
2352 (memq (widget-get widget
:custom-state
)
2353 '(modified set changed saved rogue
)))))
2354 ("Use Backup Value" custom-variable-reset-backup
2356 (get (widget-value widget
) 'backup-value
)))
2357 ("---" ignore ignore
)
2358 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
2359 ("---" ignore ignore
)
2360 ("Don't show as Lisp expression" custom-variable-edit
2362 (eq (widget-get widget
:custom-form
) 'lisp
)))
2363 ("Show initial Lisp expression" custom-variable-edit-lisp
2365 (eq (widget-get widget
:custom-form
) 'edit
))))
2366 "Alist of actions for the `custom-variable' widget.
2367 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2368 the menu entry, ACTION is the function to call on the widget when the
2369 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2370 widget as an argument, and returns non-nil if ACTION is valid on that
2371 widget. If FILTER is nil, ACTION is always valid.")
2373 (defun custom-variable-action (widget &optional event
)
2374 "Show the menu for `custom-variable' WIDGET.
2375 Optional EVENT is the location for the menu."
2376 (if (eq (widget-get widget
:custom-state
) 'hidden
)
2377 (custom-toggle-hide widget
)
2378 (unless (eq (widget-get widget
:custom-state
) 'modified
)
2379 (custom-variable-state-set widget
))
2380 (custom-redraw-magic widget
)
2381 (let* ((completion-ignore-case t
)
2382 (answer (widget-choose (concat "Operation on "
2383 (custom-unlispify-tag-name
2384 (widget-get widget
:value
)))
2385 (custom-menu-filter custom-variable-menu
2389 (funcall answer widget
)))))
2391 (defun custom-variable-edit (widget)
2392 "Edit value of WIDGET."
2393 (widget-put widget
:custom-state
'unknown
)
2394 (widget-put widget
:custom-form
'edit
)
2395 (custom-redraw widget
))
2397 (defun custom-variable-edit-lisp (widget)
2398 "Edit the Lisp representation of the value of WIDGET."
2399 (widget-put widget
:custom-state
'unknown
)
2400 (widget-put widget
:custom-form
'lisp
)
2401 (custom-redraw widget
))
2403 (defun custom-variable-set (widget)
2404 "Set the current value for the variable being edited by WIDGET."
2405 (let* ((form (widget-get widget
:custom-form
))
2406 (state (widget-get widget
:custom-state
))
2407 (child (car (widget-get widget
:children
)))
2408 (symbol (widget-value widget
))
2409 (set (or (get symbol
'custom-set
) 'set-default
))
2410 (comment-widget (widget-get widget
:comment-widget
))
2411 (comment (widget-value comment-widget
))
2413 (cond ((eq state
'hidden
)
2414 (error "Cannot set hidden variable"))
2415 ((setq val
(widget-apply child
:validate
))
2416 (goto-char (widget-get val
:from
))
2417 (error "%s" (widget-get val
:error
)))
2418 ((memq form
'(lisp mismatch
))
2419 (when (equal comment
"")
2421 ;; Make the comment invisible by hand if it's empty
2422 (custom-comment-hide comment-widget
))
2423 (custom-variable-backup-value widget
)
2424 (funcall set symbol
(eval (setq val
(widget-value child
))))
2425 (put symbol
'customized-value
(list val
))
2426 (put symbol
'variable-comment comment
)
2427 (put symbol
'customized-variable-comment comment
))
2429 (when (equal comment
"")
2431 ;; Make the comment invisible by hand if it's empty
2432 (custom-comment-hide comment-widget
))
2433 (custom-variable-backup-value widget
)
2434 (funcall set symbol
(setq val
(widget-value child
)))
2435 (put symbol
'customized-value
(list (custom-quote val
)))
2436 (put symbol
'variable-comment comment
)
2437 (put symbol
'customized-variable-comment comment
)))
2438 (custom-variable-state-set widget
)
2439 (custom-redraw-magic widget
)))
2441 (defun custom-variable-save (widget)
2442 "Set and save the value for the variable being edited by WIDGET."
2443 (let* ((form (widget-get widget
:custom-form
))
2444 (state (widget-get widget
:custom-state
))
2445 (child (car (widget-get widget
:children
)))
2446 (symbol (widget-value widget
))
2447 (set (or (get symbol
'custom-set
) 'set-default
))
2448 (comment-widget (widget-get widget
:comment-widget
))
2449 (comment (widget-value comment-widget
))
2451 (cond ((eq state
'hidden
)
2452 (error "Cannot set hidden variable"))
2453 ((setq val
(widget-apply child
:validate
))
2454 (goto-char (widget-get val
:from
))
2455 (error "Saving %s: %s" symbol
(widget-get val
:error
)))
2456 ((memq form
'(lisp mismatch
))
2457 (when (equal comment
"")
2459 ;; Make the comment invisible by hand if it's empty
2460 (custom-comment-hide comment-widget
))
2461 (put symbol
'saved-value
(list (widget-value child
)))
2462 (custom-push-theme 'theme-value symbol
'user
2463 'set
(list (widget-value child
)))
2464 (funcall set symbol
(eval (widget-value child
)))
2465 (put symbol
'variable-comment comment
)
2466 (put symbol
'saved-variable-comment comment
))
2468 (when (equal comment
"")
2470 ;; Make the comment invisible by hand if it's empty
2471 (custom-comment-hide comment-widget
))
2472 (put symbol
'saved-value
2473 (list (custom-quote (widget-value child
))))
2474 (custom-push-theme 'theme-value symbol
'user
2475 'set
(list (custom-quote (widget-value
2477 (funcall set symbol
(widget-value child
))
2478 (put symbol
'variable-comment comment
)
2479 (put symbol
'saved-variable-comment comment
)))
2480 (put symbol
'customized-value nil
)
2481 (put symbol
'customized-variable-comment nil
)
2483 (custom-variable-state-set widget
)
2484 (custom-redraw-magic widget
)))
2486 (defun custom-variable-reset-saved (widget)
2487 "Restore the saved value for the variable being edited by WIDGET.
2488 The value that was current before this operation
2489 becomes the backup value, so you can get it again."
2490 (let* ((symbol (widget-value widget
))
2491 (set (or (get symbol
'custom-set
) 'set-default
))
2492 (value (get symbol
'saved-value
))
2493 (comment (get symbol
'saved-variable-comment
)))
2494 (cond ((or value comment
)
2495 (put symbol
'variable-comment comment
)
2496 (custom-variable-backup-value widget
)
2498 (funcall set symbol
(eval (car value
)))
2501 (error "No saved value for %s" symbol
)))
2502 (put symbol
'customized-value nil
)
2503 (put symbol
'customized-variable-comment nil
)
2504 (widget-put widget
:custom-state
'unknown
)
2505 ;; This call will possibly make the comment invisible
2506 (custom-redraw widget
)))
2508 (defun custom-variable-reset-standard (widget)
2509 "Restore the standard setting for the variable being edited by WIDGET.
2510 This operation eliminates any saved setting for the variable,
2511 restoring it to the state of a variable that has never been customized.
2512 The value that was current before this operation
2513 becomes the backup value, so you can get it again."
2514 (let* ((symbol (widget-value widget
))
2515 (set (or (get symbol
'custom-set
) 'set-default
)))
2516 (if (get symbol
'standard-value
)
2518 (custom-variable-backup-value widget
)
2519 (funcall set symbol
(eval (car (get symbol
'standard-value
)))))
2520 (error "No standard setting known for %S" symbol
))
2521 (put symbol
'variable-comment nil
)
2522 (put symbol
'customized-value nil
)
2523 (put symbol
'customized-variable-comment nil
)
2524 (when (or (get symbol
'saved-value
) (get symbol
'saved-variable-comment
))
2525 (put symbol
'saved-value nil
)
2526 (custom-push-theme 'theme-value symbol
'user
'reset
'standard
)
2527 ;; As a special optimizations we do not (explictly)
2528 ;; save resets to standard when no theme set the value.
2529 (if (null (cdr (get symbol
'theme-value
)))
2530 (put symbol
'theme-value nil
))
2531 (put symbol
'saved-variable-comment nil
)
2533 (widget-put widget
:custom-state
'unknown
)
2534 ;; This call will possibly make the comment invisible
2535 (custom-redraw widget
)))
2537 (defun custom-variable-backup-value (widget)
2538 "Back up the current value for WIDGET's variable.
2539 The backup value is kept in the car of the `backup-value' property."
2540 (let* ((symbol (widget-value widget
))
2541 (get (or (get symbol
'custom-get
) 'default-value
))
2542 (type (custom-variable-type symbol
))
2543 (conv (widget-convert type
))
2544 (value (if (default-boundp symbol
)
2545 (funcall get symbol
)
2546 (widget-get conv
:value
))))
2547 (put symbol
'backup-value
(list value
))))
2549 (defun custom-variable-reset-backup (widget)
2550 "Restore the backup value for the variable being edited by WIDGET.
2551 The value that was current before this operation
2552 becomes the backup value, so you can use this operation repeatedly
2553 to switch between two values."
2554 (let* ((symbol (widget-value widget
))
2555 (set (or (get symbol
'custom-set
) 'set-default
))
2556 (value (get symbol
'backup-value
))
2557 (comment-widget (widget-get widget
:comment-widget
))
2558 (comment (widget-value comment-widget
)))
2561 (custom-variable-backup-value widget
)
2563 (funcall set symbol
(car value
))
2565 (error "No backup value for %s" symbol
))
2566 (put symbol
'customized-value
(list (car value
)))
2567 (put symbol
'variable-comment comment
)
2568 (put symbol
'customized-variable-comment comment
)
2569 (custom-variable-state-set widget
)
2570 ;; This call will possibly make the comment invisible
2571 (custom-redraw widget
)))
2573 ;;; The `custom-face-edit' Widget.
2575 (define-widget 'custom-face-edit
'checklist
2576 "Edit face attributes."
2580 :button-args
'(:help-echo
"Control whether this attribute has any effect.")
2581 :value-to-internal
'custom-face-edit-fix-value
2582 :match
(lambda (widget value
)
2583 (widget-checklist-match widget
2584 (custom-face-edit-fix-value widget value
)))
2585 :convert-widget
'custom-face-edit-convert-widget
2586 :args
(mapcar (lambda (att)
2589 :sibling-args
(widget-get (nth 1 att
) :sibling-args
)
2590 (list 'const
:format
"" :value
(nth 0 att
))
2592 custom-face-attributes
))
2594 (defun custom-face-edit-fix-value (widget value
)
2595 "Ignoring WIDGET, convert :bold and :italic in VALUE to new form.
2596 Also change :reverse-video to :inverse-video."
2600 (let ((key (car value
))
2601 (val (car (cdr value
))))
2602 (cond ((eq key
:italic
)
2603 (push :slant result
)
2604 (push (if val
'italic
'normal
) result
))
2606 (push :weight result
)
2607 (push (if val
'bold
'normal
) result
))
2608 ((eq key
:reverse-video
)
2609 (push :inverse-video result
)
2613 (push val result
))))
2614 (setq value
(cdr (cdr value
))))
2615 (setq result
(nreverse result
))
2619 (defun custom-face-edit-convert-widget (widget)
2620 "Convert :args as widget types in WIDGET."
2623 :args
(mapcar (lambda (arg)
2625 :deactivate
'custom-face-edit-deactivate
2626 :activate
'custom-face-edit-activate
2627 :delete
'custom-face-edit-delete
))
2628 (widget-get widget
:args
)))
2631 (defun custom-face-edit-deactivate (widget)
2632 "Make face widget WIDGET inactive for user modifications."
2633 (unless (widget-get widget
:inactive
)
2634 (let ((tag (custom-face-edit-attribute-tag widget
))
2635 (from (copy-marker (widget-get widget
:from
)))
2636 (value (widget-value widget
))
2637 (inhibit-read-only t
)
2638 (inhibit-modification-hooks t
))
2641 (widget-default-delete widget
)
2642 (insert tag
": *\n")
2643 (widget-put widget
:inactive
2644 (cons value
(cons from
(- (point) from
))))))))
2646 (defun custom-face-edit-activate (widget)
2647 "Make face widget WIDGET inactive for user modifications."
2648 (let ((inactive (widget-get widget
:inactive
))
2649 (inhibit-read-only t
)
2650 (inhibit-modification-hooks t
))
2651 (when (consp inactive
)
2653 (goto-char (car (cdr inactive
)))
2654 (delete-region (point) (+ (point) (cdr (cdr inactive
))))
2655 (widget-put widget
:inactive nil
)
2656 (widget-apply widget
:create
)
2657 (widget-value-set widget
(car inactive
))
2660 (defun custom-face-edit-delete (widget)
2661 "Remove WIDGET from the buffer."
2662 (let ((inactive (widget-get widget
:inactive
))
2663 (inhibit-read-only t
)
2664 (inhibit-modification-hooks t
))
2666 ;; Widget is alive, we don't have to do anything special
2667 (widget-default-delete widget
)
2668 ;; WIDGET is already deleted because we did so to inactivate it;
2669 ;; now just get rid of the label we put in its place.
2670 (delete-region (car (cdr inactive
))
2671 (+ (car (cdr inactive
)) (cdr (cdr inactive
))))
2672 (widget-put widget
:inactive nil
))))
2675 (defun custom-face-edit-attribute-tag (widget)
2676 "Returns the first :tag property in WIDGET or one of its children."
2677 (let ((tag (widget-get widget
:tag
)))
2678 (or (and (not (equal tag
"")) tag
)
2679 (let ((children (widget-get widget
:children
)))
2680 (while (and (null tag
) children
)
2681 (setq tag
(custom-face-edit-attribute-tag (pop children
))))
2684 ;;; The `custom-display' Widget.
2686 (define-widget 'custom-display
'menu-choice
2687 "Select a display type."
2690 :help-echo
"Specify frames where the face attributes should be used."
2691 :args
'((const :tag
"all" t
)
2695 :args
((group :sibling-args
(:help-echo
"\
2696 Only match the specified window systems.")
2697 (const :format
"Type: "
2699 (checklist :inline t
2702 :sibling-args
(:help-echo
"\
2703 The X11 Window System.")
2705 (const :format
"PM "
2706 :sibling-args
(:help-echo
"\
2707 OS/2 Presentation Manager.")
2709 (const :format
"W32 "
2710 :sibling-args
(:help-echo
"\
2713 (const :format
"MAC "
2714 :sibling-args
(:help-echo
"\
2717 (const :format
"DOS "
2718 :sibling-args
(:help-echo
"\
2721 (const :format
"TTY%n"
2722 :sibling-args
(:help-echo
"\
2723 Plain text terminals.")
2725 (group :sibling-args
(:help-echo
"\
2726 Only match the frames with the specified color support.")
2727 (const :format
"Class: "
2729 (checklist :inline t
2731 (const :format
"Color "
2732 :sibling-args
(:help-echo
"\
2733 Match color frames.")
2735 (const :format
"Grayscale "
2736 :sibling-args
(:help-echo
"\
2737 Match grayscale frames.")
2739 (const :format
"Monochrome%n"
2740 :sibling-args
(:help-echo
"\
2741 Match frames with no color support.")
2743 (group :sibling-args
(:help-echo
"\
2744 The minimum number of colors the frame should support.")
2745 (const :format
"" min-colors
)
2746 (integer :tag
"Minimum number of colors" ))
2747 (group :sibling-args
(:help-echo
"\
2748 Only match frames with the specified intensity.")
2750 Background brightness: "
2752 (checklist :inline t
2754 (const :format
"Light "
2755 :sibling-args
(:help-echo
"\
2756 Match frames with light backgrounds.")
2758 (const :format
"Dark\n"
2759 :sibling-args
(:help-echo
"\
2760 Match frames with dark backgrounds.")
2762 (group :sibling-args
(:help-echo
"\
2763 Only match frames that support the specified face attributes.")
2764 (const :format
"Supports attributes:" supports
)
2765 (custom-face-edit :inline t
:format
"%n%v"))))))
2767 ;;; The `custom-face' Widget.
2769 (defface custom-face-tag-face
2770 `((t (:weight bold
:height
1.2 :inherit variable-pitch
)))
2771 "Face used for face tags."
2772 :group
'custom-faces
)
2774 (defcustom custom-face-default-form
'selected
2775 "Default form of displaying face definition."
2776 :type
'(choice (const all
)
2779 :group
'custom-buffer
2782 (define-widget 'custom-face
'custom
2784 :sample-face
'custom-face-tag-face
2785 :help-echo
"Set or reset this face."
2786 :documentation-property
#'face-doc-string
2787 :value-create
'custom-face-value-create
2788 :action
'custom-face-action
2789 :custom-category
'face
2790 :custom-form nil
; defaults to value of `custom-face-default-form'
2791 :custom-set
'custom-face-set
2792 :custom-save
'custom-face-save
2793 :custom-reset-current
'custom-redraw
2794 :custom-reset-saved
'custom-face-reset-saved
2795 :custom-reset-standard
'custom-face-reset-standard
2796 :custom-standard-value
'custom-face-standard-value
2797 :custom-menu
'custom-face-menu-create
)
2799 (define-widget 'custom-face-all
'editable-list
2800 "An editable list of display specifications and attributes."
2801 :entry-format
"%i %d %v"
2802 :insert-button-args
'(:help-echo
"Insert new display specification here.")
2803 :append-button-args
'(:help-echo
"Append new display specification here.")
2804 :delete-button-args
'(:help-echo
"Delete this display specification.")
2805 :args
'((group :format
"%v" custom-display custom-face-edit
)))
2807 (defconst custom-face-all
(widget-convert 'custom-face-all
)
2808 "Converted version of the `custom-face-all' widget.")
2810 (define-widget 'custom-display-unselected
'item
2811 "A display specification that doesn't match the selected display."
2812 :match
'custom-display-unselected-match
)
2814 (defun custom-display-unselected-match (widget value
)
2815 "Non-nil if VALUE is an unselected display specification."
2816 (not (face-spec-set-match-display value
(selected-frame))))
2818 (define-widget 'custom-face-selected
'group
2819 "Edit the attributes of the selected display in a face specification."
2820 :args
'((repeat :format
""
2822 (group custom-display-unselected sexp
))
2823 (group (sexp :format
"") custom-face-edit
)
2828 (defconst custom-face-selected
(widget-convert 'custom-face-selected
)
2829 "Converted version of the `custom-face-selected' widget.")
2831 (defun custom-filter-face-spec (spec filter-index
&optional default-filter
)
2832 "Return a canonicalized version of SPEC using.
2833 FILTER-INDEX is the index in the entry for each attribute in
2834 `custom-face-attributes' at which the appropriate filter function can be
2835 found, and DEFAULT-FILTER is the filter to apply for attributes that
2837 (mapcar (lambda (entry)
2838 ;; Filter a single face-spec entry
2839 (let ((tests (car entry
))
2841 ;; Handle both old- and new-style attribute syntax
2842 (if (listp (car (cdr entry
)))
2845 (filtered-attrs nil
))
2846 ;; Filter each face attribute
2847 (while unfiltered-attrs
2848 (let* ((attr (pop unfiltered-attrs
))
2849 (pre-filtered-value (pop unfiltered-attrs
))
2851 (or (nth filter-index
(assq attr custom-face-attributes
))
2855 (funcall filter pre-filtered-value
)
2856 pre-filtered-value
)))
2857 (push filtered-value filtered-attrs
)
2858 (push attr filtered-attrs
)))
2860 (list tests filtered-attrs
)))
2863 (defun custom-pre-filter-face-spec (spec)
2864 "Return SPEC changed as necessary for editing by the face customization widget.
2865 SPEC must be a full face spec."
2866 (custom-filter-face-spec spec
2))
2868 (defun custom-post-filter-face-spec (spec)
2869 "Return the customized SPEC in a form suitable for setting the face."
2870 (custom-filter-face-spec spec
3))
2872 (defun custom-face-value-create (widget)
2873 "Create a list of the display specifications for WIDGET."
2874 (let ((buttons (widget-get widget
:buttons
))
2876 (symbol (widget-get widget
:value
))
2877 (tag (widget-get widget
:tag
))
2878 (state (widget-get widget
:custom-state
))
2880 (is-last (widget-get widget
:custom-last
))
2881 (prefix (widget-get widget
:custom-prefix
)))
2883 (setq tag
(prin1-to-string symbol
)))
2884 (cond ((eq custom-buffer-style
'tree
)
2885 (insert prefix
(if is-last
" `--- " " |--- "))
2886 (push (widget-create-child-and-convert
2887 widget
'custom-browse-face-tag
)
2889 (insert " " tag
"\n")
2890 (widget-put widget
:buttons buttons
))
2894 (widget-specify-sample widget begin
(point))
2895 (if (eq custom-buffer-style
'face
)
2897 (if (string-match "face\\'" tag
)
2899 (insert " face: ")))
2901 (push (widget-create-child-and-convert widget
'item
2908 (push (widget-create-child-and-convert
2910 :help-echo
"Hide or show this face."
2913 :action
'custom-toggle-parent
2914 (not (eq state
'hidden
)))
2918 (let ((magic (widget-create-child-and-convert
2919 widget
'custom-magic nil
)))
2920 (widget-put widget
:custom-magic magic
)
2921 (push magic buttons
))
2923 (widget-put widget
:buttons buttons
)
2924 ;; Insert documentation.
2925 (widget-default-format-handler widget ?h
)
2926 ;; The comment field
2927 (unless (eq state
'hidden
)
2928 (let* ((comment (get symbol
'face-comment
))
2930 (widget-create-child-and-convert
2931 widget
'custom-comment
2933 :value
(or comment
""))))
2934 (widget-put widget
:comment-widget comment-widget
)
2935 (push comment-widget children
)))
2937 (unless (eq state
'hidden
)
2938 (when (eq (widget-get widget
:custom-level
) 1)
2939 (custom-add-parent-links widget
))
2940 (custom-add-see-also widget
))
2942 (unless (eq (preceding-char) ?
\n)
2944 (unless (eq state
'hidden
)
2945 (message "Creating face editor...")
2946 (custom-load-widget widget
)
2947 (unless (widget-get widget
:custom-form
)
2948 (widget-put widget
:custom-form custom-face-default-form
))
2949 (let* ((symbol (widget-value widget
))
2950 (spec (or (get symbol
'customized-face
)
2951 (get symbol
'saved-face
)
2952 (get symbol
'face-defface-spec
)
2953 ;; Attempt to construct it.
2954 (list (list t
(custom-face-attributes-get
2955 symbol
(selected-frame))))))
2956 (form (widget-get widget
:custom-form
))
2957 (indent (widget-get widget
:indent
))
2959 ;; If the user has changed this face in some other way,
2960 ;; edit it as the user has specified it.
2961 (if (not (face-spec-match-p symbol spec
(selected-frame)))
2962 (setq spec
(list (list t
(face-attr-construct symbol
(selected-frame))))))
2963 (setq spec
(custom-pre-filter-face-spec spec
))
2964 (setq edit
(widget-create-child-and-convert
2966 (cond ((and (eq form
'selected
)
2967 (widget-apply custom-face-selected
2969 (when indent
(insert-char ?\ indent
))
2970 'custom-face-selected
)
2971 ((and (not (eq form
'lisp
))
2972 (widget-apply custom-face-all
2976 (when indent
(insert-char ?\ indent
))
2979 (custom-face-state-set widget
)
2980 (push edit children
)
2981 (widget-put widget
:children children
))
2982 (message "Creating face editor...done"))))))
2984 (defvar custom-face-menu
2985 '(("Set for Current Session" custom-face-set
)
2986 ("Save for Future Sessions" custom-face-save-command
)
2987 ("Reset to Saved" custom-face-reset-saved
2989 (or (get (widget-value widget
) 'saved-face
)
2990 (get (widget-value widget
) 'saved-face-comment
))))
2991 ("Erase Customization" custom-face-reset-standard
2993 (get (widget-value widget
) 'face-defface-spec
)))
2994 ("---" ignore ignore
)
2995 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
2996 ("---" ignore ignore
)
2997 ("Show all display specs" custom-face-edit-all
2999 (not (eq (widget-get widget
:custom-form
) 'all
))))
3000 ("Just current attributes" custom-face-edit-selected
3002 (not (eq (widget-get widget
:custom-form
) 'selected
))))
3003 ("Show as Lisp expression" custom-face-edit-lisp
3005 (not (eq (widget-get widget
:custom-form
) 'lisp
)))))
3006 "Alist of actions for the `custom-face' widget.
3007 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3008 the menu entry, ACTION is the function to call on the widget when the
3009 menu is selected, and FILTER is a predicate which takes a `custom-face'
3010 widget as an argument, and returns non-nil if ACTION is valid on that
3011 widget. If FILTER is nil, ACTION is always valid.")
3013 (defun custom-face-edit-selected (widget)
3014 "Edit selected attributes of the value of WIDGET."
3015 (widget-put widget
:custom-state
'unknown
)
3016 (widget-put widget
:custom-form
'selected
)
3017 (custom-redraw widget
))
3019 (defun custom-face-edit-all (widget)
3020 "Edit all attributes of the value of WIDGET."
3021 (widget-put widget
:custom-state
'unknown
)
3022 (widget-put widget
:custom-form
'all
)
3023 (custom-redraw widget
))
3025 (defun custom-face-edit-lisp (widget)
3026 "Edit the Lisp representation of the value of WIDGET."
3027 (widget-put widget
:custom-state
'unknown
)
3028 (widget-put widget
:custom-form
'lisp
)
3029 (custom-redraw widget
))
3031 (defun custom-face-state-set (widget)
3032 "Set the state of WIDGET."
3033 (let* ((symbol (widget-value widget
))
3034 (comment (get symbol
'face-comment
))
3038 (setq tmp
(get symbol
'customized-face
))
3039 (setq temp
(get symbol
'customized-face-comment
))
3041 (if (equal temp comment
)
3045 (setq tmp
(get symbol
'saved-face
))
3046 (setq temp
(get symbol
'saved-face-comment
))
3048 (if (equal temp comment
)
3051 ((get symbol
'face-defface-spec
)
3052 (if (equal comment nil
)
3057 ;; If the user called set-face-attribute to change the default
3058 ;; for new frames, this face is "set outside of Customize".
3059 (if (and (not (eq state
'rogue
))
3060 (get symbol
'face-modified
))
3061 (setq state
'changed
))
3062 (widget-put widget
:custom-state state
)))
3064 (defun custom-face-action (widget &optional event
)
3065 "Show the menu for `custom-face' WIDGET.
3066 Optional EVENT is the location for the menu."
3067 (if (eq (widget-get widget
:custom-state
) 'hidden
)
3068 (custom-toggle-hide widget
)
3069 (let* ((completion-ignore-case t
)
3070 (symbol (widget-get widget
:value
))
3071 (answer (widget-choose (concat "Operation on "
3072 (custom-unlispify-tag-name symbol
))
3073 (custom-menu-filter custom-face-menu
3077 (funcall answer widget
)))))
3079 (defun custom-face-set (widget)
3080 "Make the face attributes in WIDGET take effect."
3081 (let* ((symbol (widget-value widget
))
3082 (child (car (widget-get widget
:children
)))
3083 (value (custom-post-filter-face-spec (widget-value child
)))
3084 (comment-widget (widget-get widget
:comment-widget
))
3085 (comment (widget-value comment-widget
)))
3086 (when (equal comment
"")
3088 ;; Make the comment invisible by hand if it's empty
3089 (custom-comment-hide comment-widget
))
3090 (put symbol
'customized-face value
)
3091 (if (face-spec-choose value
)
3092 (face-spec-set symbol value
)
3093 ;; face-set-spec ignores empty attribute lists, so just give it
3094 ;; something harmless instead.
3095 (face-spec-set symbol
'((t :foreground unspecified
))))
3096 (put symbol
'customized-face-comment comment
)
3097 (put symbol
'face-comment comment
)
3098 (custom-face-state-set widget
)
3099 (custom-redraw-magic widget
)))
3101 (defun custom-face-save-command (widget)
3102 "Save in `.emacs' the face attributes in WIDGET."
3103 (custom-face-save widget
)
3106 (defun custom-face-save (widget)
3107 "Prepare for saving WIDGET's face attributes, but don't write `.emacs'."
3108 (let* ((symbol (widget-value widget
))
3109 (child (car (widget-get widget
:children
)))
3110 (value (custom-post-filter-face-spec (widget-value child
)))
3111 (comment-widget (widget-get widget
:comment-widget
))
3112 (comment (widget-value comment-widget
)))
3113 (when (equal comment
"")
3115 ;; Make the comment invisible by hand if it's empty
3116 (custom-comment-hide comment-widget
))
3117 (if (face-spec-choose value
)
3118 (face-spec-set symbol value
)
3119 ;; face-set-spec ignores empty attribute lists, so just give it
3120 ;; something harmless instead.
3121 (face-spec-set symbol
'((t :foreground unspecified
))))
3122 (unless (eq (widget-get widget
:custom-state
) 'standard
)
3123 (put symbol
'saved-face value
))
3124 (custom-push-theme 'theme-face symbol
'user
'set value
)
3125 (put symbol
'customized-face nil
)
3126 (put symbol
'face-comment comment
)
3127 (put symbol
'customized-face-comment nil
)
3128 (put symbol
'saved-face-comment comment
)
3130 (custom-face-state-set widget
)
3131 (custom-redraw-magic widget
)))
3133 (defun custom-face-reset-saved (widget)
3134 "Restore WIDGET to the face's default attributes."
3135 (let* ((symbol (widget-value widget
))
3136 (child (car (widget-get widget
:children
)))
3137 (value (get symbol
'saved-face
))
3138 (comment (get symbol
'saved-face-comment
))
3139 (comment-widget (widget-get widget
:comment-widget
)))
3140 (unless (or value comment
)
3141 (error "No saved value for this face"))
3142 (put symbol
'customized-face nil
)
3143 (put symbol
'customized-face-comment nil
)
3144 (face-spec-set symbol value
)
3145 (put symbol
'face-comment comment
)
3146 (widget-value-set child value
)
3147 ;; This call manages the comment visibility
3148 (widget-value-set comment-widget
(or comment
""))
3149 (custom-face-state-set widget
)
3150 (custom-redraw-magic widget
)))
3152 (defun custom-face-standard-value (widget)
3153 (get (widget-value widget
) 'face-defface-spec
))
3155 (defun custom-face-reset-standard (widget)
3156 "Restore WIDGET to the face's standard settings.
3157 This operation eliminates any saved setting for the face,
3158 restoring it to the state of a face that has never been customized."
3159 (let* ((symbol (widget-value widget
))
3160 (child (car (widget-get widget
:children
)))
3161 (value (get symbol
'face-defface-spec
))
3162 (comment-widget (widget-get widget
:comment-widget
)))
3164 (error "No standard setting for this face"))
3165 (put symbol
'customized-face nil
)
3166 (put symbol
'customized-face-comment nil
)
3167 (when (or (get symbol
'saved-face
) (get symbol
'saved-face-comment
))
3168 (put symbol
'saved-face nil
)
3169 (custom-push-theme 'theme-face symbol
'user
'reset
'standard
)
3170 ;; Do not explictly save resets to standards without themes.
3171 (if (null (cdr (get symbol
'theme-face
)))
3172 (put symbol
'theme-face nil
))
3173 (put symbol
'saved-face-comment nil
)
3175 (face-spec-set symbol value
)
3176 (put symbol
'face-comment nil
)
3177 (widget-value-set child value
)
3178 ;; This call manages the comment visibility
3179 (widget-value-set comment-widget
"")
3180 (custom-face-state-set widget
)
3181 (custom-redraw-magic widget
)))
3183 ;;; The `face' Widget.
3185 (define-widget 'face
'default
3186 "Select and customize a face."
3187 :convert-widget
'widget-value-convert-widget
3188 :button-prefix
'widget-push-button-prefix
3189 :button-suffix
'widget-push-button-suffix
3190 :format
"%{%t%}: %[select face%] %v"
3193 :value-create
'widget-face-value-create
3194 :value-delete
'widget-face-value-delete
3195 :value-get
'widget-value-value-get
3196 :validate
'widget-children-validate
3197 :action
'widget-face-action
3198 :match
(lambda (widget value
) (symbolp value
)))
3200 (defun widget-face-value-create (widget)
3201 "Create a `custom-face' child."
3202 (let* ((symbol (widget-value widget
))
3203 (custom-buffer-style 'face
)
3204 (child (widget-create-child-and-convert
3208 (custom-magic-reset child
)
3209 (setq custom-options
(cons child custom-options
))
3210 (widget-put widget
:children
(list child
))))
3212 (defun widget-face-value-delete (widget)
3213 "Remove the child from the options."
3214 (let ((child (car (widget-get widget
:children
))))
3215 (setq custom-options
(delq child custom-options
))
3216 (widget-children-value-delete widget
)))
3218 (defvar face-history nil
3219 "History of entered face names.")
3221 (defun widget-face-action (widget &optional event
)
3222 "Prompt for a face."
3223 (let ((answer (completing-read "Face: "
3224 (mapcar (lambda (face)
3225 (list (symbol-name face
)))
3229 (unless (zerop (length answer
))
3230 (widget-value-set widget
(intern answer
))
3231 (widget-apply widget
:notify widget event
)
3234 ;;; The `hook' Widget.
3236 (define-widget 'hook
'list
3238 :value-to-internal
(lambda (widget value
)
3239 (if (and value
(symbolp value
))
3242 :match
(lambda (widget value
)
3244 (widget-group-match widget value
)))
3245 ;; Avoid adding undefined functions to the hook, especially for
3246 ;; things like `find-file-hook' or even more basic ones, to avoid
3248 :set
(lambda (symbol value
)
3251 (add-hook symbol elt
))))
3252 :convert-widget
'custom-hook-convert-widget
3255 (defun custom-hook-convert-widget (widget)
3256 ;; Handle `:options'.
3257 (let* ((options (widget-get widget
:options
))
3258 (other `(editable-list :inline t
3259 :entry-format
"%i %d%v"
3260 (function :format
" %v")))
3262 (list `(checklist :inline t
3263 ,@(mapcar (lambda (entry)
3264 `(function-item ,entry
))
3268 (widget-put widget
:args args
)
3271 ;;; The `custom-group-link' Widget.
3273 (define-widget 'custom-group-link
'link
3274 "Show parent in other window when activated."
3275 :help-echo
"Create customization buffer for this group."
3276 :action
'custom-group-link-action
)
3278 (defun custom-group-link-action (widget &rest ignore
)
3279 (customize-group (widget-value widget
)))
3281 ;;; The `custom-group' Widget.
3283 (defcustom custom-group-tag-faces nil
3284 ;; In XEmacs, this ought to play games with font size.
3285 ;; Fixme: make it do so in Emacs.
3286 "Face used for group tags.
3287 The first member is used for level 1 groups, the second for level 2,
3288 and so forth. The remaining group tags are shown with
3289 `custom-group-tag-face'."
3290 :type
'(repeat face
)
3291 :group
'custom-faces
)
3293 (defface custom-group-tag-face-1
3296 (:foreground
"pink" :weight bold
:height
1.2 :inherit variable-pitch
))
3299 (:foreground
"red" :weight bold
:height
1.2 :inherit variable-pitch
))
3301 "Face used for group tags."
3302 :group
'custom-faces
)
3304 (defface custom-group-tag-face
3307 (:foreground
"light blue" :weight bold
:height
1.2))
3310 (:foreground
"blue" :weight bold
:height
1.2))
3312 "Face used for low level group tags."
3313 :group
'custom-faces
)
3315 (define-widget 'custom-group
'custom
3318 :sample-face-get
'custom-group-sample-face-get
3319 :documentation-property
'group-documentation
3320 :help-echo
"Set or reset all members of this group."
3321 :value-create
'custom-group-value-create
3322 :action
'custom-group-action
3323 :custom-category
'group
3324 :custom-set
'custom-group-set
3325 :custom-save
'custom-group-save
3326 :custom-reset-current
'custom-group-reset-current
3327 :custom-reset-saved
'custom-group-reset-saved
3328 :custom-reset-standard
'custom-group-reset-standard
3329 :custom-menu
'custom-group-menu-create
)
3331 (defun custom-group-sample-face-get (widget)
3332 ;; Use :sample-face.
3333 (or (nth (1- (widget-get widget
:custom-level
)) custom-group-tag-faces
)
3334 'custom-group-tag-face
))
3336 (define-widget 'custom-group-visibility
'visibility
3337 "An indicator and manipulator for hidden group contents."
3338 :create
'custom-group-visibility-create
)
3340 (defun custom-group-visibility-create (widget)
3341 (let ((visible (widget-value widget
)))
3343 (insert "--------")))
3344 (widget-default-create widget
))
3346 (defun custom-group-members (symbol groups-only
)
3347 "Return SYMBOL's custom group members.
3348 If GROUPS-ONLY non-nil, return only those members that are groups."
3349 (if (not groups-only
)
3350 (get symbol
'custom-group
)
3352 (dolist (entry (get symbol
'custom-group
))
3353 (when (eq (nth 1 entry
) 'custom-group
)
3354 (push entry members
)))
3355 (nreverse members
))))
3357 (defun custom-group-value-create (widget)
3358 "Insert a customize group for WIDGET in the current buffer."
3359 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
3360 (custom-load-widget widget
))
3361 (let* ((state (widget-get widget
:custom-state
))
3362 (level (widget-get widget
:custom-level
))
3363 ;; (indent (widget-get widget :indent))
3364 (prefix (widget-get widget
:custom-prefix
))
3365 (buttons (widget-get widget
:buttons
))
3366 (tag (widget-get widget
:tag
))
3367 (symbol (widget-value widget
))
3368 (members (custom-group-members symbol
3369 (and (eq custom-buffer-style
'tree
)
3370 custom-browse-only-groups
))))
3371 (cond ((and (eq custom-buffer-style
'tree
)
3373 (or members
(custom-unloaded-widget-p widget
)))
3374 (custom-browse-insert-prefix prefix
)
3375 (push (widget-create-child-and-convert
3376 widget
'custom-browse-visibility
3377 ;; :tag-glyph "plus"
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 ((and (eq custom-buffer-style
'tree
)
3388 (zerop (length members
)))
3389 (custom-browse-insert-prefix prefix
)
3391 ;; (widget-glyph-insert nil "[ ]" "empty")
3392 ;; (widget-glyph-insert nil "-- " "horizontal")
3393 (push (widget-create-child-and-convert
3394 widget
'custom-browse-group-tag
)
3396 (insert " " tag
"\n")
3397 (widget-put widget
:buttons buttons
))
3398 ((eq custom-buffer-style
'tree
)
3399 (custom-browse-insert-prefix prefix
)
3400 (if (zerop (length members
))
3402 (custom-browse-insert-prefix prefix
)
3404 ;; (widget-glyph-insert nil "[ ]" "empty")
3405 ;; (widget-glyph-insert nil "-- " "horizontal")
3406 (push (widget-create-child-and-convert
3407 widget
'custom-browse-group-tag
)
3409 (insert " " tag
"\n")
3410 (widget-put widget
:buttons buttons
))
3411 (push (widget-create-child-and-convert
3412 widget
'custom-browse-visibility
3413 ;; :tag-glyph "minus"
3417 ;; (widget-glyph-insert nil "-\\ " "top")
3418 (push (widget-create-child-and-convert
3419 widget
'custom-browse-group-tag
)
3421 (insert " " tag
"\n")
3422 (widget-put widget
:buttons buttons
)
3423 (message "Creating group...")
3424 (let* ((members (custom-sort-items members
3425 custom-browse-sort-alphabetically
3426 custom-browse-order-groups
))
3427 (prefixes (widget-get widget
:custom-prefixes
))
3428 (custom-prefix-list (custom-prefix-add symbol prefixes
))
3429 (extra-prefix (if (widget-get widget
:custom-last
)
3432 (prefix (concat prefix extra-prefix
))
3435 (setq entry
(car members
)
3436 members
(cdr members
))
3437 (push (widget-create-child-and-convert
3438 widget
(nth 1 entry
)
3440 :tag
(custom-unlispify-tag-name (nth 0 entry
))
3441 :custom-prefixes custom-prefix-list
3442 :custom-level
(1+ level
)
3443 :custom-last
(null members
)
3444 :value
(nth 0 entry
)
3445 :custom-prefix prefix
)
3447 (widget-put widget
:children
(reverse children
)))
3448 (message "Creating group...done")))
3451 ;; Create level indicator.
3452 (unless (eq custom-buffer-style
'links
)
3453 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3456 (let ((begin (point)))
3458 (widget-specify-sample widget begin
(point)))
3460 ;; Create link/visibility indicator.
3461 (if (eq custom-buffer-style
'links
)
3462 (push (widget-create-child-and-convert
3463 widget
'custom-group-link
3467 (push (widget-create-child-and-convert
3468 widget
'custom-group-visibility
3469 :help-echo
"Show members of this group."
3470 :action
'custom-toggle-parent
3471 (not (eq state
'hidden
)))
3474 ;; Create magic button.
3475 (let ((magic (widget-create-child-and-convert
3476 widget
'custom-magic nil
)))
3477 (widget-put widget
:custom-magic magic
)
3478 (push magic buttons
))
3480 (widget-put widget
:buttons buttons
)
3481 ;; Insert documentation.
3482 (if (and (eq custom-buffer-style
'links
) (> level
1))
3483 (widget-put widget
:documentation-indent
0))
3484 (widget-default-format-handler widget ?h
))
3487 ;; Add parent groups references above the group.
3488 (if t
;;; This should test that the buffer
3489 ;;; was made to display a group.
3491 (if (custom-add-parent-links widget
3492 "Go to parent group:")
3494 ;; Create level indicator.
3495 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3498 (let ((start (point)))
3500 (widget-specify-sample widget start
(point)))
3502 ;; Create visibility indicator.
3503 (unless (eq custom-buffer-style
'links
)
3505 (push (widget-create-child-and-convert
3507 :help-echo
"Hide members of this group."
3508 :action
'custom-toggle-parent
3509 (not (eq state
'hidden
)))
3512 ;; Create more dashes.
3513 ;; Use 76 instead of 75 to compensate for the temporary "<"
3514 ;; added by `widget-insert'.
3515 (insert-char ?-
(- 76 (current-column)
3516 (* custom-buffer-indent level
)))
3518 ;; Create magic button.
3519 (let ((magic (widget-create-child-and-convert
3520 widget
'custom-magic
3523 (widget-put widget
:custom-magic magic
)
3524 (push magic buttons
))
3526 (widget-put widget
:buttons buttons
)
3527 ;; Insert documentation.
3528 (widget-default-format-handler widget ?h
)
3530 (if nil
;;; This should test that the buffer
3531 ;;; was not made to display a group.
3533 (insert-char ?\ custom-buffer-indent
)
3534 (custom-add-parent-links widget
)))
3535 (custom-add-see-also widget
3536 (make-string (* custom-buffer-indent level
)
3539 (message "Creating group...")
3540 (let* ((members (custom-sort-items members
3541 custom-buffer-sort-alphabetically
3542 custom-buffer-order-groups
))
3543 (prefixes (widget-get widget
:custom-prefixes
))
3544 (custom-prefix-list (custom-prefix-add symbol prefixes
))
3545 (length (length members
))
3547 (children (mapcar (lambda (entry)
3548 (widget-insert "\n")
3550 Creating group members... %2d%%"
3551 (/ (* 100.0 count
) length
))
3552 (setq count
(1+ count
))
3554 (widget-create-child-and-convert
3555 widget
(nth 1 entry
)
3557 :tag
(custom-unlispify-tag-name
3559 :custom-prefixes custom-prefix-list
3560 :custom-level
(1+ level
)
3561 :value
(nth 0 entry
))
3562 (unless (eq (preceding-char) ?
\n)
3563 (widget-insert "\n"))))
3565 (message "Creating group magic...")
3566 (mapc 'custom-magic-reset children
)
3567 (message "Creating group state...")
3568 (widget-put widget
:children children
)
3569 (custom-group-state-update widget
)
3570 (message "Creating group... done"))
3573 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3574 (insert "\\- " (widget-get widget
:tag
) " group end ")
3575 (insert-char ?-
(- 75 (current-column) (* custom-buffer-indent level
)))
3578 (defvar custom-group-menu
3579 '(("Set for Current Session" custom-group-set
3581 (eq (widget-get widget
:custom-state
) 'modified
)))
3582 ("Save for Future Sessions" custom-group-save
3584 (memq (widget-get widget
:custom-state
) '(modified set
))))
3585 ("Reset to Current" custom-group-reset-current
3587 (memq (widget-get widget
:custom-state
) '(modified))))
3588 ("Reset to Saved" custom-group-reset-saved
3590 (memq (widget-get widget
:custom-state
) '(modified set
))))
3591 ("Reset to standard setting" custom-group-reset-standard
3593 (memq (widget-get widget
:custom-state
) '(modified set saved
)))))
3594 "Alist of actions for the `custom-group' widget.
3595 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3596 the menu entry, ACTION is the function to call on the widget when the
3597 menu is selected, and FILTER is a predicate which takes a `custom-group'
3598 widget as an argument, and returns non-nil if ACTION is valid on that
3599 widget. If FILTER is nil, ACTION is always valid.")
3601 (defun custom-group-action (widget &optional event
)
3602 "Show the menu for `custom-group' WIDGET.
3603 Optional EVENT is the location for the menu."
3604 (if (eq (widget-get widget
:custom-state
) 'hidden
)
3605 (custom-toggle-hide widget
)
3606 (let* ((completion-ignore-case t
)
3607 (answer (widget-choose (concat "Operation on "
3608 (custom-unlispify-tag-name
3609 (widget-get widget
:value
)))
3610 (custom-menu-filter custom-group-menu
3614 (funcall answer widget
)))))
3616 (defun custom-group-set (widget)
3617 "Set changes in all modified group members."
3618 (let ((children (widget-get widget
:children
)))
3619 (mapc (lambda (child)
3620 (when (eq (widget-get child
:custom-state
) 'modified
)
3621 (widget-apply child
:custom-set
)))
3624 (defun custom-group-save (widget)
3625 "Save all modified group members."
3626 (let ((children (widget-get widget
:children
)))
3627 (mapc (lambda (child)
3628 (when (memq (widget-get child
:custom-state
) '(modified set
))
3629 (widget-apply child
:custom-save
)))
3632 (defun custom-group-reset-current (widget)
3633 "Reset all modified group members."
3634 (let ((children (widget-get widget
:children
)))
3635 (mapc (lambda (child)
3636 (when (eq (widget-get child
:custom-state
) 'modified
)
3637 (widget-apply child
:custom-reset-current
)))
3640 (defun custom-group-reset-saved (widget)
3641 "Reset all modified or set group members."
3642 (let ((children (widget-get widget
:children
)))
3643 (mapc (lambda (child)
3644 (when (memq (widget-get child
:custom-state
) '(modified set
))
3645 (widget-apply child
:custom-reset-saved
)))
3648 (defun custom-group-reset-standard (widget)
3649 "Reset all modified, set, or saved group members."
3650 (let ((children (widget-get widget
:children
)))
3651 (mapc (lambda (child)
3652 (when (memq (widget-get child
:custom-state
)
3653 '(modified set saved
))
3654 (widget-apply child
:custom-reset-standard
)))
3657 (defun custom-group-state-update (widget)
3659 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
3660 (let* ((children (widget-get widget
:children
))
3661 (states (mapcar (lambda (child)
3662 (widget-get child
:custom-state
))
3664 (magics custom-magic-alist
)
3667 (let ((magic (car (car magics
))))
3668 (if (and (not (eq magic
'hidden
))
3669 (memq magic states
))
3672 (setq magics
(cdr magics
)))))
3673 (widget-put widget
:custom-state found
)))
3674 (custom-magic-reset widget
))
3676 ;;; The `custom-save-all' Function.
3678 (defcustom custom-file nil
3679 "File used for storing customization information.
3680 The default is nil, which means to use your init file
3681 as specified by `user-init-file'. If you specify some other file,
3682 you need to explicitly load that file for the settings to take effect.
3684 When you change this variable, look in the previous custom file
3685 \(usually your init file) for the forms `(custom-set-variables ...)'
3686 and `(custom-set-faces ...)', and copy them (whichever ones you find)
3687 to the new custom file. This will preserve your existing customizations."
3688 :type
'(choice (const :tag
"Your Emacs init file" nil
) file
)
3691 (defun custom-file ()
3692 "Return the file name for saving customizations."
3695 (let ((user-init-file user-init-file
)
3697 (if (eq system-type
'ms-dos
) "~/_emacs" "~/.emacs")))
3698 (when (null user-init-file
)
3699 (if (or (file-exists-p default-init-file
)
3700 (and (eq system-type
'windows-nt
)
3701 (file-exists-p "~/_emacs")))
3702 ;; Started with -q, i.e. the file containing
3703 ;; Custom settings hasn't been read. Saving
3704 ;; settings there would overwrite other settings.
3705 (error "Saving settings from \"emacs -q\" would overwrite existing customizations"))
3706 (setq user-init-file default-init-file
))
3709 (defun custom-save-delete (symbol)
3710 "Visit `custom-file' and delete all calls to SYMBOL from it.
3711 Leave point at the old location of the first such call,
3712 or (if there were none) at the end of the buffer."
3713 (let ((default-major-mode 'emacs-lisp-mode
))
3714 (set-buffer (find-file-noselect (custom-file))))
3715 (goto-char (point-min))
3716 ;; Skip all whitespace and comments.
3717 (while (forward-comment 1))
3719 (save-excursion (forward-sexp (buffer-size)))) ; Test for scan errors.
3722 (while t
;; We exit this loop only via throw.
3723 ;; Skip all whitespace and comments.
3724 (while (forward-comment 1))
3725 (let ((start (point))
3726 (sexp (condition-case nil
3727 (read (current-buffer))
3728 (end-of-file (throw 'found nil
)))))
3729 (when (and (listp sexp
)
3730 (eq (car sexp
) symbol
))
3731 (delete-region start
(point))
3733 (setq first
(point)))))))
3736 ;; Move in front of local variables, otherwise long Custom
3737 ;; entries would make them ineffective.
3738 (let ((pos (point-max))
3739 (case-fold-search t
))
3741 (goto-char (point-max))
3742 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
3744 (when (search-forward "Local Variables:" nil t
)
3745 (setq pos
(line-beginning-position))))
3748 (defun custom-save-variables ()
3749 "Save all customized variables in `custom-file'."
3751 (custom-save-delete 'custom-load-themes
)
3752 (custom-save-delete 'custom-reset-variables
)
3753 (custom-save-delete 'custom-set-variables
)
3754 (custom-save-loaded-themes)
3755 (custom-save-resets 'theme-value
'custom-reset-variables nil
)
3756 (let ((standard-output (current-buffer))
3757 (saved-list (make-list 1 0))
3759 ;; First create a sorted list of saved variables.
3762 (if (get symbol
'saved-value
)
3763 (nconc saved-list
(list symbol
)))))
3764 (setq saved-list
(sort (cdr saved-list
) 'string
<))
3767 (princ "(custom-set-variables
3768 ;; custom-set-variables was added by Custom.
3769 ;; If you edit it by hand, you could mess it up, so be careful.
3770 ;; Your init file should contain only one such instance.
3771 ;; If there is more than one, they won't work right.\n")
3772 (dolist (symbol saved-list
)
3773 (let ((spec (car-safe (get symbol
'theme-value
)))
3774 (value (get symbol
'saved-value
))
3775 (requests (get symbol
'custom-requests
))
3776 (now (not (or (custom-variable-p symbol
)
3777 (and (not (boundp symbol
))
3778 (not (eq (get symbol
'force-value
)
3780 (comment (get symbol
'saved-variable-comment
)))
3781 ;; Check `requests'.
3782 (dolist (request requests
)
3783 (when (and (symbolp request
) (not (featurep request
)))
3784 (message "Unknown requested feature: %s" request
)
3785 (setq requests
(delq request requests
))))
3787 (eq (nth 0 spec
) 'user
)
3788 (eq (nth 1 spec
) 'set
))
3790 (and (null spec
) (get symbol
'saved-value
)))
3797 (when (or now requests comment
)
3800 (when (or requests comment
)
3810 (unless (looking-at "\n")
3813 (defun custom-save-faces ()
3814 "Save all customized faces in `custom-file'."
3816 (custom-save-delete 'custom-reset-faces
)
3817 (custom-save-delete 'custom-set-faces
)
3818 (custom-save-resets 'theme-face
'custom-reset-faces
'(default))
3819 (let ((standard-output (current-buffer))
3820 (saved-list (make-list 1 0))
3822 ;; First create a sorted list of saved faces.
3825 (if (get symbol
'saved-face
)
3826 (nconc saved-list
(list symbol
)))))
3827 (setq saved-list
(sort (cdr saved-list
) 'string
<))
3828 ;; The default face must be first, since it affects the others.
3829 (if (memq 'default saved-list
)
3830 (setq saved-list
(cons 'default
(delq 'default saved-list
))))
3833 (princ "(custom-set-faces
3834 ;; custom-set-faces was added by Custom.
3835 ;; If you edit it by hand, you could mess it up, so be careful.
3836 ;; Your init file should contain only one such instance.
3837 ;; If there is more than one, they won't work right.\n")
3838 (dolist (symbol saved-list
)
3839 (let ((spec (car-safe (get symbol
'theme-face
)))
3840 (value (get symbol
'saved-face
))
3841 (now (not (or (get symbol
'face-defface-spec
)
3842 (and (not (custom-facep symbol
))
3843 (not (get symbol
'force-face
))))))
3844 (comment (get symbol
'saved-face-comment
)))
3846 (eq (nth 0 spec
) 'user
)
3847 (eq (nth 1 spec
) 'set
))
3849 (and (null spec
) (get symbol
'saved-face
)))
3850 ;; Don't print default face here.
3857 (when (or now comment
)
3867 (unless (looking-at "\n")
3870 (defun custom-save-resets (property setter special
)
3871 (let (started-writing ignored-special
)
3872 ;; (custom-save-delete setter) Done by caller
3873 (let ((standard-output (current-buffer))
3874 (mapper `(lambda (object)
3875 (let ((spec (car-safe (get object
(quote ,property
)))))
3876 (when (and (not (memq object ignored-special
))
3877 (eq (nth 0 spec
) 'user
)
3878 (eq (nth 1 spec
) 'reset
))
3879 ;; Do not write reset statements unless necessary.
3880 (unless started-writing
3881 (setq started-writing t
)
3885 (princ (quote ,setter
))
3889 (prin1 (nth 3 spec
))
3891 (mapc mapper special
)
3892 (setq ignored-special special
)
3894 (when started-writing
3897 (defun custom-save-loaded-themes ()
3898 (let ((themes (reverse (get 'user
'theme-loads-themes
)))
3899 (standard-output (current-buffer)))
3901 (unless (bolp) (princ "\n"))
3902 (princ "(custom-load-themes")
3903 (mapc (lambda (theme)
3905 (prin1 theme
)) themes
)
3909 (defun customize-save-customized ()
3910 "Save all user options which have been set in this session."
3912 (mapatoms (lambda (symbol)
3913 (let ((face (get symbol
'customized-face
))
3914 (value (get symbol
'customized-value
))
3915 (face-comment (get symbol
'customized-face-comment
))
3917 (get symbol
'customized-variable-comment
)))
3919 (put symbol
'saved-face face
)
3920 (custom-push-theme 'theme-face symbol
'user
'set value
)
3921 (put symbol
'customized-face nil
))
3923 (put symbol
'saved-value value
)
3924 (custom-push-theme 'theme-value symbol
'user
'set value
)
3925 (put symbol
'customized-value nil
))
3926 (when variable-comment
3927 (put symbol
'saved-variable-comment variable-comment
)
3928 (put symbol
'customized-variable-comment nil
))
3930 (put symbol
'saved-face-comment face-comment
)
3931 (put symbol
'customized-face-comment nil
)))))
3932 ;; We really should update all custom buffers here.
3936 (defun custom-save-all ()
3937 "Save all customizations in `custom-file'."
3938 (let ((inhibit-read-only t
))
3939 (custom-save-variables)
3942 (let ((default-major-mode nil
))
3943 (set-buffer (find-file-noselect (custom-file))))
3944 (let ((file-precious-flag t
))
3947 ;;; The Customize Menu.
3951 (defcustom custom-menu-nesting
2
3952 "Maximum nesting in custom menus."
3954 :group
'custom-menu
)
3956 (defun custom-face-menu-create (widget symbol
)
3957 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
3958 (vector (custom-unlispify-menu-entry symbol
)
3959 `(customize-face ',symbol
)
3962 (defun custom-variable-menu-create (widget symbol
)
3963 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
3964 (let ((type (get symbol
'custom-type
)))
3965 (unless (listp type
)
3966 (setq type
(list type
)))
3967 (if (and type
(widget-get type
:custom-menu
))
3968 (widget-apply type
:custom-menu symbol
)
3969 (vector (custom-unlispify-menu-entry symbol
)
3970 `(customize-variable ',symbol
)
3973 ;; Add checkboxes to boolean variable entries.
3974 (widget-put (get 'boolean
'widget-type
)
3975 :custom-menu
(lambda (widget symbol
)
3976 (vector (custom-unlispify-menu-entry symbol
)
3977 `(customize-variable ',symbol
)
3979 ':selected symbol
)))
3981 (defun custom-group-menu-create (widget symbol
)
3982 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
3983 `( ,(custom-unlispify-menu-entry symbol t
)
3984 :filter
(lambda (&rest junk
)
3985 (let ((menu (custom-menu-create ',symbol
)))
3986 (if (consp menu
) (cdr menu
) menu
)))))
3989 (defun custom-menu-create (symbol)
3990 "Create menu for customization group SYMBOL.
3991 The menu is in a format applicable to `easy-menu-define'."
3992 (let* ((item (vector (custom-unlispify-menu-entry symbol
)
3993 `(customize-group ',symbol
)
3995 (if (and (or (not (boundp 'custom-menu-nesting
))
3996 (>= custom-menu-nesting
0))
3998 (custom-load-symbol symbol
)
3999 (< (length (get symbol
'custom-group
)) widget-menu-max-size
)))
4000 (let ((custom-prefix-list (custom-prefix-add symbol
4001 custom-prefix-list
))
4002 (members (custom-sort-items (get symbol
'custom-group
)
4003 custom-menu-sort-alphabetically
4004 custom-menu-order-groups
)))
4005 `(,(custom-unlispify-menu-entry symbol t
)
4008 ,@(mapcar (lambda (entry)
4009 (widget-apply (if (listp (nth 1 entry
))
4011 (list (nth 1 entry
)))
4012 :custom-menu
(nth 0 entry
)))
4017 (defun customize-menu-create (symbol &optional name
)
4018 "Return a customize menu for customization group SYMBOL.
4019 If optional NAME is given, use that as the name of the menu.
4020 Otherwise the menu will be named `Customize'.
4021 The format is suitable for use with `easy-menu-define'."
4023 (setq name
"Customize"))
4025 :filter
(lambda (&rest junk
)
4026 (let ((menu (custom-menu-create ',symbol
)))
4027 (if (consp menu
) (cdr menu
) menu
)))))
4029 ;;; The Custom Mode.
4031 (defvar custom-mode-map nil
4032 "Keymap for `custom-mode'.")
4034 (unless custom-mode-map
4035 ;; This keymap should be dense, but a dense keymap would prevent inheriting
4036 ;; "\r" bindings from the parent map.
4037 (setq custom-mode-map
(make-sparse-keymap))
4038 (set-keymap-parent custom-mode-map widget-keymap
)
4039 (suppress-keymap custom-mode-map
)
4040 (define-key custom-mode-map
" " 'scroll-up
)
4041 (define-key custom-mode-map
"\177" 'scroll-down
)
4042 (define-key custom-mode-map
"\C-x\C-s" 'Custom-save
)
4043 (define-key custom-mode-map
"q" 'Custom-buffer-done
)
4044 (define-key custom-mode-map
"u" 'Custom-goto-parent
)
4045 (define-key custom-mode-map
"n" 'widget-forward
)
4046 (define-key custom-mode-map
"p" 'widget-backward
)
4047 (define-key custom-mode-map
[mouse-1
] 'Custom-move-and-invoke
))
4049 (defun Custom-move-and-invoke (event)
4050 "Move to where you click, and if it is an active field, invoke it."
4052 (mouse-set-point event
)
4053 (if (widget-event-point event
)
4054 (let* ((pos (widget-event-point event
))
4055 (button (get-char-property pos
'button
)))
4057 (widget-button-click event
)))))
4059 (easy-menu-define Custom-mode-menu
4061 "Menu used in customization buffers."
4063 ,(customize-menu-create 'customize
)
4064 ["Set" Custom-set t
]
4065 ["Save" Custom-save t
]
4066 ["Reset to Current" Custom-reset-current t
]
4067 ["Reset to Saved" Custom-reset-saved t
]
4068 ["Reset to Standard Settings" Custom-reset-standard t
]
4069 ["Info" (Info-goto-node "(emacs)Easy Customization") t
]))
4071 (defun Custom-goto-parent ()
4072 "Go to the parent group listed at the top of this buffer.
4073 If several parents are listed, go to the first of them."
4076 (goto-char (point-min))
4077 (if (search-forward "\nGo to parent group: " nil t
)
4078 (let* ((button (get-char-property (point) 'button
))
4079 (parent (downcase (widget-get button
:tag
))))
4080 (customize-group parent
)))))
4082 (defcustom custom-mode-hook nil
4083 "Hook called when entering Custom mode."
4085 :group
'custom-buffer
)
4087 (defun custom-state-buffer-message (widget)
4088 (if (eq (widget-get (widget-get widget
:parent
) :custom-state
) 'modified
)
4089 (message "To install your edits, invoke [State] and choose the Set operation")))
4091 (defun custom-mode ()
4092 "Major mode for editing customization buffers.
4094 The following commands are available:
4096 Move to next button or editable field. \\[widget-forward]
4097 Move to previous button or editable field. \\[widget-backward]
4098 \\<widget-field-keymap>\
4099 Complete content of editable text field. \\[widget-complete]
4100 \\<custom-mode-map>\
4101 Invoke button under the mouse pointer. \\[Custom-move-and-invoke]
4102 Invoke button under point. \\[widget-button-press]
4103 Set all modifications. \\[Custom-set]
4104 Make all modifications default. \\[Custom-save]
4105 Reset all modified options. \\[Custom-reset-current]
4106 Reset all modified or set options. \\[Custom-reset-saved]
4107 Reset all options. \\[Custom-reset-standard]
4109 Entry to this mode calls the value of `custom-mode-hook'
4110 if that value is non-nil."
4111 (kill-all-local-variables)
4112 (setq major-mode
'custom-mode
4114 (use-local-map custom-mode-map
)
4115 (easy-menu-add Custom-mode-menu
)
4116 (make-local-variable 'custom-options
)
4117 (make-local-variable 'custom-local-buffer
)
4118 (make-local-variable 'widget-documentation-face
)
4119 (setq widget-documentation-face
'custom-documentation-face
)
4120 (make-local-variable 'widget-button-face
)
4121 (setq widget-button-face
'custom-button-face
)
4122 (set (make-local-variable 'widget-button-pressed-face
)
4123 'custom-button-pressed-face
)
4124 (set (make-local-variable 'widget-mouse-face
)
4125 'custom-button-pressed-face
) ; buttons `depress' when moused
4126 ;; When possible, use relief for buttons, not bracketing. This test
4127 ;; may not be optimal.
4128 (when custom-raised-buttons
4129 (set (make-local-variable 'widget-push-button-prefix
) "")
4130 (set (make-local-variable 'widget-push-button-suffix
) "")
4131 (set (make-local-variable 'widget-link-prefix
) "")
4132 (set (make-local-variable 'widget-link-suffix
) ""))
4133 (add-hook 'widget-edit-functions
'custom-state-buffer-message nil t
)
4134 (run-hooks 'custom-mode-hook
))
4136 (put 'custom-mode
'mode-class
'special
)
4139 'debug-ignored-errors
4140 "^No user options have changed defaults in recent Emacs versions$")
4146 ;;; arch-tag: 64533aa4-1b1a-48c3-8812-f9dc718e8a6f
4147 ;;; cus-edit.el ends here