1 ;;; cus-edit.el --- tools for customizing Emacs and Lisp packages
3 ;; Copyright (C) 1996, 1997, 1999, 2000, 2001, 2002, 2003, 2004, 2005
4 ;; Free Software Foundation, Inc.
6 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
8 ;; Keywords: help, faces
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
29 ;; This file implements the code to create and edit customize buffers.
33 ;; No commands should have names starting with `custom-' because
34 ;; that interferes with completion. Use `customize-' for commands
35 ;; that the user will run with M-x, and `Custom-' for interactive commands.
37 ;; The identity of a customize option is represented by a Lisp symbol.
38 ;; The following values are associated with an option.
40 ;; 0. The current value.
42 ;; This is the value of the option as seen by "the rest of Emacs".
44 ;; Usually extracted by 'default-value', but can be extracted with
45 ;; different means if the option symbol has the 'custom-get'
46 ;; property. Similarly, set-default (or the 'custom-set' property)
49 ;; 1. The widget value.
51 ;; This is the value shown in the widget in a customize buffer.
53 ;; 2. The customized value.
55 ;; This is the last value given to the option through customize.
57 ;; It is stored in the 'customized-value' property of the option, in a
58 ;; cons-cell whose car evaluates to the customized value.
60 ;; 3. The saved value.
62 ;; This is last value saved from customize.
64 ;; It is stored in the 'saved-value' property of the option, in a
65 ;; cons-cell whose car evaluates to the saved value.
67 ;; 4. The standard value.
69 ;; This is the value given in the 'defcustom' declaration.
71 ;; It is stored in the 'standard-value' property of the option, in a
72 ;; cons-cell whose car evaluates to the standard value.
74 ;; 5. The "think" value.
76 ;; This is what customize thinks the current value should be.
78 ;; This is the customized value, if any such value exists, otherwise
79 ;; the saved value, if that exists, and as a last resort the standard
82 ;; The reason for storing values unevaluated: This is so you can have
83 ;; values that depend on the environment. For example, you can have a
84 ;; variable that has one value when Emacs is running under a window
85 ;; system, and another value on a tty. Since the evaluation is only done
86 ;; when the variable is first initialized, this is only relevant for the
87 ;; saved (and standard) values, but affect others values for
90 ;; You can see (and modify and save) this unevaluated value by selecting
91 ;; "Show initial Lisp expression" from the Lisp interface. This will
92 ;; give you the unevaluated saved value, if any, otherwise the
93 ;; unevaluated standard value.
95 ;; The possible states for a customize widget are:
99 ;; The state has not been determined yet.
103 ;; The widget value is different from the current value.
107 ;; The current value is different from the "think" value.
111 ;; The "think" value is the customized value.
115 ;; The "think" value is the saved value.
119 ;; The "think" value is the standard value.
123 ;; There is no standard value. This means that the variable was
124 ;; not defined with defcustom, nor handled in cus-start.el. You
125 ;; can not create a Custom buffer for such variables using the
126 ;; normal interactive Custom commands. However, such Custom
127 ;; buffers can be created in other ways, for instance, by calling
128 ;; `customize-option' non-interactively.
132 ;; There is no widget value.
136 ;; The widget value is not valid member of the :type specified for the
144 (defvar custom-versions-load-alist
)) ; from cus-load
154 (put 'custom-define-hook
'custom-type
'hook
)
155 (put 'custom-define-hook
'standard-value
'(nil))
156 (custom-add-to-group 'customize
'custom-define-hook
'custom-variable
)
158 ;;; Customization Groups.
161 "Customization of the One True Editor."
162 :link
'(custom-manual "(emacs)Top"))
164 ;; Most of these groups are stolen from `finder.el',
165 (defgroup editing nil
166 "Basic text editing facilities."
170 "Abbreviation handling, typing shortcuts, macros."
174 (defgroup matching nil
175 "Various sorts of searching and matching."
178 (defgroup emulations nil
179 "Emulations of other editors."
180 :link
'(custom-manual "(emacs)Emulation")
187 (defgroup outlines nil
188 "Support for hierarchical outlining."
191 (defgroup external nil
192 "Interfacing to external utilities."
195 (defgroup processes nil
196 "Process, subshell, compilation, and job control support."
200 (defgroup convenience nil
201 "Convenience features for faster editing."
204 (defgroup programming nil
205 "Support for programming in other languages."
208 (defgroup languages nil
209 "Specialized modes for editing programming languages."
213 "Lisp support, including Emacs Lisp."
218 "Support for the C language and related languages."
219 :link
'(custom-manual "(ccmode)")
227 "Support for object-oriented programming."
230 (defgroup applications nil
231 "Applications written in Emacs."
234 (defgroup calendar nil
235 "Calendar and time management support."
236 :group
'applications
)
239 "Modes for electronic-mail handling."
240 :group
'applications
)
243 "Support for netnews reading and posting."
244 :link
'(custom-manual "(gnus)")
245 :group
'applications
)
248 "Games, jokes and amusements."
249 :group
'applications
)
251 (defgroup development nil
252 "Support for further development of Emacs."
256 "Support for Emacs documentation."
259 (defgroup extensions nil
260 "Emacs Lisp language extensions."
263 (defgroup internal nil
264 "Code for Emacs internals, build process, defaults."
268 "Maintenance aids for the Emacs development group."
272 (defgroup environment nil
273 "Fitting Emacs with its environment."
277 "Communications, networking, remote access to files."
281 (defgroup hardware nil
282 "Support for interfacing with exotic hardware."
285 (defgroup terminals nil
286 "Support for terminal types."
290 "Front-ends/assistants for, or emulators of, UNIX features."
294 "Support code for vms."
298 "Internationalization and alternate character-set support."
299 :link
'(custom-manual "(emacs)International")
304 "The X Window system."
308 "Support for Emacs frames and window systems."
312 "Support editing files of data."
316 "Support editing files."
324 "Code related to the TeX formatter."
328 "Support for multiple fonts."
331 (defgroup hypermedia nil
332 "Support for links between text or other media types."
336 "Support for on-line help systems."
339 (defgroup multimedia nil
340 "Non-textual support, specifically images and sound."
344 "Code local to your site."
347 (defgroup customize
'((widgets custom-group
))
348 "Customization of the Customization support."
352 (defgroup custom-faces nil
353 "Faces used by customize."
357 (defgroup custom-browse nil
358 "Control customize browser."
362 (defgroup custom-buffer nil
363 "Control customize buffers."
367 (defgroup custom-menu nil
368 "Control customize menus."
372 (defgroup abbrev-mode nil
373 "Word abbreviations mode."
374 :link
'(custom-manual "(emacs)Abbrevs")
378 "Storage allocation and gc for GNU Emacs Lisp interpreter."
379 :tag
"Storage Allocation"
383 "Undoing changes in buffers."
384 :link
'(custom-manual "(emacs)Undo")
387 (defgroup modeline nil
388 "Content of the modeline."
391 (defgroup editing-basics nil
392 "Most basic editing facilities."
395 (defgroup display nil
396 "How characters are displayed in buffers."
399 (defgroup execute nil
400 "Executing external commands."
403 (defgroup installation nil
404 "The Emacs installation."
412 "Internal Emacs limits."
416 "Debugging Emacs itself."
419 (defgroup minibuffer nil
420 "Controling the behaviour of the minibuffer."
421 :link
'(custom-manual "(emacs)Minibuffer")
424 (defgroup keyboard nil
425 "Input from the keyboard."
429 "Input from the mouse."
433 "Input from the menus."
437 "Handling data from drag and drop."
440 (defgroup auto-save nil
441 "Preventing accidential loss of data."
444 (defgroup processes-basics nil
445 "Basic stuff dealing with processes."
449 "MULE Emacs internationalization."
452 (defgroup windows nil
453 "Windows within a frame."
454 :link
'(custom-manual "(emacs)Windows")
459 (defun custom-quote (sexp)
460 "Quote SEXP iff it is not self quoting."
461 (if (or (memq sexp
'(t nil
))
464 (memq (car sexp
) '(lambda)))
468 ;;; (and (fboundp 'characterp)
469 ;;; (characterp sexp))
474 (defun custom-split-regexp-maybe (regexp)
475 "If REGEXP is a string, split it to a list at `\\|'.
476 You can get the original back with from the result with:
477 (mapconcat 'identity result \"\\|\")
479 IF REGEXP is not a string, return it unchanged."
483 (while (string-match "\\\\|" regexp start
)
484 (setq all
(cons (substring regexp start
(match-beginning 0)) all
)
485 start
(match-end 0)))
486 (nreverse (cons (substring regexp start
) all
)))
489 (defun custom-variable-prompt ()
490 "Prompt for a custom variable, defaulting to the variable at point.
491 Return a list suitable for use in `interactive'."
492 (let ((v (variable-at-point))
493 (enable-recursive-minibuffers t
)
495 (setq val
(completing-read
496 (if (and (symbolp v
) (custom-variable-p v
))
497 (format "Customize option: (default %s) " v
)
498 "Customize option: ")
499 obarray
'custom-variable-p t
))
500 (list (if (equal val
"")
501 (if (symbolp v
) v nil
)
504 (defun custom-menu-filter (menu widget
)
505 "Convert MENU to the form used by `widget-choose'.
506 MENU should be in the same format as `custom-variable-menu'.
507 WIDGET is the widget to apply the filter entries of MENU on."
509 current name action filter
)
511 (setq current
(car menu
)
513 action
(nth 1 current
)
514 filter
(nth 2 current
)
516 (if (or (null filter
) (funcall filter widget
))
517 (push (cons name action
) result
)
523 (defvar custom-prefix-list nil
524 "List of prefixes that should be ignored by `custom-unlispify'.")
526 (defcustom custom-unlispify-menu-entries t
527 "Display menu entries as words instead of symbols if non nil."
531 (defcustom custom-unlispify-remove-prefixes nil
532 "Non-nil means remove group prefixes from option names in buffer."
534 :group
'custom-buffer
537 (defun custom-unlispify-menu-entry (symbol &optional no-suffix
)
538 "Convert SYMBOL into a menu entry."
539 (cond ((not custom-unlispify-menu-entries
)
540 (symbol-name symbol
))
541 ((get symbol
'custom-tag
)
543 (get symbol
'custom-tag
)
544 (concat (get symbol
'custom-tag
) "...")))
546 (with-current-buffer (get-buffer-create " *Custom-Work*")
548 (princ symbol
(current-buffer))
549 (goto-char (point-min))
550 ;; FIXME: Boolean variables are not predicates, so they shouldn't
551 ;; end with `-p'. -stef
552 ;; (when (and (eq (get symbol 'custom-type) 'boolean)
553 ;; (re-search-forward "-p\\'" nil t))
554 ;; (replace-match "" t t)
555 ;; (goto-char (point-min)))
556 (if custom-unlispify-remove-prefixes
557 (let ((prefixes custom-prefix-list
)
560 (setq prefix
(car prefixes
))
561 (if (search-forward prefix
(+ (point) (length prefix
)) t
)
564 (delete-region (point-min) (point)))
565 (setq prefixes
(cdr prefixes
))))))
566 (subst-char-in-region (point-min) (point-max) ?- ?\ t
)
567 (capitalize-region (point-min) (point-max))
569 (goto-char (point-max))
573 (defcustom custom-unlispify-tag-names t
574 "Display tag names as words instead of symbols if non nil."
575 :group
'custom-buffer
578 (defun custom-unlispify-tag-name (symbol)
579 "Convert SYMBOL into a menu entry."
580 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names
))
581 (custom-unlispify-menu-entry symbol t
)))
583 (defun custom-prefix-add (symbol prefixes
)
584 "Add SYMBOL to list of ignored PREFIXES."
585 (cons (or (get symbol
'custom-prefix
)
586 (concat (symbol-name symbol
) "-"))
591 (defcustom custom-guess-name-alist
596 ("-function\\'" function
)
597 ("-functions\\'" (repeat function
))
598 ("-list\\'" (repeat sexp
))
599 ("-alist\\'" (repeat (cons sexp sexp
))))
600 "Alist of (MATCH TYPE).
602 MATCH should be a regexp matching the name of a symbol, and TYPE should
603 be a widget suitable for editing the value of that symbol. The TYPE
604 of the first entry where MATCH matches the name of the symbol will be
607 This is used for guessing the type of variables not declared with
609 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
612 (defcustom custom-guess-doc-alist
613 '(("\\`\\*?Non-nil " boolean
))
614 "Alist of (MATCH TYPE).
616 MATCH should be a regexp matching a documentation string, and TYPE
617 should be a widget suitable for editing the value of a variable with
618 that documentation string. The TYPE of the first entry where MATCH
619 matches the name of the symbol will be used.
621 This is used for guessing the type of variables not declared with
623 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
626 (defun custom-guess-type (symbol)
627 "Guess a widget suitable for editing the value of SYMBOL.
628 This is done by matching SYMBOL with `custom-guess-name-alist' and
629 if that fails, the doc string with `custom-guess-doc-alist'."
630 (let ((name (symbol-name symbol
))
631 (names custom-guess-name-alist
)
634 (setq current
(car names
)
636 (when (string-match (nth 0 current
) name
)
637 (setq found
(nth 1 current
)
640 (let ((doc (documentation-property symbol
'variable-documentation
))
641 (docs custom-guess-doc-alist
))
644 (setq current
(car docs
)
646 (when (string-match (nth 0 current
) doc
)
647 (setq found
(nth 1 current
)
653 (defcustom custom-browse-sort-alphabetically nil
654 "If non-nil, sort members of each customization group alphabetically."
656 :group
'custom-browse
)
658 (defcustom custom-browse-order-groups nil
659 "If non-nil, order group members within each customization group.
660 If `first', order groups before non-groups.
661 If `last', order groups after non-groups."
662 :type
'(choice (const first
)
664 (const :tag
"none" nil
))
665 :group
'custom-browse
)
667 (defcustom custom-browse-only-groups nil
668 "If non-nil, show group members only within each customization group."
670 :group
'custom-browse
)
672 (defcustom custom-buffer-sort-alphabetically nil
673 "If non-nil, sort members of each customization group alphabetically."
675 :group
'custom-buffer
)
677 (defcustom custom-buffer-order-groups
'last
678 "If non-nil, order group members within each customization group.
679 If `first', order groups before non-groups.
680 If `last', order groups after non-groups."
681 :type
'(choice (const first
)
683 (const :tag
"none" nil
))
684 :group
'custom-buffer
)
686 (defcustom custom-menu-sort-alphabetically nil
687 "If non-nil, sort members of each customization group alphabetically."
691 (defcustom custom-menu-order-groups
'first
692 "If non-nil, order group members within each customization group.
693 If `first', order groups before non-groups.
694 If `last', order groups after non-groups."
695 :type
'(choice (const first
)
697 (const :tag
"none" nil
))
700 ;;;###autoload (add-hook 'same-window-regexps "\\`\\*Customiz.*\\*\\'")
702 (defun custom-sort-items (items sort-alphabetically order-groups
)
703 "Return a sorted copy of ITEMS.
704 ITEMS should be a `custom-group' property.
705 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
706 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
707 groups after non-groups, if nil do not order groups at all."
708 (sort (copy-sequence items
)
710 (let ((typea (nth 1 a
)) (typeb (nth 1 b
))
711 (namea (nth 0 a
)) (nameb (nth 0 b
)))
712 (cond ((not order-groups
)
713 ;; Since we don't care about A and B order, maybe sort.
714 (when sort-alphabetically
715 (string-lessp namea nameb
)))
716 ((eq typea
'custom-group
)
717 ;; If B is also a group, maybe sort. Otherwise, order A and B.
718 (if (eq typeb
'custom-group
)
719 (when sort-alphabetically
720 (string-lessp namea nameb
))
721 (eq order-groups
'first
)))
722 ((eq typeb
'custom-group
)
723 ;; Since A cannot be a group, order A and B.
724 (eq order-groups
'last
))
726 ;; Since A and B cannot be groups, sort.
727 (string-lessp namea nameb
)))))))
729 ;;; Custom Mode Commands.
731 (defvar custom-options nil
732 "Customization widgets in the current buffer.")
735 "Set changes in all modified options."
737 (let ((children custom-options
))
738 (mapc (lambda (child)
739 (when (eq (widget-get child
:custom-state
) 'modified
)
740 (widget-apply child
:custom-set
)))
743 (defun Custom-save ()
744 "Set all modified group members and save them."
746 (let ((children custom-options
))
747 (mapc (lambda (child)
748 (when (memq (widget-get child
:custom-state
)
749 '(modified set changed rogue
))
750 (widget-apply child
:custom-save
)))
754 (defvar custom-reset-menu
755 '(("Current" . Custom-reset-current
)
756 ("Saved" . Custom-reset-saved
)
757 ("Erase Customization (use standard settings)" . Custom-reset-standard
))
758 "Alist of actions for the `Reset' button.
759 The key is a string containing the name of the action, the value is a
760 Lisp function taking the widget as an element which will be called
761 when the action is chosen.")
763 (defun custom-reset (event)
764 "Select item from reset menu."
765 (let* ((completion-ignore-case t
)
766 (answer (widget-choose "Reset to"
772 (defun Custom-reset-current (&rest ignore
)
773 "Reset all modified group members to their current value."
775 (let ((children custom-options
))
776 (mapc (lambda (widget)
777 (if (memq (widget-get widget
:custom-state
)
779 (widget-apply widget
:custom-reset-current
)))
782 (defun Custom-reset-saved (&rest ignore
)
783 "Reset all modified or set group members to their saved value."
785 (let ((children custom-options
))
786 (mapc (lambda (widget)
787 (if (memq (widget-get widget
:custom-state
)
788 '(modified set changed rogue
))
789 (widget-apply widget
:custom-reset-saved
)))
792 (defun Custom-reset-standard (&rest ignore
)
793 "Erase all customization (either current or saved) for the group members.
794 The immediate result is to restore them to their standard settings.
795 This operation eliminates any saved settings for the group members,
796 making them as if they had never been customized at all."
798 (let ((children custom-options
))
799 (mapc (lambda (widget)
800 (and (widget-apply widget
:custom-standard-value
)
801 (if (memq (widget-get widget
:custom-state
)
802 '(modified set changed saved rogue
))
803 (widget-apply widget
:custom-reset-standard
))))
806 ;;; The Customize Commands
808 (defun custom-prompt-variable (prompt-var prompt-val
&optional comment
)
809 "Prompt for a variable and a value and return them as a list.
810 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
811 prompt for the value. The %s escape in PROMPT-VAL is replaced with
812 the name of the variable.
814 If the variable has a `variable-interactive' property, that is used as if
815 it were the arg to `interactive' (which see) to interactively read the value.
817 If the variable has a `custom-type' property, it must be a widget and the
818 `:prompt-value' property of that widget will be used for reading the value.
820 If optional COMMENT argument is non nil, also prompt for a comment and return
821 it as the third element in the list."
822 (let* ((var (read-variable prompt-var
))
823 (minibuffer-help-form '(describe-variable var
))
825 (let ((prop (get var
'variable-interactive
))
826 (type (get var
'custom-type
))
827 (prompt (format prompt-val var
)))
829 (setq type
(list type
)))
831 ;; Use VAR's `variable-interactive' property
832 ;; as an interactive spec for prompting.
833 (call-interactively (list 'lambda
'(arg)
834 (list 'interactive prop
)
837 (widget-prompt-value type
843 (eval-minibuffer prompt
))))))
846 (read-string "Comment: " (get var
'variable-comment
)))
850 (defun customize-set-value (variable value
&optional comment
)
851 "Set VARIABLE to VALUE, and return VALUE. VALUE is a Lisp object.
853 If VARIABLE has a `variable-interactive' property, that is used as if
854 it were the arg to `interactive' (which see) to interactively read the value.
856 If VARIABLE has a `custom-type' property, it must be a widget and the
857 `:prompt-value' property of that widget will be used for reading the value.
859 If given a prefix (or a COMMENT argument), also prompt for a comment."
860 (interactive (custom-prompt-variable "Set variable: "
864 (cond ((string= comment
"")
865 (put variable
'variable-comment nil
))
867 (put variable
'variable-comment comment
)))
868 (set variable value
))
871 (defun customize-set-variable (variable value
&optional comment
)
872 "Set the default for VARIABLE to VALUE, and return VALUE.
873 VALUE is a Lisp object.
875 If VARIABLE has a `custom-set' property, that is used for setting
876 VARIABLE, otherwise `set-default' is used.
878 The `customized-value' property of the VARIABLE will be set to a list
879 with a quoted VALUE as its sole list member.
881 If VARIABLE has a `variable-interactive' property, that is used as if
882 it were the arg to `interactive' (which see) to interactively read the value.
884 If VARIABLE has a `custom-type' property, it must be a widget and the
885 `:prompt-value' property of that widget will be used for reading the value.
887 If given a prefix (or a COMMENT argument), also prompt for a comment."
888 (interactive (custom-prompt-variable "Set variable: "
889 "Set customized value for %s to: "
891 (custom-load-symbol variable
)
892 (funcall (or (get variable
'custom-set
) 'set-default
) variable value
)
893 (put variable
'customized-value
(list (custom-quote value
)))
894 (cond ((string= comment
"")
895 (put variable
'variable-comment nil
)
896 (put variable
'customized-variable-comment nil
))
898 (put variable
'variable-comment comment
)
899 (put variable
'customized-variable-comment comment
)))
903 (defun customize-save-variable (variable value
&optional comment
)
904 "Set the default for VARIABLE to VALUE, and save it for future sessions.
907 If VARIABLE has a `custom-set' property, that is used for setting
908 VARIABLE, otherwise `set-default' is used.
910 The `customized-value' property of the VARIABLE will be set to a list
911 with a quoted VALUE as its sole list member.
913 If VARIABLE has a `variable-interactive' property, that is used as if
914 it were the arg to `interactive' (which see) to interactively read the value.
916 If VARIABLE has a `custom-type' property, it must be a widget and the
917 `:prompt-value' property of that widget will be used for reading the value.
919 If given a prefix (or a COMMENT argument), also prompt for a comment."
920 (interactive (custom-prompt-variable "Set and save variable: "
921 "Set and save value for %s as: "
923 (funcall (or (get variable
'custom-set
) 'set-default
) variable value
)
924 (put variable
'saved-value
(list (custom-quote value
)))
925 (custom-push-theme 'theme-value variable
'user
'set
(list (custom-quote value
)))
926 (cond ((string= comment
"")
927 (put variable
'variable-comment nil
)
928 (put variable
'saved-variable-comment nil
))
930 (put variable
'variable-comment comment
)
931 (put variable
'saved-variable-comment comment
)))
937 "Select a customization buffer which you can use to set user options.
938 User options are structured into \"groups\".
939 Initially the top-level group `Emacs' and its immediate subgroups
940 are shown; the contents of those subgroups are initially hidden."
942 (customize-group 'emacs
))
945 (defun customize-mode (mode)
946 "Customize options related to the current major mode.
947 If a prefix \\[universal-argument] was given (or if the current major mode has no known group),
948 then prompt for the MODE to customize."
951 (let ((completion-regexp-list '("-mode\\'"))
952 (group (custom-group-of-mode major-mode
)))
953 (if (and group
(not current-prefix-arg
))
956 (completing-read (if group
957 (format "Major mode (default %s): " major-mode
)
960 'custom-group-of-mode
961 t nil nil
(if group
(symbol-name major-mode
))))))))
962 (customize-group (custom-group-of-mode mode
)))
966 (defun customize-group (group)
967 "Customize GROUP, which must be a customization group."
968 (interactive (list (let ((completion-ignore-case t
))
969 (completing-read "Customize group: (default emacs) "
972 (or (get symbol
'custom-loads
)
973 (get symbol
'custom-group
)))
975 (when (stringp group
)
976 (if (string-equal "" group
)
978 (setq group
(intern group
))))
979 (let ((name (format "*Customize Group: %s*"
980 (custom-unlispify-tag-name group
))))
981 (if (get-buffer name
)
983 (custom-buffer-create (list (list group
'custom-group
))
985 (concat " for group "
986 (custom-unlispify-tag-name group
))))))
989 (defun customize-group-other-window (group)
990 "Customize GROUP, which must be a customization group."
991 (interactive (list (let ((completion-ignore-case t
))
992 (completing-read "Customize group: (default emacs) "
995 (or (get symbol
'custom-loads
)
996 (get symbol
'custom-group
)))
998 (when (stringp group
)
999 (if (string-equal "" group
)
1001 (setq group
(intern group
))))
1002 (let ((name (format "*Customize Group: %s*"
1003 (custom-unlispify-tag-name group
))))
1004 (if (get-buffer name
)
1006 ;; Copied from `custom-buffer-create-other-window'.
1008 (same-window-buffer-names nil
)
1009 (same-window-regexps nil
))
1010 (pop-to-buffer name
))
1011 (custom-buffer-create-other-window
1012 (list (list group
'custom-group
))
1014 (concat " for group "
1015 (custom-unlispify-tag-name group
))))))
1018 (defalias 'customize-variable
'customize-option
)
1021 (defun customize-option (symbol)
1022 "Customize SYMBOL, which must be a user option variable."
1023 (interactive (custom-variable-prompt))
1024 (custom-buffer-create (list (list symbol
'custom-variable
))
1025 (format "*Customize Option: %s*"
1026 (custom-unlispify-tag-name symbol
))))
1029 (defalias 'customize-variable-other-window
'customize-option-other-window
)
1032 (defun customize-option-other-window (symbol)
1033 "Customize SYMBOL, which must be a user option variable.
1034 Show the buffer in another window, but don't select it."
1035 (interactive (custom-variable-prompt))
1036 (custom-buffer-create-other-window
1037 (list (list symbol
'custom-variable
))
1038 (format "*Customize Option: %s*" (custom-unlispify-tag-name symbol
))))
1040 (defvar customize-changed-options-previous-release
"20.2"
1041 "Version for `customize-changed-options' to refer back to by default.")
1044 (defun customize-changed-options (since-version)
1045 "Customize all user option variables changed in Emacs itself.
1046 This includes new user option variables and faces, and new
1047 customization groups, as well as older options and faces whose default
1048 values have changed since the previous major Emacs release.
1050 With argument SINCE-VERSION (a string), customize all user option
1051 variables that were added (or their meanings were changed) since that
1054 (interactive "sCustomize options changed, since version (default all versions): ")
1055 (if (equal since-version
"")
1056 (setq since-version nil
)
1057 (unless (condition-case nil
1058 (numberp (read since-version
))
1060 (signal 'wrong-type-argument
(list 'numberp since-version
))))
1061 (unless since-version
1062 (setq since-version customize-changed-options-previous-release
))
1064 ;; Load the information for versions since since-version. We use
1065 ;; custom-load-symbol for this.
1066 (put 'custom-versions-load-alist
'custom-loads nil
)
1067 (dolist (elt custom-versions-load-alist
)
1068 (if (customize-version-lessp since-version
(car elt
))
1069 (dolist (load (cdr elt
))
1070 (custom-add-load 'custom-versions-load-alist load
))))
1071 (custom-load-symbol 'custom-versions-load-alist
)
1072 (put 'custom-versions-load-alist
'custom-loads nil
)
1077 (let ((version (get symbol
'custom-version
)))
1079 (when (customize-version-lessp since-version version
)
1080 (if (or (get symbol
'custom-group
)
1081 (get symbol
'group-documentation
))
1082 (push (list symbol
'custom-group
) found
))
1083 (if (custom-variable-p symbol
)
1084 (push (list symbol
'custom-variable
) found
))
1085 (if (custom-facep symbol
)
1086 (push (list symbol
'custom-face
) found
)))))))
1088 (custom-buffer-create (custom-sort-items found t
'first
)
1089 "*Customize Changed Options*")
1090 (error "No user option defaults have been changed since Emacs %s"
1093 (defun customize-version-lessp (version1 version2
)
1094 ;; Why are the versions strings, and given that they are, why aren't
1095 ;; they converted to numbers and compared as such here? -- fx
1097 ;; In case someone made a mistake and left out the quotes
1098 ;; in the :version value.
1099 (if (numberp version2
)
1100 (setq version2
(prin1-to-string version2
)))
1101 (let (major1 major2 minor1 minor2
)
1102 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version1
)
1103 (setq major1
(read (or (match-string 1 version1
)
1105 (setq minor1
(read (or (match-string 3 version1
)
1107 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version2
)
1108 (setq major2
(read (or (match-string 1 version2
)
1110 (setq minor2
(read (or (match-string 3 version2
)
1112 (or (< major1 major2
)
1113 (and (= major1 major2
)
1114 (< minor1 minor2
)))))
1117 (defun customize-face (&optional face
)
1118 "Customize FACE, which should be a face name or nil.
1119 If FACE is nil, customize all faces.
1121 Interactively, when point is on text which has a face specified,
1122 suggest to customize that face, if it's customizable."
1124 (list (read-face-name "Customize face" "all faces" t
)))
1125 (if (member face
'(nil ""))
1126 (setq face
(face-list)))
1127 (if (and (listp face
) (null (cdr face
)))
1128 (setq face
(car face
)))
1130 (custom-buffer-create (custom-sort-items
1132 (list s
'custom-face
))
1135 "*Customize Faces*")
1136 (unless (facep face
)
1137 (error "Invalid face %S" face
))
1138 (custom-buffer-create (list (list face
'custom-face
))
1139 (format "*Customize Face: %s*"
1140 (custom-unlispify-tag-name face
)))))
1143 (defun customize-face-other-window (&optional face
)
1144 "Show customization buffer for face FACE in other window.
1146 Interactively, when point is on text which has a face specified,
1147 suggest to customize that face, if it's customizable."
1149 (list (read-face-name "Customize face" "all faces" t
)))
1150 (if (member face
'(nil ""))
1151 (setq face
(face-list)))
1152 (if (and (listp face
) (null (cdr face
)))
1153 (setq face
(car face
)))
1155 (custom-buffer-create-other-window
1158 (list s
'custom-face
))
1161 "*Customize Faces*")
1162 (unless (facep face
)
1163 (error "Invalid face %S" face
))
1164 (custom-buffer-create-other-window
1165 (list (list face
'custom-face
))
1166 (format "*Customize Face: %s*"
1167 (custom-unlispify-tag-name face
)))))
1170 (defun customize-customized ()
1171 "Customize all user options set since the last save in this session."
1174 (mapatoms (lambda (symbol)
1175 (and (or (get symbol
'customized-face
)
1176 (get symbol
'customized-face-comment
))
1177 (custom-facep symbol
)
1178 (push (list symbol
'custom-face
) found
))
1179 (and (or (get symbol
'customized-value
)
1180 (get symbol
'customized-variable-comment
))
1182 (push (list symbol
'custom-variable
) found
))))
1184 (error "No customized user options")
1185 (custom-buffer-create (custom-sort-items found t nil
)
1186 "*Customize Customized*"))))
1189 (defun customize-rogue ()
1190 "Customize all user variable modified outside customize."
1193 (mapatoms (lambda (symbol)
1194 (let ((cval (or (get symbol
'customized-value
)
1195 (get symbol
'saved-value
)
1196 (get symbol
'standard-value
))))
1197 (when (and cval
;Declared with defcustom.
1198 (default-boundp symbol
) ;Has a value.
1199 (not (equal (eval (car cval
))
1200 ;; Which does not match customize.
1201 (default-value symbol
))))
1202 (push (list symbol
'custom-variable
) found
)))))
1204 (error "No rogue user options")
1205 (custom-buffer-create (custom-sort-items found t nil
)
1206 "*Customize Rogue*"))))
1208 (defun customize-saved ()
1209 "Customize all already saved user options."
1212 (mapatoms (lambda (symbol)
1213 (and (or (get symbol
'saved-face
)
1214 (get symbol
'saved-face-comment
))
1215 (custom-facep symbol
)
1216 (push (list symbol
'custom-face
) found
))
1217 (and (or (get symbol
'saved-value
)
1218 (get symbol
'saved-variable-comment
))
1220 (push (list symbol
'custom-variable
) found
))))
1222 (error "No saved user options")
1223 (custom-buffer-create (custom-sort-items found t nil
)
1224 "*Customize Saved*"))))
1227 (defun customize-apropos (regexp &optional all
)
1228 "Customize all user options matching REGEXP.
1229 If ALL is `options', include only options.
1230 If ALL is `faces', include only faces.
1231 If ALL is `groups', include only groups.
1232 If ALL is t (interactively, with prefix arg), include options which are not
1233 user-settable, as well as faces and groups."
1234 (interactive "sCustomize regexp: \nP")
1236 (mapatoms (lambda (symbol)
1237 (when (string-match regexp
(symbol-name symbol
))
1238 (when (and (not (memq all
'(faces options
)))
1239 (get symbol
'custom-group
))
1240 (push (list symbol
'custom-group
) found
))
1241 (when (and (not (memq all
'(options groups
)))
1242 (custom-facep symbol
))
1243 (push (list symbol
'custom-face
) found
))
1244 (when (and (not (memq all
'(groups faces
)))
1246 (or (get symbol
'saved-value
)
1247 (custom-variable-p symbol
)
1248 (if (memq all
'(nil options
))
1249 (user-variable-p symbol
)
1250 (get symbol
'variable-documentation
))))
1251 (push (list symbol
'custom-variable
) found
)))))
1253 (error "No matches")
1254 (custom-buffer-create (custom-sort-items found t
1255 custom-buffer-order-groups
)
1256 "*Customize Apropos*"))))
1259 (defun customize-apropos-options (regexp &optional arg
)
1260 "Customize all user options matching REGEXP.
1261 With prefix arg, include options which are not user-settable."
1262 (interactive "sCustomize regexp: \nP")
1263 (customize-apropos regexp
(or arg
'options
)))
1266 (defun customize-apropos-faces (regexp)
1267 "Customize all user faces matching REGEXP."
1268 (interactive "sCustomize regexp: \n")
1269 (customize-apropos regexp
'faces
))
1272 (defun customize-apropos-groups (regexp)
1273 "Customize all user groups matching REGEXP."
1274 (interactive "sCustomize regexp: \n")
1275 (customize-apropos regexp
'groups
))
1279 (defcustom custom-buffer-style
'links
1280 "Control the presentation style for customization buffers.
1281 The value should be a symbol, one of:
1283 brackets: groups nest within each other with big horizontal brackets.
1284 links: groups have links to subgroups."
1285 :type
'(radio (const brackets
)
1287 :group
'custom-buffer
)
1289 (defcustom custom-buffer-done-kill nil
1290 "*Non-nil means exiting a Custom buffer should kill it."
1293 :group
'custom-buffer
)
1295 (defcustom custom-buffer-indent
3
1296 "Number of spaces to indent nested groups."
1298 :group
'custom-buffer
)
1300 (defun custom-get-fresh-buffer (name)
1301 "Get a fresh new buffer with name NAME.
1302 If the buffer already exist, clean it up to be like new.
1303 Beware: it's not quite like new. Good enough for custom, but maybe
1305 ;; To be more complete, we should also kill all permanent-local variables,
1306 ;; but it's not needed for custom.
1307 (let ((buf (get-buffer name
)))
1308 (when (and buf
(buffer-local-value 'buffer-file-name buf
))
1309 ;; This will check if the file is not saved.
1313 (get-buffer-create name
)
1314 (with-current-buffer buf
1315 (kill-all-local-variables)
1316 (run-hooks 'kill-buffer-hook
)
1317 ;; Delete overlays before erasing the buffer so the overlay hooks
1318 ;; don't get run spuriously when we erase the buffer.
1319 (let ((ols (overlay-lists)))
1320 (dolist (ol (nconc (car ols
) (cdr ols
)))
1321 (delete-overlay ol
)))
1326 (defun custom-buffer-create (options &optional name description
)
1327 "Create a buffer containing OPTIONS.
1328 Optional NAME is the name of the buffer.
1329 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1330 SYMBOL is a customization option, and WIDGET is a widget for editing
1332 (pop-to-buffer (custom-get-fresh-buffer (or name
"*Customization*")))
1333 (custom-buffer-create-internal options description
))
1336 (defun custom-buffer-create-other-window (options &optional name description
)
1337 "Create a buffer containing OPTIONS, and display it in another window.
1338 The result includes selecting that window.
1339 Optional NAME is the name of the buffer.
1340 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1341 SYMBOL is a customization option, and WIDGET is a widget for editing
1343 (unless name
(setq name
"*Customization*"))
1344 (let ((pop-up-windows t
)
1345 (same-window-buffer-names nil
)
1346 (same-window-regexps nil
))
1347 (pop-to-buffer (custom-get-fresh-buffer name
))
1348 (custom-buffer-create-internal options description
)))
1350 (defcustom custom-reset-button-menu nil
1351 "If non-nil, only show a single reset button in customize buffers.
1352 This button will have a menu with all three reset operations."
1354 :group
'custom-buffer
)
1356 (defcustom custom-buffer-verbose-help t
1357 "If non-nil, include explanatory text in the customization buffer."
1359 :group
'custom-buffer
)
1361 (defun Custom-buffer-done (&rest ignore
)
1362 "Exit current Custom buffer according to `custom-buffer-done-kill'."
1364 (quit-window custom-buffer-done-kill
))
1366 (defcustom custom-raised-buttons
(not (equal (face-valid-attribute-values :box
)
1367 '(("unspecified" . unspecified
))))
1368 "If non-nil, indicate active buttons in a `raised-button' style.
1369 Otherwise use brackets."
1372 :group
'custom-buffer
)
1374 (defun custom-buffer-create-internal (options &optional description
)
1376 (if custom-buffer-verbose-help
1378 (widget-insert "This is a customization buffer")
1380 (widget-insert description
))
1381 (widget-insert (format ".
1382 %s show active fields; type RET or click mouse-1
1383 on an active field to invoke its action. Editing an option value
1384 changes only the text in the buffer. Invoke the State button to set or
1385 save the option value. Saving an option normally edits your init file.
1387 (if custom-raised-buttons
1389 "Square brackets")))
1390 (widget-create 'info-link
1392 "(emacs)Saving Customizations")
1394 " for information on how to save in a different file.
1396 (widget-create 'info-link
1398 :help-echo
"Read the online help."
1399 "(emacs)Easy Customization")
1400 (widget-insert " for general information.\n\n")
1401 (widget-insert "Operate on everything in this buffer:\n "))
1402 (widget-insert " "))
1403 (widget-create 'push-button
1404 :tag
"Set for Current Session"
1406 Make your editing in this buffer take effect for this session."
1407 :action
(lambda (widget &optional event
)
1410 (widget-create 'push-button
1411 :tag
"Save for Future Sessions"
1413 Make your editing in this buffer take effect for future Emacs sessions.
1414 This updates your Emacs initialization file or creates a new one."
1415 :action
(lambda (widget &optional event
)
1417 (if custom-reset-button-menu
1420 (widget-create 'push-button
1422 :help-echo
"Show a menu with reset operations."
1423 :mouse-down-action
(lambda (&rest junk
) t
)
1424 :action
(lambda (widget &optional event
)
1425 (custom-reset event
))))
1426 (widget-insert "\n ")
1427 (widget-create 'push-button
1430 Reset all edited text in this buffer to reflect current values."
1431 :action
'Custom-reset-current
)
1433 (widget-create 'push-button
1434 :tag
"Reset to Saved"
1436 Reset all values in this buffer to their saved settings."
1437 :action
'Custom-reset-saved
)
1439 (widget-create 'push-button
1440 :tag
"Erase Customization"
1442 Un-customize all values in this buffer. They get their standard settings."
1443 :action
'Custom-reset-standard
))
1444 (if (not custom-buffer-verbose-help
)
1447 (widget-create 'info-link
1449 :help-echo
"Read the online help."
1450 "(emacs)Easy Customization")))
1452 (widget-create 'push-button
1455 (lambda (&rest ignore
)
1456 (if custom-buffer-done-kill
1458 "Bury this buffer"))
1459 :action
#'Custom-buffer-done
)
1460 (widget-insert "\n\n")
1461 (message "Creating customization items...")
1462 (buffer-disable-undo)
1463 (setq custom-options
1464 (if (= (length options
) 1)
1465 (mapcar (lambda (entry)
1466 (widget-create (nth 1 entry
)
1467 :documentation-shown t
1468 :custom-state
'unknown
1469 :tag
(custom-unlispify-tag-name
1471 :value
(nth 0 entry
)))
1474 (length (length options
)))
1475 (mapcar (lambda (entry)
1477 (message "Creating customization items ...%2d%%"
1478 (/ (* 100.0 count
) length
))
1479 (widget-create (nth 1 entry
)
1480 :tag
(custom-unlispify-tag-name
1482 :value
(nth 0 entry
))
1483 (setq count
(1+ count
))
1484 (unless (eq (preceding-char) ?
\n)
1485 (widget-insert "\n"))
1486 (widget-insert "\n")))
1488 (unless (eq (preceding-char) ?
\n)
1489 (widget-insert "\n"))
1490 (message "Creating customization items ...done")
1491 (message "Resetting customization items...")
1492 (unless (eq custom-buffer-style
'tree
)
1493 (mapc 'custom-magic-reset custom-options
))
1494 (message "Resetting customization items...done")
1495 (message "Creating customization setup...")
1497 (buffer-enable-undo)
1498 (goto-char (point-min))
1499 (message "Creating customization setup...done"))
1501 ;;; The Tree Browser.
1504 (defun customize-browse (&optional group
)
1505 "Create a tree browser for the customize hierarchy."
1508 (setq group
'emacs
))
1509 (let ((name "*Customize Browser*"))
1510 (pop-to-buffer (custom-get-fresh-buffer name
)))
1513 Square brackets show active fields; type RET or click mouse-1
1514 on an active field to invoke its action.
1515 Invoke [+] below to expand a group, and [-] to collapse an expanded group.\n")
1516 (if custom-browse-only-groups
1518 Invoke the [Group] button below to edit that item in another window.\n\n")
1519 (widget-insert "Invoke the ")
1520 (widget-create 'item
1523 :tag-glyph
"folder")
1524 (widget-insert ", ")
1525 (widget-create 'item
1529 (widget-insert ", and ")
1530 (widget-create 'item
1533 :tag-glyph
"option")
1534 (widget-insert " buttons below to edit that
1535 item in another window.\n\n"))
1536 (let ((custom-buffer-style 'tree
))
1537 (widget-create 'custom-group
1539 :custom-state
'unknown
1540 :tag
(custom-unlispify-tag-name group
)
1543 (goto-char (point-min)))
1545 (define-widget 'custom-browse-visibility
'item
1546 "Control visibility of items in the customize tree browser."
1548 :action
'custom-browse-visibility-action
)
1550 (defun custom-browse-visibility-action (widget &rest ignore
)
1551 (let ((custom-buffer-style 'tree
))
1552 (custom-toggle-parent widget
)))
1554 (define-widget 'custom-browse-group-tag
'push-button
1555 "Show parent in other window when activated."
1558 :action
'custom-browse-group-tag-action
)
1560 (defun custom-browse-group-tag-action (widget &rest ignore
)
1561 (let ((parent (widget-get widget
:parent
)))
1562 (customize-group-other-window (widget-value parent
))))
1564 (define-widget 'custom-browse-variable-tag
'push-button
1565 "Show parent in other window when activated."
1568 :action
'custom-browse-variable-tag-action
)
1570 (defun custom-browse-variable-tag-action (widget &rest ignore
)
1571 (let ((parent (widget-get widget
:parent
)))
1572 (customize-variable-other-window (widget-value parent
))))
1574 (define-widget 'custom-browse-face-tag
'push-button
1575 "Show parent in other window when activated."
1578 :action
'custom-browse-face-tag-action
)
1580 (defun custom-browse-face-tag-action (widget &rest ignore
)
1581 (let ((parent (widget-get widget
:parent
)))
1582 (customize-face-other-window (widget-value parent
))))
1584 (defconst custom-browse-alist
'((" " "space")
1590 (defun custom-browse-insert-prefix (prefix)
1591 "Insert PREFIX. On XEmacs convert it to line graphics."
1592 ;; Fixme: do graphics.
1593 (if nil
; (string-match "XEmacs" emacs-version)
1596 (while (not (string-equal prefix
""))
1597 (let ((entry (substring prefix
0 3)))
1598 (setq prefix
(substring prefix
3))
1599 (let ((overlay (make-overlay (1- (point)) (point) nil t nil
))
1600 (name (nth 1 (assoc entry custom-browse-alist
))))
1601 (overlay-put overlay
'end-glyph
(widget-glyph-find name entry
))
1602 (overlay-put overlay
'start-open t
)
1603 (overlay-put overlay
'end-open t
)))))
1606 ;;; Modification of Basic Widgets.
1608 ;; We add extra properties to the basic widgets needed here. This is
1609 ;; fine, as long as we are careful to stay within out own namespace.
1611 ;; We want simple widgets to be displayed by default, but complex
1612 ;; widgets to be hidden.
1614 (widget-put (get 'item
'widget-type
) :custom-show t
)
1615 (widget-put (get 'editable-field
'widget-type
)
1616 :custom-show
(lambda (widget value
)
1617 (let ((pp (pp-to-string value
)))
1618 (cond ((string-match "\n" pp
)
1623 (widget-put (get 'menu-choice
'widget-type
) :custom-show t
)
1625 ;;; The `custom-manual' Widget.
1627 (define-widget 'custom-manual
'info-link
1628 "Link to the manual entry for this customization option."
1629 :help-echo
"Read the manual entry for this option."
1632 ;;; The `custom-magic' Widget.
1634 (defgroup custom-magic-faces nil
1635 "Faces used by the magic button."
1636 :group
'custom-faces
1637 :group
'custom-buffer
)
1639 (defface custom-invalid-face
'((((class color
))
1640 (:foreground
"yellow1" :background
"red1"))
1642 (:weight bold
:slant italic
:underline t
)))
1643 "Face used when the customize item is invalid."
1644 :group
'custom-magic-faces
)
1646 (defface custom-rogue-face
'((((class color
))
1647 (:foreground
"pink" :background
"black"))
1650 "Face used when the customize item is not defined for customization."
1651 :group
'custom-magic-faces
)
1653 (defface custom-modified-face
'((((min-colors 88) (class color
))
1654 (:foreground
"white" :background
"blue1"))
1656 (:foreground
"white" :background
"blue"))
1658 (:slant italic
:bold
)))
1659 "Face used when the customize item has been modified."
1660 :group
'custom-magic-faces
)
1662 (defface custom-set-face
'((((min-colors 88) (class color
))
1663 (:foreground
"blue1" :background
"white"))
1665 (:foreground
"blue" :background
"white"))
1668 "Face used when the customize item has been set."
1669 :group
'custom-magic-faces
)
1671 (defface custom-changed-face
'((((min-colors 88) (class color
))
1672 (:foreground
"white" :background
"blue1"))
1674 (:foreground
"white" :background
"blue"))
1677 "Face used when the customize item has been changed."
1678 :group
'custom-magic-faces
)
1680 (defface custom-saved-face
'((t (:underline t
)))
1681 "Face used when the customize item has been saved."
1682 :group
'custom-magic-faces
)
1684 (defconst custom-magic-alist
1685 '((nil "#" underline
"\
1686 UNINITIALIZED, you should not see this.")
1687 (unknown "?" italic
"\
1688 UNKNOWN, you should not see this.")
1689 (hidden "-" default
"\
1690 HIDDEN, invoke \"Show\" in the previous line to show." "\
1691 group now hidden, invoke \"Show\", above, to show contents.")
1692 (invalid "x" custom-invalid-face
"\
1693 INVALID, the displayed value cannot be set.")
1694 (modified "*" custom-modified-face
"\
1695 EDITED, shown value does not take effect until you set or save it." "\
1696 something in this group has been edited but not set.")
1697 (set "+" custom-set-face
"\
1698 SET for current session only." "\
1699 something in this group has been set but not saved.")
1700 (changed ":" custom-changed-face
"\
1701 CHANGED outside Customize; operating on it here may be unreliable." "\
1702 something in this group has been changed outside customize.")
1703 (saved "!" custom-saved-face
"\
1705 something in this group has been set and saved.")
1706 (rogue "@" custom-rogue-face
"\
1707 NO CUSTOMIZATION DATA; you should not see this." "\
1708 something in this group is not prepared for customization.")
1709 (standard " " nil
"\
1711 visible group members are all at standard settings."))
1712 "Alist of customize option states.
1713 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1715 STATE is one of the following symbols:
1718 For internal use, should never occur.
1720 For internal use, should never occur.
1722 This item is not being displayed.
1724 This item is modified, but has an invalid form.
1726 This item is modified, and has a valid form.
1728 This item has been set but not saved.
1730 The current value of this item has been changed outside Customize.
1732 This item is marked for saving.
1734 This item has no customization information.
1736 This item is unchanged from the standard setting.
1738 MAGIC is a string used to present that state.
1740 FACE is a face used to present the state.
1742 ITEM-DESC is a string describing the state for options.
1744 GROUP-DESC is a string describing the state for groups. If this is
1745 left out, ITEM-DESC will be used.
1747 The string %c in either description will be replaced with the
1748 category of the item. These are `group'. `option', and `face'.
1750 The list should be sorted most significant first.")
1752 (defcustom custom-magic-show
'long
1753 "If non-nil, show textual description of the state.
1754 If `long', show a full-line description, not just one word."
1755 :type
'(choice (const :tag
"no" nil
)
1757 (other :tag
"short" short
))
1758 :group
'custom-buffer
)
1760 (defcustom custom-magic-show-hidden
'(option face
)
1761 "Control whether the State button is shown for hidden items.
1762 The value should be a list with the custom categories where the State
1763 button should be visible. Possible categories are `group', `option',
1765 :type
'(set (const group
) (const option
) (const face
))
1766 :group
'custom-buffer
)
1768 (defcustom custom-magic-show-button nil
1769 "Show a \"magic\" button indicating the state of each customization option."
1771 :group
'custom-buffer
)
1773 (define-widget 'custom-magic
'default
1774 "Show and manipulate state for a customization option."
1776 :action
'widget-parent-action
1779 :value-create
'custom-magic-value-create
1780 :value-delete
'widget-children-value-delete
)
1782 (defun widget-magic-mouse-down-action (widget &optional event
)
1783 ;; Non-nil unless hidden.
1784 (not (eq (widget-get (widget-get (widget-get widget
:parent
) :parent
)
1788 (defun custom-magic-value-create (widget)
1789 "Create compact status report for WIDGET."
1790 (let* ((parent (widget-get widget
:parent
))
1791 (state (widget-get parent
:custom-state
))
1792 (hidden (eq state
'hidden
))
1793 (entry (assq state custom-magic-alist
))
1794 (magic (nth 1 entry
))
1795 (face (nth 2 entry
))
1796 (category (widget-get parent
:custom-category
))
1797 (text (or (and (eq category
'group
)
1800 (form (widget-get parent
:custom-form
))
1802 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text
)
1803 (setq text
(concat (match-string 1 text
)
1804 (symbol-name category
)
1805 (match-string 2 text
))))
1806 (when (and custom-magic-show
1808 (memq category custom-magic-show-hidden
)))
1810 (when (and (eq category
'group
)
1811 (not (and (eq custom-buffer-style
'links
)
1812 (> (widget-get parent
:custom-level
) 1))))
1813 (insert-char ?\
(* custom-buffer-indent
1814 (widget-get parent
:custom-level
))))
1815 (push (widget-create-child-and-convert
1817 :help-echo
"Change the state of this item."
1818 :format
(if hidden
"%t" "%[%t%]")
1819 :button-prefix
'widget-push-button-prefix
1820 :button-suffix
'widget-push-button-suffix
1821 :mouse-down-action
'widget-magic-mouse-down-action
1825 (let ((start (point)))
1826 (if (eq custom-magic-show
'long
)
1828 (insert (symbol-name state
)))
1829 (cond ((eq form
'lisp
)
1831 ((eq form
'mismatch
)
1832 (insert " (mismatch)")))
1833 (put-text-property start
(point) 'face
'custom-state-face
))
1835 (when (and (eq category
'group
)
1836 (not (and (eq custom-buffer-style
'links
)
1837 (> (widget-get parent
:custom-level
) 1))))
1838 (insert-char ?\
(* custom-buffer-indent
1839 (widget-get parent
:custom-level
))))
1840 (when custom-magic-show-button
1841 (when custom-magic-show
1842 (let ((indent (widget-get parent
:indent
)))
1844 (insert-char ? indent
))))
1845 (push (widget-create-child-and-convert
1847 :mouse-down-action
'widget-magic-mouse-down-action
1851 :help-echo
"Change the state."
1852 :format
(if hidden
"%t" "%[%t%]")
1853 :tag
(if (memq form
'(lisp mismatch
))
1854 (concat "(" magic
")")
1855 (concat "[" magic
"]")))
1858 (widget-put widget
:children children
)))
1860 (defun custom-magic-reset (widget)
1861 "Redraw the :custom-magic property of WIDGET."
1862 (let ((magic (widget-get widget
:custom-magic
)))
1863 (widget-value-set magic
(widget-value magic
))))
1865 ;;; The `custom' Widget.
1867 (defface custom-button-face
1868 '((((type x w32 mac
) (class color
)) ; Like default modeline
1869 (:box
(:line-width
2 :style released-button
)
1870 :background
"lightgrey" :foreground
"black"))
1873 "Face used for buttons in customization buffers."
1875 :group
'custom-faces
)
1877 (defface custom-button-pressed-face
1878 '((((type x w32 mac
) (class color
))
1879 (:box
(:line-width
2 :style pressed-button
)
1880 :background
"lightgrey" :foreground
"black"))
1882 (:inverse-video t
)))
1883 "Face used for buttons in customization buffers."
1885 :group
'custom-faces
)
1887 (defface custom-documentation-face nil
1888 "Face used for documentation strings in customization buffers."
1889 :group
'custom-faces
)
1891 (defface custom-state-face
'((((class color
)
1893 (:foreground
"lime green"))
1896 (:foreground
"dark green"))
1898 "Face used for State descriptions in the customize buffer."
1899 :group
'custom-faces
)
1901 (define-widget 'custom
'default
1902 "Customize a user option."
1904 :convert-widget
'custom-convert-widget
1905 :notify
'custom-notify
1908 :custom-state
'hidden
1909 :documentation-property
'widget-subclass-responsibility
1910 :value-create
'widget-subclass-responsibility
1911 :value-delete
'widget-children-value-delete
1912 :value-get
'widget-value-value-get
1913 :validate
'widget-children-validate
1914 :match
(lambda (widget value
) (symbolp value
)))
1916 (defun custom-convert-widget (widget)
1917 "Initialize :value and :tag from :args in WIDGET."
1918 (let ((args (widget-get widget
:args
)))
1920 (widget-put widget
:value
(widget-apply widget
1921 :value-to-internal
(car args
)))
1922 (widget-put widget
:tag
(custom-unlispify-tag-name (car args
)))
1923 (widget-put widget
:args nil
)))
1926 (defun custom-notify (widget &rest args
)
1927 "Keep track of changes."
1928 (let ((state (widget-get widget
:custom-state
)))
1929 (unless (eq state
'modified
)
1930 (unless (memq state
'(nil unknown hidden
))
1931 (widget-put widget
:custom-state
'modified
))
1932 (custom-magic-reset widget
)
1933 (apply 'widget-default-notify widget args
))))
1935 (defun custom-redraw (widget)
1936 "Redraw WIDGET with current settings."
1937 (let ((line (count-lines (point-min) (point)))
1938 (column (current-column))
1940 (from (marker-position (widget-get widget
:from
)))
1941 (to (marker-position (widget-get widget
:to
))))
1943 (widget-value-set widget
(widget-value widget
))
1944 (custom-redraw-magic widget
))
1945 (when (and (>= pos from
) (<= pos to
))
1950 (goto-line (1+ line
)))
1951 (move-to-column column
))
1954 (defun custom-redraw-magic (widget)
1955 "Redraw WIDGET state with current settings."
1957 (let ((magic (widget-get widget
:custom-magic
)))
1959 (widget-value-set magic
(widget-value magic
))
1960 (when (setq widget
(widget-get widget
:group
))
1961 (custom-group-state-update widget
)))
1963 (setq widget nil
)))))
1966 (defun custom-show (widget value
)
1967 "Non-nil if WIDGET should be shown with VALUE by default."
1968 (let ((show (widget-get widget
:custom-show
)))
1974 (funcall show widget value
)))))
1976 (defun custom-load-widget (widget)
1977 "Load all dependencies for WIDGET."
1978 (custom-load-symbol (widget-value widget
)))
1980 (defun custom-unloaded-symbol-p (symbol)
1981 "Return non-nil if the dependencies of SYMBOL have not yet been loaded."
1983 (loads (get symbol
'custom-loads
))
1986 (setq load
(car loads
)
1988 (cond ((symbolp load
)
1989 (unless (featurep load
)
1991 ((assoc load load-history
))
1992 ((assoc (locate-library load
) load-history
)
1998 (defun custom-unloaded-widget-p (widget)
1999 "Return non-nil if the dependencies of WIDGET have not yet been loaded."
2000 (custom-unloaded-symbol-p (widget-value widget
)))
2002 (defun custom-toggle-hide (widget)
2003 "Toggle visibility of WIDGET."
2004 (custom-load-widget widget
)
2005 (let ((state (widget-get widget
:custom-state
)))
2006 (cond ((memq state
'(invalid modified
))
2007 (error "There are unset changes"))
2009 (widget-put widget
:custom-state
'unknown
))
2011 (widget-put widget
:documentation-shown nil
)
2012 (widget-put widget
:custom-state
'hidden
)))
2013 (custom-redraw widget
)
2016 (defun custom-toggle-parent (widget &rest ignore
)
2017 "Toggle visibility of parent of WIDGET."
2018 (custom-toggle-hide (widget-get widget
:parent
)))
2020 (defun custom-add-see-also (widget &optional prefix
)
2021 "Add `See also ...' to WIDGET if there are any links.
2022 Insert PREFIX first if non-nil."
2023 (let* ((symbol (widget-get widget
:value
))
2024 (links (get symbol
'custom-links
))
2025 (many (> (length links
) 2))
2026 (buttons (widget-get widget
:buttons
))
2027 (indent (widget-get widget
:indent
)))
2030 (insert-char ?\ indent
))
2033 (insert "See also ")
2035 (push (widget-create-child-and-convert widget
(car links
))
2037 (setq links
(cdr links
))
2046 (widget-put widget
:buttons buttons
))))
2048 (defun custom-add-parent-links (widget &optional initial-string
)
2049 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
2050 The value if non-nil if any parents were found.
2051 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
2052 (let ((name (widget-value widget
))
2053 (type (widget-type widget
))
2054 (buttons (widget-get widget
:buttons
))
2057 (insert (or initial-string
"Parent groups:"))
2058 (mapatoms (lambda (symbol)
2059 (let ((entry (assq name
(get symbol
'custom-group
))))
2060 (when (eq (nth 1 entry
) type
)
2062 (push (widget-create-child-and-convert
2063 widget
'custom-group-link
2064 :tag
(custom-unlispify-tag-name symbol
)
2067 (setq parents
(cons symbol parents
))))))
2068 (and (null (get name
'custom-links
)) ;No links of its own.
2069 (= (length parents
) 1) ;A single parent.
2070 (let* ((links (get (car parents
) 'custom-links
))
2071 (many (> (length links
) 2)))
2073 (insert "\nParent documentation: ")
2075 (push (widget-create-child-and-convert widget
(car links
))
2077 (setq links
(cdr links
))
2088 (delete-region start
(point)))
2089 (widget-put widget
:buttons buttons
)
2092 ;;; The `custom-comment' Widget.
2094 ;; like the editable field
2095 (defface custom-comment-face
'((((class grayscale color
)
2097 (:background
"gray85"))
2098 (((class grayscale color
)
2100 (:background
"dim gray"))
2103 "Face used for comments on variables or faces"
2105 :group
'custom-faces
)
2107 ;; like font-lock-comment-face
2108 (defface custom-comment-tag-face
2109 '((((class color
) (background dark
)) (:foreground
"gray80"))
2110 (((class color
) (background light
)) (:foreground
"blue4"))
2111 (((class grayscale
) (background light
))
2112 (:foreground
"DimGray" :weight bold
:slant italic
))
2113 (((class grayscale
) (background dark
))
2114 (:foreground
"LightGray" :weight bold
:slant italic
))
2116 "Face used for variables or faces comment tags"
2117 :group
'custom-faces
)
2119 (define-widget 'custom-comment
'string
2122 :help-echo
"Edit a comment here."
2123 :sample-face
'custom-comment-tag-face
2124 :value-face
'custom-comment-face
2126 :create
'custom-comment-create
)
2128 (defun custom-comment-create (widget)
2129 (let* ((null-comment (equal "" (widget-value widget
))))
2130 (if (or (widget-get (widget-get widget
:parent
) :comment-shown
)
2132 (widget-default-create widget
)
2133 ;; `widget-default-delete' expects markers in these slots --
2134 ;; maybe it shouldn't.
2135 (widget-put widget
:from
(point-marker))
2136 (widget-put widget
:to
(point-marker)))))
2138 (defun custom-comment-hide (widget)
2139 (widget-put (widget-get widget
:parent
) :comment-shown nil
))
2141 ;; Those functions are for the menu. WIDGET is NOT the comment widget. It's
2142 ;; the global custom one
2143 (defun custom-comment-show (widget)
2144 (widget-put widget
:comment-shown t
)
2145 (custom-redraw widget
)
2148 (defun custom-comment-invisible-p (widget)
2149 (let ((val (widget-value (widget-get widget
:comment-widget
))))
2151 (not (widget-get widget
:comment-shown
)))))
2153 ;;; The `custom-variable' Widget.
2155 ;; When this was underlined blue, users confused it with a
2156 ;; Mosaic-style hyperlink...
2157 (defface custom-variable-tag-face
2160 (:foreground
"light blue" :weight bold
:height
1.2 :inherit variable-pitch
))
2161 (((min-colors 88) (class color
)
2163 (:foreground
"blue1" :weight bold
:height
1.2 :inherit variable-pitch
))
2166 (:foreground
"blue" :weight bold
:height
1.2 :inherit variable-pitch
))
2168 "Face used for unpushable variable tags."
2169 :group
'custom-faces
)
2171 (defface custom-variable-button-face
'((t (:underline t
:weight bold
)))
2172 "Face used for pushable variable tags."
2173 :group
'custom-faces
)
2175 (defcustom custom-variable-default-form
'edit
2176 "Default form of displaying variable values."
2177 :type
'(choice (const edit
)
2179 :group
'custom-buffer
2182 (defun custom-variable-documentation (variable)
2183 "Return documentation of VARIABLE for use in Custom buffer.
2184 Normally just return the docstring. But if VARIABLE automatically
2185 becomes buffer local when set, append a message to that effect."
2186 (if (and (local-variable-if-set-p variable
)
2187 (or (not (local-variable-p variable
))
2189 (local-variable-if-set-p variable
))))
2190 (concat (documentation-property variable
'variable-documentation
)
2192 This variable automatically becomes buffer-local when set outside Custom.
2193 However, setting it through Custom sets the default value.")
2194 (documentation-property variable
'variable-documentation
)))
2196 (define-widget 'custom-variable
'custom
2197 "Customize variable."
2199 :help-echo
"Set or reset this variable."
2200 :documentation-property
#'custom-variable-documentation
2201 :custom-category
'option
2203 :custom-menu
'custom-variable-menu-create
2204 :custom-form nil
; defaults to value of `custom-variable-default-form'
2205 :value-create
'custom-variable-value-create
2206 :action
'custom-variable-action
2207 :custom-set
'custom-variable-set
2208 :custom-save
'custom-variable-save
2209 :custom-reset-current
'custom-redraw
2210 :custom-reset-saved
'custom-variable-reset-saved
2211 :custom-reset-standard
'custom-variable-reset-standard
2212 :custom-standard-value
'custom-variable-standard-value
)
2214 (defun custom-variable-type (symbol)
2215 "Return a widget suitable for editing the value of SYMBOL.
2216 If SYMBOL has a `custom-type' property, use that.
2217 Otherwise, look up symbol in `custom-guess-type-alist'."
2218 (let* ((type (or (get symbol
'custom-type
)
2219 (and (not (get symbol
'standard-value
))
2220 (custom-guess-type symbol
))
2222 (options (get symbol
'custom-options
))
2223 (tmp (if (listp type
)
2224 (copy-sequence type
)
2227 (widget-put tmp
:options options
))
2230 (defun custom-variable-value-create (widget)
2231 "Here is where you edit the variable's value."
2232 (custom-load-widget widget
)
2233 (unless (widget-get widget
:custom-form
)
2234 (widget-put widget
:custom-form custom-variable-default-form
))
2235 (let* ((buttons (widget-get widget
:buttons
))
2236 (children (widget-get widget
:children
))
2237 (form (widget-get widget
:custom-form
))
2238 (state (widget-get widget
:custom-state
))
2239 (symbol (widget-get widget
:value
))
2240 (tag (widget-get widget
:tag
))
2241 (type (custom-variable-type symbol
))
2242 (conv (widget-convert type
))
2243 (get (or (get symbol
'custom-get
) 'default-value
))
2244 (prefix (widget-get widget
:custom-prefix
))
2245 (last (widget-get widget
:custom-last
))
2246 (value (if (default-boundp symbol
)
2247 (funcall get symbol
)
2248 (widget-get conv
:value
))))
2249 ;; If the widget is new, the child determines whether it is hidden.
2251 ((custom-show type value
)
2252 (setq state
'unknown
))
2254 (setq state
'hidden
)))
2255 ;; If we don't know the state, see if we need to edit it in lisp form.
2256 (when (eq state
'unknown
)
2257 (unless (widget-apply conv
:match value
)
2258 ;; (widget-apply (widget-convert type) :match value)
2259 (setq form
'mismatch
)))
2260 ;; Now we can create the child widget.
2261 (cond ((eq custom-buffer-style
'tree
)
2262 (insert prefix
(if last
" `--- " " |--- "))
2263 (push (widget-create-child-and-convert
2264 widget
'custom-browse-variable-tag
)
2266 (insert " " tag
"\n")
2267 (widget-put widget
:buttons buttons
))
2269 ;; Indicate hidden value.
2270 (push (widget-create-child-and-convert
2273 :sample-face
'custom-variable-tag-face
2277 (push (widget-create-child-and-convert
2279 :help-echo
"Show the value of this option."
2281 :action
'custom-toggle-parent
2284 ((memq form
'(lisp mismatch
))
2285 ;; In lisp mode edit the saved value when possible.
2286 (let* ((value (cond ((get symbol
'saved-value
)
2287 (car (get symbol
'saved-value
)))
2288 ((get symbol
'standard-value
)
2289 (car (get symbol
'standard-value
)))
2290 ((default-boundp symbol
)
2291 (custom-quote (funcall get symbol
)))
2293 (custom-quote (widget-get conv
:value
))))))
2294 (insert (symbol-name symbol
) ": ")
2295 (push (widget-create-child-and-convert
2297 :help-echo
"Hide the value of this option."
2300 :action
'custom-toggle-parent
2304 (push (widget-create-child-and-convert
2306 :button-face
'custom-variable-button-face
2308 :tag
(symbol-name symbol
)
2314 (let* ((format (widget-get type
:format
))
2315 tag-format value-format
)
2316 (unless (string-match ":" format
)
2317 (error "Bad format"))
2318 (setq tag-format
(substring format
0 (match-end 0)))
2319 (setq value-format
(substring format
(match-end 0)))
2320 (push (widget-create-child-and-convert
2323 :action
'custom-tag-action
2324 :help-echo
"Change value of this option."
2325 :mouse-down-action
'custom-tag-mouse-down-action
2326 :button-face
'custom-variable-button-face
2327 :sample-face
'custom-variable-tag-face
2331 (push (widget-create-child-and-convert
2333 :help-echo
"Hide the value of this option."
2336 :action
'custom-toggle-parent
2339 (push (widget-create-child-and-convert
2341 :format value-format
2344 (unless (eq custom-buffer-style
'tree
)
2345 (unless (eq (preceding-char) ?
\n)
2346 (widget-insert "\n"))
2347 ;; Create the magic button.
2348 (let ((magic (widget-create-child-and-convert
2349 widget
'custom-magic nil
)))
2350 (widget-put widget
:custom-magic magic
)
2351 (push magic buttons
))
2352 ;; ### NOTE: this is ugly!!!! I need to update the :buttons property
2353 ;; before the call to `widget-default-format-handler'. Otherwise, I
2354 ;; loose my current `buttons'. This function shouldn't be called like
2355 ;; this anyway. The doc string widget should be added like the others.
2357 (widget-put widget
:buttons buttons
)
2359 ;; Insert documentation.
2360 (widget-default-format-handler widget ?h
)
2362 ;; The comment field
2363 (unless (eq state
'hidden
)
2364 (let* ((comment (get symbol
'variable-comment
))
2366 (widget-create-child-and-convert
2367 widget
'custom-comment
2369 :value
(or comment
""))))
2370 (widget-put widget
:comment-widget comment-widget
)
2371 ;; Don't push it !!! Custom assumes that the first child is the
2373 (setq children
(append children
(list comment-widget
)))))
2374 ;; Update the rest of the properties properties.
2375 (widget-put widget
:custom-form form
)
2376 (widget-put widget
:children children
)
2377 ;; Now update the state.
2378 (if (eq state
'hidden
)
2379 (widget-put widget
:custom-state state
)
2380 (custom-variable-state-set widget
))
2382 (unless (eq state
'hidden
)
2383 (when (eq (widget-get widget
:custom-level
) 1)
2384 (custom-add-parent-links widget
))
2385 (custom-add-see-also widget
)))))
2387 (defun custom-tag-action (widget &rest args
)
2388 "Pass :action to first child of WIDGET's parent."
2389 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2392 (defun custom-tag-mouse-down-action (widget &rest args
)
2393 "Pass :mouse-down-action to first child of WIDGET's parent."
2394 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2395 :mouse-down-action args
))
2397 (defun custom-variable-state-set (widget)
2398 "Set the state of WIDGET."
2399 (let* ((symbol (widget-value widget
))
2400 (get (or (get symbol
'custom-get
) 'default-value
))
2401 (value (if (default-boundp symbol
)
2402 (funcall get symbol
)
2403 (widget-get widget
:value
)))
2404 (comment (get symbol
'variable-comment
))
2407 (state (cond ((progn (setq tmp
(get symbol
'customized-value
))
2409 (get symbol
'customized-variable-comment
))
2411 (if (condition-case nil
2412 (and (equal value
(eval (car tmp
)))
2413 (equal comment temp
))
2417 ((progn (setq tmp
(get symbol
'saved-value
))
2418 (setq temp
(get symbol
'saved-variable-comment
))
2420 (if (condition-case nil
2421 (and (equal value
(eval (car tmp
)))
2422 (equal comment temp
))
2426 ((setq tmp
(get symbol
'standard-value
))
2427 (if (condition-case nil
2428 (and (equal value
(eval (car tmp
)))
2429 (equal comment nil
))
2434 (widget-put widget
:custom-state state
)))
2436 (defun custom-variable-standard-value (widget)
2437 (get (widget-value widget
) 'standard-value
))
2439 (defvar custom-variable-menu
2440 '(("Set for Current Session" custom-variable-set
2442 (eq (widget-get widget
:custom-state
) 'modified
)))
2443 ("Save for Future Sessions" custom-variable-save
2445 (memq (widget-get widget
:custom-state
) '(modified set changed rogue
))))
2446 ("Reset to Current" custom-redraw
2448 (and (default-boundp (widget-value widget
))
2449 (memq (widget-get widget
:custom-state
) '(modified changed
)))))
2450 ("Reset to Saved" custom-variable-reset-saved
2452 (and (or (get (widget-value widget
) 'saved-value
)
2453 (get (widget-value widget
) 'saved-variable-comment
))
2454 (memq (widget-get widget
:custom-state
)
2455 '(modified set changed rogue
)))))
2456 ("Erase Customization" custom-variable-reset-standard
2458 (and (get (widget-value widget
) 'standard-value
)
2459 (memq (widget-get widget
:custom-state
)
2460 '(modified set changed saved rogue
)))))
2461 ("Use Backup Value" custom-variable-reset-backup
2463 (get (widget-value widget
) 'backup-value
)))
2464 ("---" ignore ignore
)
2465 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
2466 ("---" ignore ignore
)
2467 ("Don't show as Lisp expression" custom-variable-edit
2469 (eq (widget-get widget
:custom-form
) 'lisp
)))
2470 ("Show initial Lisp expression" custom-variable-edit-lisp
2472 (eq (widget-get widget
:custom-form
) 'edit
))))
2473 "Alist of actions for the `custom-variable' widget.
2474 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2475 the menu entry, ACTION is the function to call on the widget when the
2476 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2477 widget as an argument, and returns non-nil if ACTION is valid on that
2478 widget. If FILTER is nil, ACTION is always valid.")
2480 (defun custom-variable-action (widget &optional event
)
2481 "Show the menu for `custom-variable' WIDGET.
2482 Optional EVENT is the location for the menu."
2483 (if (eq (widget-get widget
:custom-state
) 'hidden
)
2484 (custom-toggle-hide widget
)
2485 (unless (eq (widget-get widget
:custom-state
) 'modified
)
2486 (custom-variable-state-set widget
))
2487 (custom-redraw-magic widget
)
2488 (let* ((completion-ignore-case t
)
2489 (answer (widget-choose (concat "Operation on "
2490 (custom-unlispify-tag-name
2491 (widget-get widget
:value
)))
2492 (custom-menu-filter custom-variable-menu
2496 (funcall answer widget
)))))
2498 (defun custom-variable-edit (widget)
2499 "Edit value of WIDGET."
2500 (widget-put widget
:custom-state
'unknown
)
2501 (widget-put widget
:custom-form
'edit
)
2502 (custom-redraw widget
))
2504 (defun custom-variable-edit-lisp (widget)
2505 "Edit the Lisp representation of the value of WIDGET."
2506 (widget-put widget
:custom-state
'unknown
)
2507 (widget-put widget
:custom-form
'lisp
)
2508 (custom-redraw widget
))
2510 (defun custom-variable-set (widget)
2511 "Set the current value for the variable being edited by WIDGET."
2512 (let* ((form (widget-get widget
:custom-form
))
2513 (state (widget-get widget
:custom-state
))
2514 (child (car (widget-get widget
:children
)))
2515 (symbol (widget-value widget
))
2516 (set (or (get symbol
'custom-set
) 'set-default
))
2517 (comment-widget (widget-get widget
:comment-widget
))
2518 (comment (widget-value comment-widget
))
2520 (cond ((eq state
'hidden
)
2521 (error "Cannot set hidden variable"))
2522 ((setq val
(widget-apply child
:validate
))
2523 (goto-char (widget-get val
:from
))
2524 (error "%s" (widget-get val
:error
)))
2525 ((memq form
'(lisp mismatch
))
2526 (when (equal comment
"")
2528 ;; Make the comment invisible by hand if it's empty
2529 (custom-comment-hide comment-widget
))
2530 (custom-variable-backup-value widget
)
2531 (funcall set symbol
(eval (setq val
(widget-value child
))))
2532 (put symbol
'customized-value
(list val
))
2533 (put symbol
'variable-comment comment
)
2534 (put symbol
'customized-variable-comment comment
))
2536 (when (equal comment
"")
2538 ;; Make the comment invisible by hand if it's empty
2539 (custom-comment-hide comment-widget
))
2540 (custom-variable-backup-value widget
)
2541 (funcall set symbol
(setq val
(widget-value child
)))
2542 (put symbol
'customized-value
(list (custom-quote val
)))
2543 (put symbol
'variable-comment comment
)
2544 (put symbol
'customized-variable-comment comment
)))
2545 (custom-variable-state-set widget
)
2546 (custom-redraw-magic widget
)))
2548 (defun custom-variable-save (widget)
2549 "Set and save the value for the variable being edited by WIDGET."
2550 (let* ((form (widget-get widget
:custom-form
))
2551 (state (widget-get widget
:custom-state
))
2552 (child (car (widget-get widget
:children
)))
2553 (symbol (widget-value widget
))
2554 (set (or (get symbol
'custom-set
) 'set-default
))
2555 (comment-widget (widget-get widget
:comment-widget
))
2556 (comment (widget-value comment-widget
))
2558 (cond ((eq state
'hidden
)
2559 (error "Cannot set hidden variable"))
2560 ((setq val
(widget-apply child
:validate
))
2561 (goto-char (widget-get val
:from
))
2562 (error "Saving %s: %s" symbol
(widget-get val
:error
)))
2563 ((memq form
'(lisp mismatch
))
2564 (when (equal comment
"")
2566 ;; Make the comment invisible by hand if it's empty
2567 (custom-comment-hide comment-widget
))
2568 (put symbol
'saved-value
(list (widget-value child
)))
2569 (custom-push-theme 'theme-value symbol
'user
2570 'set
(list (widget-value child
)))
2571 (funcall set symbol
(eval (widget-value child
)))
2572 (put symbol
'variable-comment comment
)
2573 (put symbol
'saved-variable-comment comment
))
2575 (when (equal comment
"")
2577 ;; Make the comment invisible by hand if it's empty
2578 (custom-comment-hide comment-widget
))
2579 (put symbol
'saved-value
2580 (list (custom-quote (widget-value child
))))
2581 (custom-push-theme 'theme-value symbol
'user
2582 'set
(list (custom-quote (widget-value
2584 (funcall set symbol
(widget-value child
))
2585 (put symbol
'variable-comment comment
)
2586 (put symbol
'saved-variable-comment comment
)))
2587 (put symbol
'customized-value nil
)
2588 (put symbol
'customized-variable-comment nil
)
2590 (custom-variable-state-set widget
)
2591 (custom-redraw-magic widget
)))
2593 (defun custom-variable-reset-saved (widget)
2594 "Restore the saved value for the variable being edited by WIDGET.
2595 The value that was current before this operation
2596 becomes the backup value, so you can get it again."
2597 (let* ((symbol (widget-value widget
))
2598 (set (or (get symbol
'custom-set
) 'set-default
))
2599 (value (get symbol
'saved-value
))
2600 (comment (get symbol
'saved-variable-comment
)))
2601 (cond ((or value comment
)
2602 (put symbol
'variable-comment comment
)
2603 (custom-variable-backup-value widget
)
2605 (funcall set symbol
(eval (car value
)))
2608 (error "No saved value for %s" symbol
)))
2609 (put symbol
'customized-value nil
)
2610 (put symbol
'customized-variable-comment nil
)
2611 (widget-put widget
:custom-state
'unknown
)
2612 ;; This call will possibly make the comment invisible
2613 (custom-redraw widget
)))
2615 (defun custom-variable-reset-standard (widget)
2616 "Restore the standard setting for the variable being edited by WIDGET.
2617 This operation eliminates any saved setting for the variable,
2618 restoring it to the state of a variable that has never been customized.
2619 The value that was current before this operation
2620 becomes the backup value, so you can get it again."
2621 (let* ((symbol (widget-value widget
))
2622 (set (or (get symbol
'custom-set
) 'set-default
)))
2623 (if (get symbol
'standard-value
)
2625 (custom-variable-backup-value widget
)
2626 (funcall set symbol
(eval (car (get symbol
'standard-value
)))))
2627 (error "No standard setting known for %S" symbol
))
2628 (put symbol
'variable-comment nil
)
2629 (put symbol
'customized-value nil
)
2630 (put symbol
'customized-variable-comment nil
)
2631 (when (or (get symbol
'saved-value
) (get symbol
'saved-variable-comment
))
2632 (put symbol
'saved-value nil
)
2633 (custom-push-theme 'theme-value symbol
'user
'reset
'standard
)
2634 ;; As a special optimizations we do not (explictly)
2635 ;; save resets to standard when no theme set the value.
2636 (if (null (cdr (get symbol
'theme-value
)))
2637 (put symbol
'theme-value nil
))
2638 (put symbol
'saved-variable-comment nil
)
2640 (widget-put widget
:custom-state
'unknown
)
2641 ;; This call will possibly make the comment invisible
2642 (custom-redraw widget
)))
2644 (defun custom-variable-backup-value (widget)
2645 "Back up the current value for WIDGET's variable.
2646 The backup value is kept in the car of the `backup-value' property."
2647 (let* ((symbol (widget-value widget
))
2648 (get (or (get symbol
'custom-get
) 'default-value
))
2649 (type (custom-variable-type symbol
))
2650 (conv (widget-convert type
))
2651 (value (if (default-boundp symbol
)
2652 (funcall get symbol
)
2653 (widget-get conv
:value
))))
2654 (put symbol
'backup-value
(list value
))))
2656 (defun custom-variable-reset-backup (widget)
2657 "Restore the backup value for the variable being edited by WIDGET.
2658 The value that was current before this operation
2659 becomes the backup value, so you can use this operation repeatedly
2660 to switch between two values."
2661 (let* ((symbol (widget-value widget
))
2662 (set (or (get symbol
'custom-set
) 'set-default
))
2663 (value (get symbol
'backup-value
))
2664 (comment-widget (widget-get widget
:comment-widget
))
2665 (comment (widget-value comment-widget
)))
2668 (custom-variable-backup-value widget
)
2670 (funcall set symbol
(car value
))
2672 (error "No backup value for %s" symbol
))
2673 (put symbol
'customized-value
(list (car value
)))
2674 (put symbol
'variable-comment comment
)
2675 (put symbol
'customized-variable-comment comment
)
2676 (custom-variable-state-set widget
)
2677 ;; This call will possibly make the comment invisible
2678 (custom-redraw widget
)))
2680 ;;; The `custom-face-edit' Widget.
2682 (define-widget 'custom-face-edit
'checklist
2683 "Edit face attributes."
2687 :button-args
'(:help-echo
"Control whether this attribute has any effect.")
2688 :value-to-internal
'custom-face-edit-fix-value
2689 :match
(lambda (widget value
)
2690 (widget-checklist-match widget
2691 (custom-face-edit-fix-value widget value
)))
2692 :convert-widget
'custom-face-edit-convert-widget
2693 :args
(mapcar (lambda (att)
2696 :sibling-args
(widget-get (nth 1 att
) :sibling-args
)
2697 (list 'const
:format
"" :value
(nth 0 att
))
2699 custom-face-attributes
))
2701 (defun custom-face-edit-fix-value (widget value
)
2702 "Ignoring WIDGET, convert :bold and :italic in VALUE to new form.
2703 Also change :reverse-video to :inverse-video."
2707 (let ((key (car value
))
2708 (val (car (cdr value
))))
2709 (cond ((eq key
:italic
)
2710 (push :slant result
)
2711 (push (if val
'italic
'normal
) result
))
2713 (push :weight result
)
2714 (push (if val
'bold
'normal
) result
))
2715 ((eq key
:reverse-video
)
2716 (push :inverse-video result
)
2720 (push val result
))))
2721 (setq value
(cdr (cdr value
))))
2722 (setq result
(nreverse result
))
2726 (defun custom-face-edit-convert-widget (widget)
2727 "Convert :args as widget types in WIDGET."
2730 :args
(mapcar (lambda (arg)
2732 :deactivate
'custom-face-edit-deactivate
2733 :activate
'custom-face-edit-activate
2734 :delete
'custom-face-edit-delete
))
2735 (widget-get widget
:args
)))
2738 (defun custom-face-edit-deactivate (widget)
2739 "Make face widget WIDGET inactive for user modifications."
2740 (unless (widget-get widget
:inactive
)
2741 (let ((tag (custom-face-edit-attribute-tag widget
))
2742 (from (copy-marker (widget-get widget
:from
)))
2743 (value (widget-value widget
))
2744 (inhibit-read-only t
)
2745 (inhibit-modification-hooks t
))
2748 (widget-default-delete widget
)
2749 (insert tag
": *\n")
2750 (widget-put widget
:inactive
2751 (cons value
(cons from
(- (point) from
))))))))
2753 (defun custom-face-edit-activate (widget)
2754 "Make face widget WIDGET inactive for user modifications."
2755 (let ((inactive (widget-get widget
:inactive
))
2756 (inhibit-read-only t
)
2757 (inhibit-modification-hooks t
))
2758 (when (consp inactive
)
2760 (goto-char (car (cdr inactive
)))
2761 (delete-region (point) (+ (point) (cdr (cdr inactive
))))
2762 (widget-put widget
:inactive nil
)
2763 (widget-apply widget
:create
)
2764 (widget-value-set widget
(car inactive
))
2767 (defun custom-face-edit-delete (widget)
2768 "Remove WIDGET from the buffer."
2769 (let ((inactive (widget-get widget
:inactive
))
2770 (inhibit-read-only t
)
2771 (inhibit-modification-hooks t
))
2773 ;; Widget is alive, we don't have to do anything special
2774 (widget-default-delete widget
)
2775 ;; WIDGET is already deleted because we did so to inactivate it;
2776 ;; now just get rid of the label we put in its place.
2777 (delete-region (car (cdr inactive
))
2778 (+ (car (cdr inactive
)) (cdr (cdr inactive
))))
2779 (widget-put widget
:inactive nil
))))
2782 (defun custom-face-edit-attribute-tag (widget)
2783 "Returns the first :tag property in WIDGET or one of its children."
2784 (let ((tag (widget-get widget
:tag
)))
2785 (or (and (not (equal tag
"")) tag
)
2786 (let ((children (widget-get widget
:children
)))
2787 (while (and (null tag
) children
)
2788 (setq tag
(custom-face-edit-attribute-tag (pop children
))))
2791 ;;; The `custom-display' Widget.
2793 (define-widget 'custom-display
'menu-choice
2794 "Select a display type."
2797 :help-echo
"Specify frames where the face attributes should be used."
2798 :args
'((const :tag
"all" t
)
2799 (const :tag
"defaults" default
)
2803 :args
((group :sibling-args
(:help-echo
"\
2804 Only match the specified window systems.")
2805 (const :format
"Type: "
2807 (checklist :inline t
2810 :sibling-args
(:help-echo
"\
2811 The X11 Window System.")
2813 (const :format
"PM "
2814 :sibling-args
(:help-echo
"\
2815 OS/2 Presentation Manager.")
2817 (const :format
"W32 "
2818 :sibling-args
(:help-echo
"\
2821 (const :format
"MAC "
2822 :sibling-args
(:help-echo
"\
2825 (const :format
"DOS "
2826 :sibling-args
(:help-echo
"\
2829 (const :format
"TTY%n"
2830 :sibling-args
(:help-echo
"\
2831 Plain text terminals.")
2833 (group :sibling-args
(:help-echo
"\
2834 Only match the frames with the specified color support.")
2835 (const :format
"Class: "
2837 (checklist :inline t
2839 (const :format
"Color "
2840 :sibling-args
(:help-echo
"\
2841 Match color frames.")
2843 (const :format
"Grayscale "
2844 :sibling-args
(:help-echo
"\
2845 Match grayscale frames.")
2847 (const :format
"Monochrome%n"
2848 :sibling-args
(:help-echo
"\
2849 Match frames with no color support.")
2851 (group :sibling-args
(:help-echo
"\
2852 The minimum number of colors the frame should support.")
2853 (const :format
"" min-colors
)
2854 (integer :tag
"Minimum number of colors" ))
2855 (group :sibling-args
(:help-echo
"\
2856 Only match frames with the specified intensity.")
2858 Background brightness: "
2860 (checklist :inline t
2862 (const :format
"Light "
2863 :sibling-args
(:help-echo
"\
2864 Match frames with light backgrounds.")
2866 (const :format
"Dark\n"
2867 :sibling-args
(:help-echo
"\
2868 Match frames with dark backgrounds.")
2870 (group :sibling-args
(:help-echo
"\
2871 Only match frames that support the specified face attributes.")
2872 (const :format
"Supports attributes:" supports
)
2873 (custom-face-edit :inline t
:format
"%n%v"))))))
2875 ;;; The `custom-face' Widget.
2877 (defface custom-face-tag-face
2878 `((t (:weight bold
:height
1.2 :inherit variable-pitch
)))
2879 "Face used for face tags."
2880 :group
'custom-faces
)
2882 (defcustom custom-face-default-form
'selected
2883 "Default form of displaying face definition."
2884 :type
'(choice (const all
)
2887 :group
'custom-buffer
2890 (define-widget 'custom-face
'custom
2892 :sample-face
'custom-face-tag-face
2893 :help-echo
"Set or reset this face."
2894 :documentation-property
#'face-doc-string
2895 :value-create
'custom-face-value-create
2896 :action
'custom-face-action
2897 :custom-category
'face
2898 :custom-form nil
; defaults to value of `custom-face-default-form'
2899 :custom-set
'custom-face-set
2900 :custom-save
'custom-face-save
2901 :custom-reset-current
'custom-redraw
2902 :custom-reset-saved
'custom-face-reset-saved
2903 :custom-reset-standard
'custom-face-reset-standard
2904 :custom-standard-value
'custom-face-standard-value
2905 :custom-menu
'custom-face-menu-create
)
2907 (define-widget 'custom-face-all
'editable-list
2908 "An editable list of display specifications and attributes."
2909 :entry-format
"%i %d %v"
2910 :insert-button-args
'(:help-echo
"Insert new display specification here.")
2911 :append-button-args
'(:help-echo
"Append new display specification here.")
2912 :delete-button-args
'(:help-echo
"Delete this display specification.")
2913 :args
'((group :format
"%v" custom-display custom-face-edit
)))
2915 (defconst custom-face-all
(widget-convert 'custom-face-all
)
2916 "Converted version of the `custom-face-all' widget.")
2918 (define-widget 'custom-display-unselected
'item
2919 "A display specification that doesn't match the selected display."
2920 :match
'custom-display-unselected-match
)
2922 (defun custom-display-unselected-match (widget value
)
2923 "Non-nil if VALUE is an unselected display specification."
2924 (not (face-spec-set-match-display value
(selected-frame))))
2926 (define-widget 'custom-face-selected
'group
2927 "Edit the attributes of the selected display in a face specification."
2928 :args
'((choice :inline t
2929 (group :tag
"With Defaults" :inline t
2930 (group (const :tag
"" default
)
2931 (custom-face-edit :tag
" Default\n Attributes"))
2934 (group custom-display-unselected sexp
))
2935 (group (sexp :format
"")
2936 (custom-face-edit :tag
" Overriding\n Attributes"))
2940 (group :tag
"No Defaults" :inline t
2943 (group custom-display-unselected sexp
))
2944 (group (sexp :format
"")
2945 (custom-face-edit :tag
"\n Attributes"))
2952 (defconst custom-face-selected
(widget-convert 'custom-face-selected
)
2953 "Converted version of the `custom-face-selected' widget.")
2955 (defun custom-filter-face-spec (spec filter-index
&optional default-filter
)
2956 "Return a canonicalized version of SPEC using.
2957 FILTER-INDEX is the index in the entry for each attribute in
2958 `custom-face-attributes' at which the appropriate filter function can be
2959 found, and DEFAULT-FILTER is the filter to apply for attributes that
2961 (mapcar (lambda (entry)
2962 ;; Filter a single face-spec entry
2963 (let ((tests (car entry
))
2965 ;; Handle both old- and new-style attribute syntax
2966 (if (listp (car (cdr entry
)))
2969 (filtered-attrs nil
))
2970 ;; Filter each face attribute
2971 (while unfiltered-attrs
2972 (let* ((attr (pop unfiltered-attrs
))
2973 (pre-filtered-value (pop unfiltered-attrs
))
2975 (or (nth filter-index
(assq attr custom-face-attributes
))
2979 (funcall filter pre-filtered-value
)
2980 pre-filtered-value
)))
2981 (push filtered-value filtered-attrs
)
2982 (push attr filtered-attrs
)))
2984 (list tests filtered-attrs
)))
2987 (defun custom-pre-filter-face-spec (spec)
2988 "Return SPEC changed as necessary for editing by the face customization widget.
2989 SPEC must be a full face spec."
2990 (custom-filter-face-spec spec
2))
2992 (defun custom-post-filter-face-spec (spec)
2993 "Return the customized SPEC in a form suitable for setting the face."
2994 (custom-filter-face-spec spec
3))
2996 (defun custom-face-value-create (widget)
2997 "Create a list of the display specifications for WIDGET."
2998 (let ((buttons (widget-get widget
:buttons
))
3000 (symbol (widget-get widget
:value
))
3001 (tag (widget-get widget
:tag
))
3002 (state (widget-get widget
:custom-state
))
3004 (is-last (widget-get widget
:custom-last
))
3005 (prefix (widget-get widget
:custom-prefix
)))
3007 (setq tag
(prin1-to-string symbol
)))
3008 (cond ((eq custom-buffer-style
'tree
)
3009 (insert prefix
(if is-last
" `--- " " |--- "))
3010 (push (widget-create-child-and-convert
3011 widget
'custom-browse-face-tag
)
3013 (insert " " tag
"\n")
3014 (widget-put widget
:buttons buttons
))
3018 (widget-specify-sample widget begin
(point))
3019 (if (eq custom-buffer-style
'face
)
3021 (if (string-match "face\\'" tag
)
3023 (insert " face: ")))
3025 (push (widget-create-child-and-convert widget
'item
3032 (push (widget-create-child-and-convert
3034 :help-echo
"Hide or show this face."
3037 :action
'custom-toggle-parent
3038 (not (eq state
'hidden
)))
3042 (let ((magic (widget-create-child-and-convert
3043 widget
'custom-magic nil
)))
3044 (widget-put widget
:custom-magic magic
)
3045 (push magic buttons
))
3047 (widget-put widget
:buttons buttons
)
3048 ;; Insert documentation.
3049 (widget-default-format-handler widget ?h
)
3050 ;; The comment field
3051 (unless (eq state
'hidden
)
3052 (let* ((comment (get symbol
'face-comment
))
3054 (widget-create-child-and-convert
3055 widget
'custom-comment
3057 :value
(or comment
""))))
3058 (widget-put widget
:comment-widget comment-widget
)
3059 (push comment-widget children
)))
3061 (unless (eq state
'hidden
)
3062 (when (eq (widget-get widget
:custom-level
) 1)
3063 (custom-add-parent-links widget
))
3064 (custom-add-see-also widget
))
3066 (unless (eq (preceding-char) ?
\n)
3068 (unless (eq state
'hidden
)
3069 (message "Creating face editor...")
3070 (custom-load-widget widget
)
3071 (unless (widget-get widget
:custom-form
)
3072 (widget-put widget
:custom-form custom-face-default-form
))
3073 (let* ((symbol (widget-value widget
))
3074 (spec (or (get symbol
'customized-face
)
3075 (get symbol
'saved-face
)
3076 (get symbol
'face-defface-spec
)
3077 ;; Attempt to construct it.
3078 (list (list t
(custom-face-attributes-get
3079 symbol
(selected-frame))))))
3080 (form (widget-get widget
:custom-form
))
3081 (indent (widget-get widget
:indent
))
3083 ;; If the user has changed this face in some other way,
3084 ;; edit it as the user has specified it.
3085 (if (not (face-spec-match-p symbol spec
(selected-frame)))
3086 (setq spec
(list (list t
(face-attr-construct symbol
(selected-frame))))))
3087 (setq spec
(custom-pre-filter-face-spec spec
))
3088 (setq edit
(widget-create-child-and-convert
3090 (cond ((and (eq form
'selected
)
3091 (widget-apply custom-face-selected
3093 (when indent
(insert-char ?\ indent
))
3094 'custom-face-selected
)
3095 ((and (not (eq form
'lisp
))
3096 (widget-apply custom-face-all
3100 (when indent
(insert-char ?\ indent
))
3103 (custom-face-state-set widget
)
3104 (push edit children
)
3105 (widget-put widget
:children children
))
3106 (message "Creating face editor...done"))))))
3108 (defvar custom-face-menu
3109 '(("Set for Current Session" custom-face-set
)
3110 ("Save for Future Sessions" custom-face-save-command
)
3111 ("Reset to Saved" custom-face-reset-saved
3113 (or (get (widget-value widget
) 'saved-face
)
3114 (get (widget-value widget
) 'saved-face-comment
))))
3115 ("Erase Customization" custom-face-reset-standard
3117 (get (widget-value widget
) 'face-defface-spec
)))
3118 ("---" ignore ignore
)
3119 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
3120 ("---" ignore ignore
)
3121 ("Show all display specs" custom-face-edit-all
3123 (not (eq (widget-get widget
:custom-form
) 'all
))))
3124 ("Just current attributes" custom-face-edit-selected
3126 (not (eq (widget-get widget
:custom-form
) 'selected
))))
3127 ("Show as Lisp expression" custom-face-edit-lisp
3129 (not (eq (widget-get widget
:custom-form
) 'lisp
)))))
3130 "Alist of actions for the `custom-face' widget.
3131 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3132 the menu entry, ACTION is the function to call on the widget when the
3133 menu is selected, and FILTER is a predicate which takes a `custom-face'
3134 widget as an argument, and returns non-nil if ACTION is valid on that
3135 widget. If FILTER is nil, ACTION is always valid.")
3137 (defun custom-face-edit-selected (widget)
3138 "Edit selected attributes of the value of WIDGET."
3139 (widget-put widget
:custom-state
'unknown
)
3140 (widget-put widget
:custom-form
'selected
)
3141 (custom-redraw widget
))
3143 (defun custom-face-edit-all (widget)
3144 "Edit all attributes of the value of WIDGET."
3145 (widget-put widget
:custom-state
'unknown
)
3146 (widget-put widget
:custom-form
'all
)
3147 (custom-redraw widget
))
3149 (defun custom-face-edit-lisp (widget)
3150 "Edit the Lisp representation of the value of WIDGET."
3151 (widget-put widget
:custom-state
'unknown
)
3152 (widget-put widget
:custom-form
'lisp
)
3153 (custom-redraw widget
))
3155 (defun custom-face-state-set (widget)
3156 "Set the state of WIDGET."
3157 (let* ((symbol (widget-value widget
))
3158 (comment (get symbol
'face-comment
))
3162 (setq tmp
(get symbol
'customized-face
))
3163 (setq temp
(get symbol
'customized-face-comment
))
3165 (if (equal temp comment
)
3169 (setq tmp
(get symbol
'saved-face
))
3170 (setq temp
(get symbol
'saved-face-comment
))
3172 (if (equal temp comment
)
3175 ((get symbol
'face-defface-spec
)
3176 (if (equal comment nil
)
3181 ;; If the user called set-face-attribute to change the default
3182 ;; for new frames, this face is "set outside of Customize".
3183 (if (and (not (eq state
'rogue
))
3184 (get symbol
'face-modified
))
3185 (setq state
'changed
))
3186 (widget-put widget
:custom-state state
)))
3188 (defun custom-face-action (widget &optional event
)
3189 "Show the menu for `custom-face' WIDGET.
3190 Optional EVENT is the location for the menu."
3191 (if (eq (widget-get widget
:custom-state
) 'hidden
)
3192 (custom-toggle-hide widget
)
3193 (let* ((completion-ignore-case t
)
3194 (symbol (widget-get widget
:value
))
3195 (answer (widget-choose (concat "Operation on "
3196 (custom-unlispify-tag-name symbol
))
3197 (custom-menu-filter custom-face-menu
3201 (funcall answer widget
)))))
3203 (defun custom-face-set (widget)
3204 "Make the face attributes in WIDGET take effect."
3205 (let* ((symbol (widget-value widget
))
3206 (child (car (widget-get widget
:children
)))
3207 (value (custom-post-filter-face-spec (widget-value child
)))
3208 (comment-widget (widget-get widget
:comment-widget
))
3209 (comment (widget-value comment-widget
)))
3210 (when (equal comment
"")
3212 ;; Make the comment invisible by hand if it's empty
3213 (custom-comment-hide comment-widget
))
3214 (put symbol
'customized-face value
)
3215 (if (face-spec-choose value
)
3216 (face-spec-set symbol value
)
3217 ;; face-set-spec ignores empty attribute lists, so just give it
3218 ;; something harmless instead.
3219 (face-spec-set symbol
'((t :foreground unspecified
))))
3220 (put symbol
'customized-face-comment comment
)
3221 (put symbol
'face-comment comment
)
3222 (custom-face-state-set widget
)
3223 (custom-redraw-magic widget
)))
3225 (defun custom-face-save-command (widget)
3226 "Save in `.emacs' the face attributes in WIDGET."
3227 (custom-face-save widget
)
3230 (defun custom-face-save (widget)
3231 "Prepare for saving WIDGET's face attributes, but don't write `.emacs'."
3232 (let* ((symbol (widget-value widget
))
3233 (child (car (widget-get widget
:children
)))
3234 (value (custom-post-filter-face-spec (widget-value child
)))
3235 (comment-widget (widget-get widget
:comment-widget
))
3236 (comment (widget-value comment-widget
)))
3237 (when (equal comment
"")
3239 ;; Make the comment invisible by hand if it's empty
3240 (custom-comment-hide comment-widget
))
3241 (if (face-spec-choose value
)
3242 (face-spec-set symbol value
)
3243 ;; face-set-spec ignores empty attribute lists, so just give it
3244 ;; something harmless instead.
3245 (face-spec-set symbol
'((t :foreground unspecified
))))
3246 (unless (eq (widget-get widget
:custom-state
) 'standard
)
3247 (put symbol
'saved-face value
))
3248 (custom-push-theme 'theme-face symbol
'user
'set value
)
3249 (put symbol
'customized-face nil
)
3250 (put symbol
'face-comment comment
)
3251 (put symbol
'customized-face-comment nil
)
3252 (put symbol
'saved-face-comment comment
)
3254 (custom-face-state-set widget
)
3255 (custom-redraw-magic widget
)))
3257 (defun custom-face-reset-saved (widget)
3258 "Restore WIDGET to the face's default attributes."
3259 (let* ((symbol (widget-value widget
))
3260 (child (car (widget-get widget
:children
)))
3261 (value (get symbol
'saved-face
))
3262 (comment (get symbol
'saved-face-comment
))
3263 (comment-widget (widget-get widget
:comment-widget
)))
3264 (unless (or value comment
)
3265 (error "No saved value for this face"))
3266 (put symbol
'customized-face nil
)
3267 (put symbol
'customized-face-comment nil
)
3268 (face-spec-set symbol value
)
3269 (put symbol
'face-comment comment
)
3270 (widget-value-set child value
)
3271 ;; This call manages the comment visibility
3272 (widget-value-set comment-widget
(or comment
""))
3273 (custom-face-state-set widget
)
3274 (custom-redraw-magic widget
)))
3276 (defun custom-face-standard-value (widget)
3277 (get (widget-value widget
) 'face-defface-spec
))
3279 (defun custom-face-reset-standard (widget)
3280 "Restore WIDGET to the face's standard settings.
3281 This operation eliminates any saved setting for the face,
3282 restoring it to the state of a face that has never been customized."
3283 (let* ((symbol (widget-value widget
))
3284 (child (car (widget-get widget
:children
)))
3285 (value (get symbol
'face-defface-spec
))
3286 (comment-widget (widget-get widget
:comment-widget
)))
3288 (error "No standard setting for this face"))
3289 (put symbol
'customized-face nil
)
3290 (put symbol
'customized-face-comment nil
)
3291 (when (or (get symbol
'saved-face
) (get symbol
'saved-face-comment
))
3292 (put symbol
'saved-face nil
)
3293 (custom-push-theme 'theme-face symbol
'user
'reset
'standard
)
3294 ;; Do not explictly save resets to standards without themes.
3295 (if (null (cdr (get symbol
'theme-face
)))
3296 (put symbol
'theme-face nil
))
3297 (put symbol
'saved-face-comment nil
)
3299 (face-spec-set symbol value
)
3300 (put symbol
'face-comment nil
)
3301 (widget-value-set child value
)
3302 ;; This call manages the comment visibility
3303 (widget-value-set comment-widget
"")
3304 (custom-face-state-set widget
)
3305 (custom-redraw-magic widget
)))
3307 ;;; The `face' Widget.
3309 (defvar widget-face-prompt-value-history nil
3310 "History of input to `widget-face-prompt-value'.")
3312 (define-widget 'face
'symbol
3313 "A Lisp face name (with sample)."
3314 :format
"%t: (%{sample%}) %v"
3317 :sample-face-get
'widget-face-sample-face-get
3318 :notify
'widget-face-notify
3319 :match
(lambda (widget value
) (facep value
))
3320 :complete-function
(lambda ()
3322 (lisp-complete-symbol 'facep
))
3323 :prompt-match
'facep
3324 :prompt-history
'widget-face-prompt-value-history
3325 :validate
(lambda (widget)
3326 (unless (facep (widget-value widget
))
3328 :error
(format "Invalid face: %S"
3329 (widget-value widget
)))
3332 (defun widget-face-sample-face-get (widget)
3333 (let ((value (widget-value widget
)))
3338 (defun widget-face-notify (widget child
&optional event
)
3339 "Update the sample, and notify the parent."
3340 (overlay-put (widget-get widget
:sample-overlay
)
3341 'face
(widget-apply widget
:sample-face-get
))
3342 (widget-default-notify widget child event
))
3345 ;;; The `hook' Widget.
3347 (define-widget 'hook
'list
3349 :value-to-internal
(lambda (widget value
)
3350 (if (and value
(symbolp value
))
3353 :match
(lambda (widget value
)
3355 (widget-group-match widget value
)))
3356 ;; Avoid adding undefined functions to the hook, especially for
3357 ;; things like `find-file-hook' or even more basic ones, to avoid
3359 :set
(lambda (symbol value
)
3362 (add-hook symbol elt
))))
3363 :convert-widget
'custom-hook-convert-widget
3366 (defun custom-hook-convert-widget (widget)
3367 ;; Handle `:options'.
3368 (let* ((options (widget-get widget
:options
))
3369 (other `(editable-list :inline t
3370 :entry-format
"%i %d%v"
3371 (function :format
" %v")))
3373 (list `(checklist :inline t
3374 ,@(mapcar (lambda (entry)
3375 `(function-item ,entry
))
3379 (widget-put widget
:args args
)
3382 ;;; The `custom-group-link' Widget.
3384 (define-widget 'custom-group-link
'link
3385 "Show parent in other window when activated."
3386 :help-echo
"Create customization buffer for this group."
3387 :action
'custom-group-link-action
)
3389 (defun custom-group-link-action (widget &rest ignore
)
3390 (customize-group (widget-value widget
)))
3392 ;;; The `custom-group' Widget.
3394 (defcustom custom-group-tag-faces nil
3395 ;; In XEmacs, this ought to play games with font size.
3396 ;; Fixme: make it do so in Emacs.
3397 "Face used for group tags.
3398 The first member is used for level 1 groups, the second for level 2,
3399 and so forth. The remaining group tags are shown with
3400 `custom-group-tag-face'."
3401 :type
'(repeat face
)
3402 :group
'custom-faces
)
3404 (defface custom-group-tag-face-1
3407 (:foreground
"pink" :weight bold
:height
1.2 :inherit variable-pitch
))
3408 (((min-colors 88) (class color
)
3410 (:foreground
"red1" :weight bold
:height
1.2 :inherit variable-pitch
))
3413 (:foreground
"red" :weight bold
:height
1.2 :inherit variable-pitch
))
3415 "Face used for group tags."
3416 :group
'custom-faces
)
3418 (defface custom-group-tag-face
3421 (:foreground
"light blue" :weight bold
:height
1.2))
3422 (((min-colors 88) (class color
)
3424 (:foreground
"blue1" :weight bold
:height
1.2))
3427 (:foreground
"blue" :weight bold
:height
1.2))
3429 "Face used for low level group tags."
3430 :group
'custom-faces
)
3432 (define-widget 'custom-group
'custom
3435 :sample-face-get
'custom-group-sample-face-get
3436 :documentation-property
'group-documentation
3437 :help-echo
"Set or reset all members of this group."
3438 :value-create
'custom-group-value-create
3439 :action
'custom-group-action
3440 :custom-category
'group
3441 :custom-set
'custom-group-set
3442 :custom-save
'custom-group-save
3443 :custom-reset-current
'custom-group-reset-current
3444 :custom-reset-saved
'custom-group-reset-saved
3445 :custom-reset-standard
'custom-group-reset-standard
3446 :custom-menu
'custom-group-menu-create
)
3448 (defun custom-group-sample-face-get (widget)
3449 ;; Use :sample-face.
3450 (or (nth (1- (widget-get widget
:custom-level
)) custom-group-tag-faces
)
3451 'custom-group-tag-face
))
3453 (define-widget 'custom-group-visibility
'visibility
3454 "An indicator and manipulator for hidden group contents."
3455 :create
'custom-group-visibility-create
)
3457 (defun custom-group-visibility-create (widget)
3458 (let ((visible (widget-value widget
)))
3460 (insert "--------")))
3461 (widget-default-create widget
))
3463 (defun custom-group-members (symbol groups-only
)
3464 "Return SYMBOL's custom group members.
3465 If GROUPS-ONLY non-nil, return only those members that are groups."
3466 (if (not groups-only
)
3467 (get symbol
'custom-group
)
3469 (dolist (entry (get symbol
'custom-group
))
3470 (when (eq (nth 1 entry
) 'custom-group
)
3471 (push entry members
)))
3472 (nreverse members
))))
3474 (defun custom-group-value-create (widget)
3475 "Insert a customize group for WIDGET in the current buffer."
3476 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
3477 (custom-load-widget widget
))
3478 (let* ((state (widget-get widget
:custom-state
))
3479 (level (widget-get widget
:custom-level
))
3480 ;; (indent (widget-get widget :indent))
3481 (prefix (widget-get widget
:custom-prefix
))
3482 (buttons (widget-get widget
:buttons
))
3483 (tag (widget-get widget
:tag
))
3484 (symbol (widget-value widget
))
3485 (members (custom-group-members symbol
3486 (and (eq custom-buffer-style
'tree
)
3487 custom-browse-only-groups
))))
3488 (cond ((and (eq custom-buffer-style
'tree
)
3490 (or members
(custom-unloaded-widget-p widget
)))
3491 (custom-browse-insert-prefix prefix
)
3492 (push (widget-create-child-and-convert
3493 widget
'custom-browse-visibility
3494 ;; :tag-glyph "plus"
3498 ;; (widget-glyph-insert nil "-- " "horizontal")
3499 (push (widget-create-child-and-convert
3500 widget
'custom-browse-group-tag
)
3502 (insert " " tag
"\n")
3503 (widget-put widget
:buttons buttons
))
3504 ((and (eq custom-buffer-style
'tree
)
3505 (zerop (length members
)))
3506 (custom-browse-insert-prefix prefix
)
3508 ;; (widget-glyph-insert nil "[ ]" "empty")
3509 ;; (widget-glyph-insert nil "-- " "horizontal")
3510 (push (widget-create-child-and-convert
3511 widget
'custom-browse-group-tag
)
3513 (insert " " tag
"\n")
3514 (widget-put widget
:buttons buttons
))
3515 ((eq custom-buffer-style
'tree
)
3516 (custom-browse-insert-prefix prefix
)
3517 (if (zerop (length members
))
3519 (custom-browse-insert-prefix prefix
)
3521 ;; (widget-glyph-insert nil "[ ]" "empty")
3522 ;; (widget-glyph-insert nil "-- " "horizontal")
3523 (push (widget-create-child-and-convert
3524 widget
'custom-browse-group-tag
)
3526 (insert " " tag
"\n")
3527 (widget-put widget
:buttons buttons
))
3528 (push (widget-create-child-and-convert
3529 widget
'custom-browse-visibility
3530 ;; :tag-glyph "minus"
3534 ;; (widget-glyph-insert nil "-\\ " "top")
3535 (push (widget-create-child-and-convert
3536 widget
'custom-browse-group-tag
)
3538 (insert " " tag
"\n")
3539 (widget-put widget
:buttons buttons
)
3540 (message "Creating group...")
3541 (let* ((members (custom-sort-items members
3542 custom-browse-sort-alphabetically
3543 custom-browse-order-groups
))
3544 (prefixes (widget-get widget
:custom-prefixes
))
3545 (custom-prefix-list (custom-prefix-add symbol prefixes
))
3546 (extra-prefix (if (widget-get widget
:custom-last
)
3549 (prefix (concat prefix extra-prefix
))
3552 (setq entry
(car members
)
3553 members
(cdr members
))
3554 (push (widget-create-child-and-convert
3555 widget
(nth 1 entry
)
3557 :tag
(custom-unlispify-tag-name (nth 0 entry
))
3558 :custom-prefixes custom-prefix-list
3559 :custom-level
(1+ level
)
3560 :custom-last
(null members
)
3561 :value
(nth 0 entry
)
3562 :custom-prefix prefix
)
3564 (widget-put widget
:children
(reverse children
)))
3565 (message "Creating group...done")))
3568 ;; Create level indicator.
3569 (unless (eq custom-buffer-style
'links
)
3570 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3573 (let ((begin (point)))
3575 (widget-specify-sample widget begin
(point)))
3577 ;; Create link/visibility indicator.
3578 (if (eq custom-buffer-style
'links
)
3579 (push (widget-create-child-and-convert
3580 widget
'custom-group-link
3584 (push (widget-create-child-and-convert
3585 widget
'custom-group-visibility
3586 :help-echo
"Show members of this group."
3587 :action
'custom-toggle-parent
3588 (not (eq state
'hidden
)))
3591 ;; Create magic button.
3592 (let ((magic (widget-create-child-and-convert
3593 widget
'custom-magic nil
)))
3594 (widget-put widget
:custom-magic magic
)
3595 (push magic buttons
))
3597 (widget-put widget
:buttons buttons
)
3598 ;; Insert documentation.
3599 (if (and (eq custom-buffer-style
'links
) (> level
1))
3600 (widget-put widget
:documentation-indent
0))
3601 (widget-default-format-handler widget ?h
))
3604 ;; Add parent groups references above the group.
3605 (if t
;;; This should test that the buffer
3606 ;;; was made to display a group.
3608 (if (custom-add-parent-links widget
3609 "Go to parent group:")
3611 ;; Create level indicator.
3612 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3615 (let ((start (point)))
3617 (widget-specify-sample widget start
(point)))
3619 ;; Create visibility indicator.
3620 (unless (eq custom-buffer-style
'links
)
3622 (push (widget-create-child-and-convert
3624 :help-echo
"Hide members of this group."
3625 :action
'custom-toggle-parent
3626 (not (eq state
'hidden
)))
3629 ;; Create more dashes.
3630 ;; Use 76 instead of 75 to compensate for the temporary "<"
3631 ;; added by `widget-insert'.
3632 (insert-char ?-
(- 76 (current-column)
3633 (* custom-buffer-indent level
)))
3635 ;; Create magic button.
3636 (let ((magic (widget-create-child-and-convert
3637 widget
'custom-magic
3640 (widget-put widget
:custom-magic magic
)
3641 (push magic buttons
))
3643 (widget-put widget
:buttons buttons
)
3644 ;; Insert documentation.
3645 (widget-default-format-handler widget ?h
)
3647 (if nil
;;; This should test that the buffer
3648 ;;; was not made to display a group.
3650 (insert-char ?\ custom-buffer-indent
)
3651 (custom-add-parent-links widget
)))
3652 (custom-add-see-also widget
3653 (make-string (* custom-buffer-indent level
)
3656 (message "Creating group...")
3657 (let* ((members (custom-sort-items members
3658 custom-buffer-sort-alphabetically
3659 custom-buffer-order-groups
))
3660 (prefixes (widget-get widget
:custom-prefixes
))
3661 (custom-prefix-list (custom-prefix-add symbol prefixes
))
3662 (length (length members
))
3664 (children (mapcar (lambda (entry)
3665 (widget-insert "\n")
3667 Creating group members... %2d%%"
3668 (/ (* 100.0 count
) length
))
3669 (setq count
(1+ count
))
3671 (widget-create-child-and-convert
3672 widget
(nth 1 entry
)
3674 :tag
(custom-unlispify-tag-name
3676 :custom-prefixes custom-prefix-list
3677 :custom-level
(1+ level
)
3678 :value
(nth 0 entry
))
3679 (unless (eq (preceding-char) ?
\n)
3680 (widget-insert "\n"))))
3682 (message "Creating group magic...")
3683 (mapc 'custom-magic-reset children
)
3684 (message "Creating group state...")
3685 (widget-put widget
:children children
)
3686 (custom-group-state-update widget
)
3687 (message "Creating group... done"))
3690 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3691 (insert "\\- " (widget-get widget
:tag
) " group end ")
3692 (insert-char ?-
(- 75 (current-column) (* custom-buffer-indent level
)))
3695 (defvar custom-group-menu
3696 '(("Set for Current Session" custom-group-set
3698 (eq (widget-get widget
:custom-state
) 'modified
)))
3699 ("Save for Future Sessions" custom-group-save
3701 (memq (widget-get widget
:custom-state
) '(modified set
))))
3702 ("Reset to Current" custom-group-reset-current
3704 (memq (widget-get widget
:custom-state
) '(modified))))
3705 ("Reset to Saved" custom-group-reset-saved
3707 (memq (widget-get widget
:custom-state
) '(modified set
))))
3708 ("Reset to standard setting" custom-group-reset-standard
3710 (memq (widget-get widget
:custom-state
) '(modified set saved
)))))
3711 "Alist of actions for the `custom-group' widget.
3712 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3713 the menu entry, ACTION is the function to call on the widget when the
3714 menu is selected, and FILTER is a predicate which takes a `custom-group'
3715 widget as an argument, and returns non-nil if ACTION is valid on that
3716 widget. If FILTER is nil, ACTION is always valid.")
3718 (defun custom-group-action (widget &optional event
)
3719 "Show the menu for `custom-group' WIDGET.
3720 Optional EVENT is the location for the menu."
3721 (if (eq (widget-get widget
:custom-state
) 'hidden
)
3722 (custom-toggle-hide widget
)
3723 (let* ((completion-ignore-case t
)
3724 (answer (widget-choose (concat "Operation on "
3725 (custom-unlispify-tag-name
3726 (widget-get widget
:value
)))
3727 (custom-menu-filter custom-group-menu
3731 (funcall answer widget
)))))
3733 (defun custom-group-set (widget)
3734 "Set changes in all modified group members."
3735 (let ((children (widget-get widget
:children
)))
3736 (mapc (lambda (child)
3737 (when (eq (widget-get child
:custom-state
) 'modified
)
3738 (widget-apply child
:custom-set
)))
3741 (defun custom-group-save (widget)
3742 "Save all modified group members."
3743 (let ((children (widget-get widget
:children
)))
3744 (mapc (lambda (child)
3745 (when (memq (widget-get child
:custom-state
) '(modified set
))
3746 (widget-apply child
:custom-save
)))
3749 (defun custom-group-reset-current (widget)
3750 "Reset all modified group members."
3751 (let ((children (widget-get widget
:children
)))
3752 (mapc (lambda (child)
3753 (when (eq (widget-get child
:custom-state
) 'modified
)
3754 (widget-apply child
:custom-reset-current
)))
3757 (defun custom-group-reset-saved (widget)
3758 "Reset all modified or set group members."
3759 (let ((children (widget-get widget
:children
)))
3760 (mapc (lambda (child)
3761 (when (memq (widget-get child
:custom-state
) '(modified set
))
3762 (widget-apply child
:custom-reset-saved
)))
3765 (defun custom-group-reset-standard (widget)
3766 "Reset all modified, set, or saved group members."
3767 (let ((children (widget-get widget
:children
)))
3768 (mapc (lambda (child)
3769 (when (memq (widget-get child
:custom-state
)
3770 '(modified set saved
))
3771 (widget-apply child
:custom-reset-standard
)))
3774 (defun custom-group-state-update (widget)
3776 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
3777 (let* ((children (widget-get widget
:children
))
3778 (states (mapcar (lambda (child)
3779 (widget-get child
:custom-state
))
3781 (magics custom-magic-alist
)
3784 (let ((magic (car (car magics
))))
3785 (if (and (not (eq magic
'hidden
))
3786 (memq magic states
))
3789 (setq magics
(cdr magics
)))))
3790 (widget-put widget
:custom-state found
)))
3791 (custom-magic-reset widget
))
3793 ;;; The `custom-save-all' Function.
3795 (defcustom custom-file nil
3796 "File used for storing customization information.
3797 The default is nil, which means to use your init file
3798 as specified by `user-init-file'. If the value is not nil,
3799 it should be an absolute file name.
3801 You can set this option through Custom, if you carefully read the
3802 last paragraph below. However, usually it is simpler to write
3803 something like the following in your init file:
3805 \(setq custom-file \"~/.emacs-custom.el\")
3808 Note that both lines are necessary: the first line tells Custom to
3809 save all customizations in this file, but does not load it.
3811 When you change this variable outside Custom, look in the
3812 previous custom file \(usually your init file) for the
3813 forms `(custom-set-variables ...)' and `(custom-set-faces ...)',
3814 and copy them (whichever ones you find) to the new custom file.
3815 This will preserve your existing customizations.
3817 If you save this option using Custom, Custom will write all
3818 currently saved customizations, including the new one for this
3819 option itself, into the file you specify, overwriting any
3820 `custom-set-variables' and `custom-set-faces' forms already
3821 present in that file. It will not delete any customizations from
3822 the old custom file. You should do that manually if that is what you
3823 want. You also have to put something like `\(load \"CUSTOM-FILE\")
3824 in your init file, where CUSTOM-FILE is the actual name of the
3825 file. Otherwise, Emacs will not load the file when it starts up,
3826 and hence will not set `custom-file' to that file either."
3827 :type
'(choice (const :tag
"Your Emacs init file" nil
)
3828 (file :format
"%t:%v%d"
3830 "Please read entire docstring below before setting \
3831 this through Custom.
3832 Click om \"More\" \(or position point there and press RETURN)
3833 if only the first line of the docstring is shown."))
3836 (defun custom-file ()
3837 "Return the file name for saving customizations."
3840 (let ((user-init-file user-init-file
)
3842 (if (eq system-type
'ms-dos
) "~/_emacs" "~/.emacs")))
3843 (when (null user-init-file
)
3844 (if (or (file-exists-p default-init-file
)
3845 (and (eq system-type
'windows-nt
)
3846 (file-exists-p "~/_emacs")))
3847 ;; Started with -q, i.e. the file containing
3848 ;; Custom settings hasn't been read. Saving
3849 ;; settings there would overwrite other settings.
3850 (error "Saving settings from \"emacs -q\" would overwrite existing customizations"))
3851 (setq user-init-file default-init-file
))
3854 (defun custom-save-delete (symbol)
3855 "Visit `custom-file' and delete all calls to SYMBOL from it.
3856 Leave point at the old location of the first such call,
3857 or (if there were none) at the end of the buffer."
3858 (let ((default-major-mode 'emacs-lisp-mode
))
3859 (set-buffer (find-file-noselect (custom-file))))
3860 (goto-char (point-min))
3861 ;; Skip all whitespace and comments.
3862 (while (forward-comment 1))
3864 (save-excursion (forward-sexp (buffer-size)))) ; Test for scan errors.
3867 (while t
;; We exit this loop only via throw.
3868 ;; Skip all whitespace and comments.
3869 (while (forward-comment 1))
3870 (let ((start (point))
3871 (sexp (condition-case nil
3872 (read (current-buffer))
3873 (end-of-file (throw 'found nil
)))))
3874 (when (and (listp sexp
)
3875 (eq (car sexp
) symbol
))
3876 (delete-region start
(point))
3878 (setq first
(point)))))))
3881 ;; Move in front of local variables, otherwise long Custom
3882 ;; entries would make them ineffective.
3883 (let ((pos (point-max))
3884 (case-fold-search t
))
3886 (goto-char (point-max))
3887 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
3889 (when (search-forward "Local Variables:" nil t
)
3890 (setq pos
(line-beginning-position))))
3893 (defun custom-save-variables ()
3894 "Save all customized variables in `custom-file'."
3896 (custom-save-delete 'custom-load-themes
)
3897 (custom-save-delete 'custom-reset-variables
)
3898 (custom-save-delete 'custom-set-variables
)
3899 (custom-save-loaded-themes)
3900 (custom-save-resets 'theme-value
'custom-reset-variables nil
)
3901 (let ((standard-output (current-buffer))
3902 (saved-list (make-list 1 0))
3904 ;; First create a sorted list of saved variables.
3907 (if (get symbol
'saved-value
)
3908 (nconc saved-list
(list symbol
)))))
3909 (setq saved-list
(sort (cdr saved-list
) 'string
<))
3912 (princ "(custom-set-variables
3913 ;; custom-set-variables was added by Custom.
3914 ;; If you edit it by hand, you could mess it up, so be careful.
3915 ;; Your init file should contain only one such instance.
3916 ;; If there is more than one, they won't work right.\n")
3917 (dolist (symbol saved-list
)
3918 (let ((spec (car-safe (get symbol
'theme-value
)))
3919 (value (get symbol
'saved-value
))
3920 (requests (get symbol
'custom-requests
))
3921 (now (not (or (custom-variable-p symbol
)
3922 (and (not (boundp symbol
))
3923 (not (eq (get symbol
'force-value
)
3925 (comment (get symbol
'saved-variable-comment
)))
3926 ;; Check `requests'.
3927 (dolist (request requests
)
3928 (when (and (symbolp request
) (not (featurep request
)))
3929 (message "Unknown requested feature: %s" request
)
3930 (setq requests
(delq request requests
))))
3932 (eq (nth 0 spec
) 'user
)
3933 (eq (nth 1 spec
) 'set
))
3935 (and (null spec
) (get symbol
'saved-value
)))
3942 (when (or now requests comment
)
3945 (when (or requests comment
)
3955 (unless (looking-at "\n")
3958 (defun custom-save-faces ()
3959 "Save all customized faces in `custom-file'."
3961 (custom-save-delete 'custom-reset-faces
)
3962 (custom-save-delete 'custom-set-faces
)
3963 (custom-save-resets 'theme-face
'custom-reset-faces
'(default))
3964 (let ((standard-output (current-buffer))
3965 (saved-list (make-list 1 0))
3967 ;; First create a sorted list of saved faces.
3970 (if (get symbol
'saved-face
)
3971 (nconc saved-list
(list symbol
)))))
3972 (setq saved-list
(sort (cdr saved-list
) 'string
<))
3973 ;; The default face must be first, since it affects the others.
3974 (if (memq 'default saved-list
)
3975 (setq saved-list
(cons 'default
(delq 'default saved-list
))))
3978 (princ "(custom-set-faces
3979 ;; custom-set-faces was added by Custom.
3980 ;; If you edit it by hand, you could mess it up, so be careful.
3981 ;; Your init file should contain only one such instance.
3982 ;; If there is more than one, they won't work right.\n")
3983 (dolist (symbol saved-list
)
3984 (let ((spec (car-safe (get symbol
'theme-face
)))
3985 (value (get symbol
'saved-face
))
3986 (now (not (or (get symbol
'face-defface-spec
)
3987 (and (not (custom-facep symbol
))
3988 (not (get symbol
'force-face
))))))
3989 (comment (get symbol
'saved-face-comment
)))
3991 (eq (nth 0 spec
) 'user
)
3992 (eq (nth 1 spec
) 'set
))
3994 (and (null spec
) (get symbol
'saved-face
)))
3995 ;; Don't print default face here.
4002 (when (or now comment
)
4012 (unless (looking-at "\n")
4015 (defun custom-save-resets (property setter special
)
4016 (let (started-writing ignored-special
)
4017 ;; (custom-save-delete setter) Done by caller
4018 (let ((standard-output (current-buffer))
4019 (mapper `(lambda (object)
4020 (let ((spec (car-safe (get object
(quote ,property
)))))
4021 (when (and (not (memq object ignored-special
))
4022 (eq (nth 0 spec
) 'user
)
4023 (eq (nth 1 spec
) 'reset
))
4024 ;; Do not write reset statements unless necessary.
4025 (unless started-writing
4026 (setq started-writing t
)
4030 (princ (quote ,setter
))
4034 (prin1 (nth 3 spec
))
4036 (mapc mapper special
)
4037 (setq ignored-special special
)
4039 (when started-writing
4042 (defun custom-save-loaded-themes ()
4043 (let ((themes (reverse (get 'user
'theme-loads-themes
)))
4044 (standard-output (current-buffer)))
4046 (unless (bolp) (princ "\n"))
4047 (princ "(custom-load-themes")
4048 (mapc (lambda (theme)
4050 (prin1 theme
)) themes
)
4054 (defun customize-save-customized ()
4055 "Save all user options which have been set in this session."
4057 (mapatoms (lambda (symbol)
4058 (let ((face (get symbol
'customized-face
))
4059 (value (get symbol
'customized-value
))
4060 (face-comment (get symbol
'customized-face-comment
))
4062 (get symbol
'customized-variable-comment
)))
4064 (put symbol
'saved-face face
)
4065 (custom-push-theme 'theme-face symbol
'user
'set value
)
4066 (put symbol
'customized-face nil
))
4068 (put symbol
'saved-value value
)
4069 (custom-push-theme 'theme-value symbol
'user
'set value
)
4070 (put symbol
'customized-value nil
))
4071 (when variable-comment
4072 (put symbol
'saved-variable-comment variable-comment
)
4073 (put symbol
'customized-variable-comment nil
))
4075 (put symbol
'saved-face-comment face-comment
)
4076 (put symbol
'customized-face-comment nil
)))))
4077 ;; We really should update all custom buffers here.
4081 (defun custom-save-all ()
4082 "Save all customizations in `custom-file'."
4083 (let ((inhibit-read-only t
))
4084 (custom-save-variables)
4087 (let ((default-major-mode nil
))
4088 (set-buffer (find-file-noselect (custom-file))))
4089 (let ((file-precious-flag t
))
4092 ;;; The Customize Menu.
4096 (defcustom custom-menu-nesting
2
4097 "Maximum nesting in custom menus."
4099 :group
'custom-menu
)
4101 (defun custom-face-menu-create (widget symbol
)
4102 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
4103 (vector (custom-unlispify-menu-entry symbol
)
4104 `(customize-face ',symbol
)
4107 (defun custom-variable-menu-create (widget symbol
)
4108 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
4109 (let ((type (get symbol
'custom-type
)))
4110 (unless (listp type
)
4111 (setq type
(list type
)))
4112 (if (and type
(widget-get type
:custom-menu
))
4113 (widget-apply type
:custom-menu symbol
)
4114 (vector (custom-unlispify-menu-entry symbol
)
4115 `(customize-variable ',symbol
)
4118 ;; Add checkboxes to boolean variable entries.
4119 (widget-put (get 'boolean
'widget-type
)
4120 :custom-menu
(lambda (widget symbol
)
4121 (vector (custom-unlispify-menu-entry symbol
)
4122 `(customize-variable ',symbol
)
4124 ':selected symbol
)))
4126 (defun custom-group-menu-create (widget symbol
)
4127 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
4128 `( ,(custom-unlispify-menu-entry symbol t
)
4129 :filter
(lambda (&rest junk
)
4130 (let ((menu (custom-menu-create ',symbol
)))
4131 (if (consp menu
) (cdr menu
) menu
)))))
4134 (defun custom-menu-create (symbol)
4135 "Create menu for customization group SYMBOL.
4136 The menu is in a format applicable to `easy-menu-define'."
4137 (let* ((item (vector (custom-unlispify-menu-entry symbol
)
4138 `(customize-group ',symbol
)
4140 (if (and (or (not (boundp 'custom-menu-nesting
))
4141 (>= custom-menu-nesting
0))
4143 (custom-load-symbol symbol
)
4144 (< (length (get symbol
'custom-group
)) widget-menu-max-size
)))
4145 (let ((custom-prefix-list (custom-prefix-add symbol
4146 custom-prefix-list
))
4147 (members (custom-sort-items (get symbol
'custom-group
)
4148 custom-menu-sort-alphabetically
4149 custom-menu-order-groups
)))
4150 `(,(custom-unlispify-menu-entry symbol t
)
4153 ,@(mapcar (lambda (entry)
4154 (widget-apply (if (listp (nth 1 entry
))
4156 (list (nth 1 entry
)))
4157 :custom-menu
(nth 0 entry
)))
4162 (defun customize-menu-create (symbol &optional name
)
4163 "Return a customize menu for customization group SYMBOL.
4164 If optional NAME is given, use that as the name of the menu.
4165 Otherwise the menu will be named `Customize'.
4166 The format is suitable for use with `easy-menu-define'."
4168 (setq name
"Customize"))
4170 :filter
(lambda (&rest junk
)
4171 (let ((menu (custom-menu-create ',symbol
)))
4172 (if (consp menu
) (cdr menu
) menu
)))))
4174 ;;; The Custom Mode.
4176 (defvar custom-mode-map
4177 ;; This keymap should be dense, but a dense keymap would prevent inheriting
4178 ;; "\r" bindings from the parent map.
4179 ;; Actually, this misfeature of dense keymaps was fixed on 2001-11-26.
4180 (let ((map (make-keymap)))
4181 (set-keymap-parent map widget-keymap
)
4182 (suppress-keymap map
)
4183 (define-key map
" " 'scroll-up
)
4184 (define-key map
"\177" 'scroll-down
)
4185 (define-key map
"\C-x\C-s" 'Custom-save
)
4186 (define-key map
"q" 'Custom-buffer-done
)
4187 (define-key map
"u" 'Custom-goto-parent
)
4188 (define-key map
"n" 'widget-forward
)
4189 (define-key map
"p" 'widget-backward
)
4190 (define-key map
[mouse-1
] 'Custom-move-and-invoke
)
4192 "Keymap for `custom-mode'.")
4194 (defun Custom-move-and-invoke (event)
4195 "Move to where you click, and if it is an active field, invoke it."
4197 (mouse-set-point event
)
4198 (if (widget-event-point event
)
4199 (let* ((pos (widget-event-point event
))
4200 (button (get-char-property pos
'button
)))
4202 (widget-button-click event
)))))
4204 (easy-menu-define Custom-mode-menu
4206 "Menu used in customization buffers."
4208 ,(customize-menu-create 'customize
)
4209 ["Set" Custom-set t
]
4210 ["Save" Custom-save t
]
4211 ["Reset to Current" Custom-reset-current t
]
4212 ["Reset to Saved" Custom-reset-saved t
]
4213 ["Reset to Standard Settings" Custom-reset-standard t
]
4214 ["Info" (Info-goto-node "(emacs)Easy Customization") t
]))
4216 (defun Custom-goto-parent ()
4217 "Go to the parent group listed at the top of this buffer.
4218 If several parents are listed, go to the first of them."
4221 (goto-char (point-min))
4222 (if (search-forward "\nGo to parent group: " nil t
)
4223 (let* ((button (get-char-property (point) 'button
))
4224 (parent (downcase (widget-get button
:tag
))))
4225 (customize-group parent
)))))
4227 (defcustom custom-mode-hook nil
4228 "Hook called when entering Custom mode."
4230 :group
'custom-buffer
)
4232 (defun custom-state-buffer-message (widget)
4233 (if (eq (widget-get (widget-get widget
:parent
) :custom-state
) 'modified
)
4234 (message "To install your edits, invoke [State] and choose the Set operation")))
4236 (defun custom-mode ()
4237 "Major mode for editing customization buffers.
4239 The following commands are available:
4241 Move to next button or editable field. \\[widget-forward]
4242 Move to previous button or editable field. \\[widget-backward]
4243 \\<widget-field-keymap>\
4244 Complete content of editable text field. \\[widget-complete]
4245 \\<custom-mode-map>\
4246 Invoke button under the mouse pointer. \\[Custom-move-and-invoke]
4247 Invoke button under point. \\[widget-button-press]
4248 Set all modifications. \\[Custom-set]
4249 Make all modifications default. \\[Custom-save]
4250 Reset all modified options. \\[Custom-reset-current]
4251 Reset all modified or set options. \\[Custom-reset-saved]
4252 Reset all options. \\[Custom-reset-standard]
4254 Entry to this mode calls the value of `custom-mode-hook'
4255 if that value is non-nil."
4256 (kill-all-local-variables)
4257 (setq major-mode
'custom-mode
4259 (use-local-map custom-mode-map
)
4260 (easy-menu-add Custom-mode-menu
)
4261 (make-local-variable 'custom-options
)
4262 (make-local-variable 'custom-local-buffer
)
4263 (make-local-variable 'widget-documentation-face
)
4264 (setq widget-documentation-face
'custom-documentation-face
)
4265 (make-local-variable 'widget-button-face
)
4266 (setq widget-button-face
'custom-button-face
)
4267 (set (make-local-variable 'widget-button-pressed-face
)
4268 'custom-button-pressed-face
)
4269 (set (make-local-variable 'widget-mouse-face
)
4270 'custom-button-pressed-face
) ; buttons `depress' when moused
4271 ;; When possible, use relief for buttons, not bracketing. This test
4272 ;; may not be optimal.
4273 (when custom-raised-buttons
4274 (set (make-local-variable 'widget-push-button-prefix
) "")
4275 (set (make-local-variable 'widget-push-button-suffix
) "")
4276 (set (make-local-variable 'widget-link-prefix
) "")
4277 (set (make-local-variable 'widget-link-suffix
) ""))
4278 (add-hook 'widget-edit-functions
'custom-state-buffer-message nil t
)
4279 (run-mode-hooks 'custom-mode-hook
))
4281 (put 'custom-mode
'mode-class
'special
)
4284 'debug-ignored-errors
4285 "^No user options have changed defaults in recent Emacs versions$")
4291 ;; arch-tag: 64533aa4-1b1a-48c3-8812-f9dc718e8a6f
4292 ;;; cus-edit.el ends here