1 ;;; cus-edit.el --- tools for customizing Emacs and Lisp packages
3 ;; Copyright (C) 1996, 1997, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007 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 3, 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., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, 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 Saved 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. Most
125 ;; standard interactive Custom commands do not let you create a
126 ;; Custom buffer containing such variables. However, such Custom
127 ;; buffers can be created, for instance, by calling
128 ;; `customize-apropos' with a prefix arg or by calling
129 ;; `customize-option' non-interactively.
133 ;; There is no widget value.
137 ;; The widget value is not valid member of the :type specified for the
145 (defvar custom-versions-load-alist
) ; from cus-load
146 (defvar recentf-exclude
) ; from recentf.el
156 (put 'custom-define-hook
'custom-type
'hook
)
157 (put 'custom-define-hook
'standard-value
'(nil))
158 (custom-add-to-group 'customize
'custom-define-hook
'custom-variable
)
160 ;;; Customization Groups.
163 "Customization of the One True Editor."
164 :link
'(custom-manual "(emacs)Top"))
166 ;; Most of these groups are stolen from `finder.el',
167 (defgroup editing nil
168 "Basic text editing facilities."
172 "Abbreviation handling, typing shortcuts, macros."
176 (defgroup matching nil
177 "Various sorts of searching and matching."
180 (defgroup emulations nil
181 "Emulations of other editors."
182 :link
'(custom-manual "(emacs)Emulation")
189 (defgroup outlines nil
190 "Support for hierarchical outlining."
193 (defgroup external nil
194 "Interfacing to external utilities."
197 (defgroup processes nil
198 "Process, subshell, compilation, and job control support."
202 (defgroup convenience nil
203 "Convenience features for faster editing."
206 (defgroup programming nil
207 "Support for programming in other languages."
210 (defgroup languages nil
211 "Specialized modes for editing programming languages."
215 "Lisp support, including Emacs Lisp."
216 :link
'(custom-group-link :tag
"Font Lock Faces group" font-lock-faces
)
221 "Support for the C language and related languages."
222 :link
'(custom-group-link :tag
"Font Lock Faces group" font-lock-faces
)
223 :link
'(custom-manual "(ccmode)")
231 "Support for object-oriented programming."
234 (defgroup applications nil
235 "Applications written in Emacs."
238 (defgroup calendar nil
239 "Calendar and time management support."
240 :group
'applications
)
243 "Modes for electronic-mail handling."
244 :group
'applications
)
247 "Support for netnews reading and posting."
248 :link
'(custom-manual "(gnus)")
249 :group
'applications
)
252 "Games, jokes and amusements."
253 :group
'applications
)
255 (defgroup development nil
256 "Support for further development of Emacs."
260 "Support for Emacs documentation."
263 (defgroup extensions nil
264 "Emacs Lisp language extensions."
267 (defgroup internal nil
268 "Code for Emacs internals, build process, defaults."
272 "Maintenance aids for the Emacs development group."
276 (defgroup environment nil
277 "Fitting Emacs with its environment."
281 "Communications, networking, remote access to files."
285 (defgroup hardware nil
286 "Support for interfacing with exotic hardware."
289 (defgroup terminals nil
290 "Support for terminal types."
294 "Front-ends/assistants for, or emulators of, UNIX features."
298 "Support code for vms."
302 "Internationalization and alternate character-set support."
303 :link
'(custom-manual "(emacs)International")
308 "The X Window system."
312 "Support for Emacs frames and window systems."
316 "Support editing files of data."
320 "Support editing files."
328 "Code related to the TeX formatter."
329 :link
'(custom-group-link :tag
"Font Lock Faces group" font-lock-faces
)
333 "Support for multiple fonts."
336 (defgroup hypermedia nil
337 "Support for links between text or other media types."
341 "Support for on-line help systems."
344 (defgroup multimedia nil
345 "Non-textual support, specifically images and sound."
349 "Code local to your site."
352 (defgroup customize
'((widgets custom-group
))
353 "Customization of the Customization support."
357 (defgroup custom-faces nil
358 "Faces used by customize."
362 (defgroup custom-browse nil
363 "Control customize browser."
367 (defgroup custom-buffer nil
368 "Control customize buffers."
372 (defgroup custom-menu nil
373 "Control customize menus."
377 (defgroup abbrev-mode nil
378 "Word abbreviations mode."
379 :link
'(custom-manual "(emacs)Abbrevs")
383 "Storage allocation and gc for GNU Emacs Lisp interpreter."
384 :tag
"Storage Allocation"
388 "Undoing changes in buffers."
389 :link
'(custom-manual "(emacs)Undo")
392 (defgroup mode-line nil
393 "Content of the modeline."
396 (defgroup editing-basics nil
397 "Most basic editing facilities."
400 (defgroup display nil
401 "How characters are displayed in buffers."
404 (defgroup execute nil
405 "Executing external commands."
408 (defgroup installation nil
409 "The Emacs installation."
417 "Internal Emacs limits."
421 "Debugging Emacs itself."
424 (defgroup minibuffer nil
425 "Controlling the behavior of the minibuffer."
426 :link
'(custom-manual "(emacs)Minibuffer")
429 (defgroup keyboard nil
430 "Input from the keyboard."
434 "Input from the mouse."
438 "Input from the menus."
442 "Handling data from drag and drop."
445 (defgroup auto-save nil
446 "Preventing accidental loss of data."
449 (defgroup processes-basics nil
450 "Basic stuff dealing with processes."
454 "MULE Emacs internationalization."
457 (defgroup windows nil
458 "Windows within a frame."
459 :link
'(custom-manual "(emacs)Windows")
463 "Mac specific features."
464 :link
'(custom-manual "(emacs)Mac OS")
469 ;;; Custom mode keymaps
471 (defvar custom-mode-map
472 ;; This keymap should be dense, but a dense keymap would prevent inheriting
473 ;; "\r" bindings from the parent map.
474 ;; Actually, this misfeature of dense keymaps was fixed on 2001-11-26.
475 (let ((map (make-keymap)))
476 (set-keymap-parent map widget-keymap
)
477 (define-key map
[remap self-insert-command
] 'Custom-no-edit
)
478 (define-key map
"\^m" 'Custom-newline
)
479 (define-key map
" " 'scroll-up
)
480 (define-key map
"\177" 'scroll-down
)
481 (define-key map
"\C-c\C-c" 'Custom-set
)
482 (define-key map
"\C-x\C-s" 'Custom-save
)
483 (define-key map
"q" 'Custom-buffer-done
)
484 (define-key map
"u" 'Custom-goto-parent
)
485 (define-key map
"n" 'widget-forward
)
486 (define-key map
"p" 'widget-backward
)
488 "Keymap for `custom-mode'.")
490 (defvar custom-mode-link-map
491 (let ((map (make-keymap)))
492 (set-keymap-parent map custom-mode-map
)
493 (define-key map
[down-mouse-2
] nil
)
494 (define-key map
[down-mouse-1
] 'mouse-drag-region
)
495 (define-key map
[mouse-2
] 'widget-move-and-invoke
)
497 "Local keymap for links in `custom-mode'.")
502 (defun custom-split-regexp-maybe (regexp)
503 "If REGEXP is a string, split it to a list at `\\|'.
504 You can get the original back from the result with:
505 (mapconcat 'identity result \"\\|\")
507 IF REGEXP is not a string, return it unchanged."
509 (split-string regexp
"\\\\|")
512 (defun custom-variable-prompt ()
513 "Prompt for a custom variable, defaulting to the variable at point.
514 Return a list suitable for use in `interactive'."
515 (let* ((v (variable-at-point))
516 (default (and (symbolp v
) (custom-variable-p v
) (symbol-name v
)))
517 (enable-recursive-minibuffers t
)
519 (setq val
(completing-read
520 (if default
(format "Customize variable (default %s): " default
)
521 "Customize variable: ")
522 obarray
'custom-variable-p t nil nil default
))
523 (list (if (equal val
"")
524 (if (symbolp v
) v nil
)
527 (defun custom-menu-filter (menu widget
)
528 "Convert MENU to the form used by `widget-choose'.
529 MENU should be in the same format as `custom-variable-menu'.
530 WIDGET is the widget to apply the filter entries of MENU on."
532 current name action filter
)
534 (setq current
(car menu
)
536 action
(nth 1 current
)
537 filter
(nth 2 current
)
539 (if (or (null filter
) (funcall filter widget
))
540 (push (cons name action
) result
)
546 (defvar custom-prefix-list nil
547 "List of prefixes that should be ignored by `custom-unlispify'.")
549 (defcustom custom-unlispify-menu-entries t
550 "Display menu entries as words instead of symbols if non-nil."
554 (defcustom custom-unlispify-remove-prefixes nil
555 "Non-nil means remove group prefixes from option names in buffer."
557 :group
'custom-buffer
560 (defun custom-unlispify-menu-entry (symbol &optional no-suffix
)
561 "Convert SYMBOL into a menu entry."
562 (cond ((not custom-unlispify-menu-entries
)
563 (symbol-name symbol
))
564 ((get symbol
'custom-tag
)
566 (get symbol
'custom-tag
)
567 (concat (get symbol
'custom-tag
) "...")))
569 (with-current-buffer (get-buffer-create " *Custom-Work*")
571 (princ symbol
(current-buffer))
572 (goto-char (point-min))
573 ;; FIXME: Boolean variables are not predicates, so they shouldn't
574 ;; end with `-p'. -stef
575 ;; (when (and (eq (get symbol 'custom-type) 'boolean)
576 ;; (re-search-forward "-p\\'" nil t))
577 ;; (replace-match "" t t)
578 ;; (goto-char (point-min)))
579 (if custom-unlispify-remove-prefixes
580 (let ((prefixes custom-prefix-list
)
583 (setq prefix
(car prefixes
))
584 (if (search-forward prefix
(+ (point) (length prefix
)) t
)
587 (delete-region (point-min) (point)))
588 (setq prefixes
(cdr prefixes
))))))
589 (subst-char-in-region (point-min) (point-max) ?- ?\ t
)
590 (capitalize-region (point-min) (point-max))
592 (goto-char (point-max))
596 (defcustom custom-unlispify-tag-names t
597 "Display tag names as words instead of symbols if non-nil."
598 :group
'custom-buffer
601 (defun custom-unlispify-tag-name (symbol)
602 "Convert SYMBOL into a menu entry."
603 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names
))
604 (custom-unlispify-menu-entry symbol t
)))
606 (defun custom-prefix-add (symbol prefixes
)
607 "Add SYMBOL to list of ignored PREFIXES."
608 (cons (or (get symbol
'custom-prefix
)
609 (concat (symbol-name symbol
) "-"))
614 (defcustom custom-guess-name-alist
620 ("-function\\'" function
)
621 ("-functions\\'" (repeat function
))
622 ("-list\\'" (repeat sexp
))
623 ("-alist\\'" (repeat (cons sexp sexp
))))
624 "Alist of (MATCH TYPE).
626 MATCH should be a regexp matching the name of a symbol, and TYPE should
627 be a widget suitable for editing the value of that symbol. The TYPE
628 of the first entry where MATCH matches the name of the symbol will be
631 This is used for guessing the type of variables not declared with
633 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
634 :group
'custom-buffer
)
636 (defcustom custom-guess-doc-alist
637 '(("\\`\\*?Non-nil " boolean
))
638 "Alist of (MATCH TYPE).
640 MATCH should be a regexp matching a documentation string, and TYPE
641 should be a widget suitable for editing the value of a variable with
642 that documentation string. The TYPE of the first entry where MATCH
643 matches the name of the symbol will be used.
645 This is used for guessing the type of variables not declared with
647 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
648 :group
'custom-buffer
)
650 (defun custom-guess-type (symbol)
651 "Guess a widget suitable for editing the value of SYMBOL.
652 This is done by matching SYMBOL with `custom-guess-name-alist' and
653 if that fails, the doc string with `custom-guess-doc-alist'."
654 (let ((name (symbol-name symbol
))
655 (names custom-guess-name-alist
)
658 (setq current
(car names
)
660 (when (string-match (nth 0 current
) name
)
661 (setq found
(nth 1 current
)
664 (let ((doc (documentation-property symbol
'variable-documentation
))
665 (docs custom-guess-doc-alist
))
668 (setq current
(car docs
)
670 (when (string-match (nth 0 current
) doc
)
671 (setq found
(nth 1 current
)
678 (defcustom custom-browse-sort-alphabetically nil
679 "If non-nil, sort customization group alphabetically in `custom-browse'."
681 :group
'custom-browse
)
683 (defcustom custom-browse-order-groups nil
684 "If non-nil, order group members within each customization group.
685 If `first', order groups before non-groups.
686 If `last', order groups after non-groups."
687 :type
'(choice (const first
)
689 (const :tag
"none" nil
))
690 :group
'custom-browse
)
692 (defcustom custom-browse-only-groups nil
693 "If non-nil, show group members only within each customization group."
695 :group
'custom-browse
)
698 (defcustom custom-buffer-sort-alphabetically nil
699 "If non-nil, sort each customization group alphabetically in Custom buffer."
701 :group
'custom-buffer
)
703 (defcustom custom-buffer-order-groups
'last
704 "If non-nil, order group members within each customization group.
705 If `first', order groups before non-groups.
706 If `last', order groups after non-groups."
707 :type
'(choice (const first
)
709 (const :tag
"none" nil
))
710 :group
'custom-buffer
)
713 (defcustom custom-menu-sort-alphabetically nil
714 "If non-nil, sort each customization group alphabetically in menus."
718 (defcustom custom-menu-order-groups
'first
719 "If non-nil, order group members within each customization group.
720 If `first', order groups before non-groups.
721 If `last', order groups after non-groups."
722 :type
'(choice (const first
)
724 (const :tag
"none" nil
))
727 ;;;###autoload (add-hook 'same-window-regexps "\\`\\*Customiz.*\\*\\'")
729 (defun custom-sort-items (items sort-alphabetically order-groups
)
730 "Return a sorted copy of ITEMS.
731 ITEMS should be a `custom-group' property.
732 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
733 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
734 groups after non-groups, if nil do not order groups at all."
735 (sort (copy-sequence items
)
737 (let ((typea (nth 1 a
)) (typeb (nth 1 b
))
738 (namea (nth 0 a
)) (nameb (nth 0 b
)))
739 (cond ((not order-groups
)
740 ;; Since we don't care about A and B order, maybe sort.
741 (when sort-alphabetically
742 (string-lessp namea nameb
)))
743 ((eq typea
'custom-group
)
744 ;; If B is also a group, maybe sort. Otherwise, order A and B.
745 (if (eq typeb
'custom-group
)
746 (when sort-alphabetically
747 (string-lessp namea nameb
))
748 (eq order-groups
'first
)))
749 ((eq typeb
'custom-group
)
750 ;; Since A cannot be a group, order A and B.
751 (eq order-groups
'last
))
753 ;; Since A and B cannot be groups, sort.
754 (string-lessp namea nameb
)))))))
756 ;;; Custom Mode Commands.
758 ;; This variable is used by `custom-tool-bar-map', or directly by
759 ;; `custom-buffer-create-internal' if the toolbar is not present and
760 ;; `custom-buffer-verbose-help' is non-nil.
762 (defvar custom-commands
763 '(("Set for current session" Custom-set t
764 "Apply all settings in this buffer to the current session"
766 ("Save for future sessions" Custom-save
767 (or custom-file user-init-file
)
768 "Apply all settings in this buffer and save them for future Emacs sessions."
770 ("Undo edits" Custom-reset-current t
771 "Restore all settings in this buffer to reflect their current values."
773 ("Reset to saved" Custom-reset-saved t
774 "Restore all settings in this buffer to their saved values (if any)."
776 ("Erase customizations" Custom-reset-standard
777 (or custom-file user-init-file
)
778 "Un-customize all settings in this buffer and save them with standard values."
780 ("Help for Customize" Custom-help t
781 "Get help for using Customize."
783 ("Exit" Custom-buffer-done t
"Exit Customize." "exit")))
785 (defun Custom-help ()
786 "Read the node on Easy Customization in the Emacs manual."
788 (info "(emacs)Easy Customization"))
790 (defvar custom-reset-menu
791 '(("Undo Edits" . Custom-reset-current
)
792 ("Reset to Saved" . Custom-reset-saved
)
793 ("Erase Customizations (use standard values)" . Custom-reset-standard
))
794 "Alist of actions for the `Reset' button.
795 The key is a string containing the name of the action, the value is a
796 Lisp function taking the widget as an element which will be called
797 when the action is chosen.")
799 (defvar custom-options nil
800 "Customization widgets in the current buffer.")
802 (defun custom-command-apply (fun query
&optional strong-query
)
803 "Call function FUN on all widgets in `custom-options'.
804 If there is more than one widget, ask user for confirmation using
805 the query string QUERY, using `y-or-n-p' if STRONG-QUERY is nil,
806 and `yes-or-no-p' otherwise."
807 (if (or (and (= 1 (length custom-options
))
808 (memq (widget-type (car custom-options
))
809 '(custom-variable custom-face
)))
810 (funcall (if strong-query
'yes-or-no-p
'y-or-n-p
) query
))
811 (progn (mapc fun custom-options
) t
)
815 (defun Custom-set (&rest ignore
)
816 "Set the current value of all edited settings in the buffer."
818 (custom-command-apply
820 (when (eq (widget-get child
:custom-state
) 'modified
)
821 (widget-apply child
:custom-set
)))
822 "Set all values according to this buffer? "))
824 (defun Custom-save (&rest ignore
)
825 "Set all edited settings, then save all settings that have been set.
826 If a setting was edited and set before, this saves it.
827 If a setting was merely edited before, this sets it then saves it."
829 (if (custom-command-apply
831 (when (memq (widget-get child
:custom-state
)
832 '(modified set changed rogue
))
833 (widget-apply child
:custom-save
)))
834 "Save all settings in this buffer? " t
)
837 (defun custom-reset (widget &optional event
)
838 "Select item from reset menu."
839 (let* ((completion-ignore-case t
)
840 (answer (widget-choose "Reset settings"
846 (defun Custom-reset-current (&rest ignore
)
847 "Reset all edited settings in the buffer to show their current values."
849 (custom-command-apply
851 (if (memq (widget-get widget
:custom-state
) '(modified changed
))
852 (widget-apply widget
:custom-reset-current
)))
853 "Reset all settings' buffer text to show current values? "))
855 (defun Custom-reset-saved (&rest ignore
)
856 "Reset all edited or set settings in the buffer to their saved value.
857 This also shows the saved values in the buffer."
859 (custom-command-apply
861 (if (memq (widget-get widget
:custom-state
) '(modified set changed rogue
))
862 (widget-apply widget
:custom-reset-saved
)))
863 "Reset all settings (current values and buffer text) to saved values? "))
865 (defun Custom-reset-standard (&rest ignore
)
866 "Erase all customization (either current or saved) for the group members.
867 The immediate result is to restore them to their standard values.
868 This operation eliminates any saved values for the group members,
869 making them as if they had never been customized at all."
871 (custom-command-apply
873 (and (or (null (widget-get widget
:custom-standard-value
))
874 (widget-apply widget
:custom-standard-value
))
875 (memq (widget-get widget
:custom-state
)
876 '(modified set changed saved rogue
))
877 (widget-apply widget
:custom-reset-standard
)))
878 "Erase all customizations for settings in this buffer? " t
))
880 ;;; The Customize Commands
882 (defun custom-prompt-variable (prompt-var prompt-val
&optional comment
)
883 "Prompt for a variable and a value and return them as a list.
884 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
885 prompt for the value. The %s escape in PROMPT-VAL is replaced with
886 the name of the variable.
888 If the variable has a `variable-interactive' property, that is used as if
889 it were the arg to `interactive' (which see) to interactively read the value.
891 If the variable has a `custom-type' property, it must be a widget and the
892 `:prompt-value' property of that widget will be used for reading the value.
894 If optional COMMENT argument is non-nil, also prompt for a comment and return
895 it as the third element in the list."
896 (let* ((var (read-variable prompt-var
))
897 (minibuffer-help-form '(describe-variable var
))
899 (let ((prop (get var
'variable-interactive
))
900 (type (get var
'custom-type
))
901 (prompt (format prompt-val var
)))
903 (setq type
(list type
)))
905 ;; Use VAR's `variable-interactive' property
906 ;; as an interactive spec for prompting.
907 (call-interactively `(lambda (arg)
911 (widget-prompt-value type
917 (eval-minibuffer prompt
))))))
920 (read-string "Comment: " (get var
'variable-comment
)))
924 (defun customize-set-value (variable value
&optional comment
)
925 "Set VARIABLE to VALUE, and return VALUE. VALUE is a Lisp object.
927 If VARIABLE has a `variable-interactive' property, that is used as if
928 it were the arg to `interactive' (which see) to interactively read the value.
930 If VARIABLE has a `custom-type' property, it must be a widget and the
931 `:prompt-value' property of that widget will be used for reading the value.
933 If given a prefix (or a COMMENT argument), also prompt for a comment."
934 (interactive (custom-prompt-variable "Set variable: "
938 (cond ((string= comment
"")
939 (put variable
'variable-comment nil
))
941 (put variable
'variable-comment comment
)))
942 (set variable value
))
945 (defun customize-set-variable (variable value
&optional comment
)
946 "Set the default for VARIABLE to VALUE, and return VALUE.
947 VALUE is a Lisp object.
949 If VARIABLE has a `custom-set' property, that is used for setting
950 VARIABLE, otherwise `set-default' is used.
952 If VARIABLE has a `variable-interactive' property, that is used as if
953 it were the arg to `interactive' (which see) to interactively read the value.
955 If VARIABLE has a `custom-type' property, it must be a widget and the
956 `:prompt-value' property of that widget will be used for reading the value.
958 If given a prefix (or a COMMENT argument), also prompt for a comment."
959 (interactive (custom-prompt-variable "Set variable: "
960 "Set customized value for %s to: "
962 (custom-load-symbol variable
)
963 (custom-push-theme 'theme-value variable
'user
'set
(custom-quote value
))
964 (funcall (or (get variable
'custom-set
) 'set-default
) variable value
)
965 (put variable
'customized-value
(list (custom-quote value
)))
966 (cond ((string= comment
"")
967 (put variable
'variable-comment nil
)
968 (put variable
'customized-variable-comment nil
))
970 (put variable
'variable-comment comment
)
971 (put variable
'customized-variable-comment comment
)))
975 (defun customize-save-variable (variable value
&optional comment
)
976 "Set the default for VARIABLE to VALUE, and save it for future sessions.
979 If VARIABLE has a `custom-set' property, that is used for setting
980 VARIABLE, otherwise `set-default' is used.
982 If VARIABLE has a `variable-interactive' property, that is used as if
983 it were the arg to `interactive' (which see) to interactively read the value.
985 If VARIABLE has a `custom-type' property, it must be a widget and the
986 `:prompt-value' property of that widget will be used for reading the value.
988 If given a prefix (or a COMMENT argument), also prompt for a comment."
989 (interactive (custom-prompt-variable "Set and save variable: "
990 "Set and save value for %s as: "
992 (funcall (or (get variable
'custom-set
) 'set-default
) variable value
)
993 (put variable
'saved-value
(list (custom-quote value
)))
994 (custom-push-theme 'theme-value variable
'user
'set
(custom-quote value
))
995 (cond ((string= comment
"")
996 (put variable
'variable-comment nil
)
997 (put variable
'saved-variable-comment nil
))
999 (put variable
'variable-comment comment
)
1000 (put variable
'saved-variable-comment comment
)))
1001 (put variable
'customized-value nil
)
1002 (put variable
'customized-variable-comment nil
)
1008 "Select a customization buffer which you can use to set user options.
1009 User options are structured into \"groups\".
1010 Initially the top-level group `Emacs' and its immediate subgroups
1011 are shown; the contents of those subgroups are initially hidden."
1013 (customize-group 'emacs
))
1016 (defun customize-mode (mode)
1017 "Customize options related to the current major mode.
1018 If a prefix \\[universal-argument] was given (or if the current major mode has no known group),
1019 then prompt for the MODE to customize."
1022 (let ((completion-regexp-list '("-mode\\'"))
1023 (group (custom-group-of-mode major-mode
)))
1024 (if (and group
(not current-prefix-arg
))
1027 (completing-read (if group
1028 (format "Major mode (default %s): " major-mode
)
1031 'custom-group-of-mode
1032 t nil nil
(if group
(symbol-name major-mode
))))))))
1033 (customize-group (custom-group-of-mode mode
)))
1035 (defun customize-read-group ()
1036 (let ((completion-ignore-case t
))
1037 (completing-read "Customize group (default emacs): "
1040 (or (and (get symbol
'custom-loads
)
1041 (not (get symbol
'custom-autoload
)))
1042 (get symbol
'custom-group
)))
1046 (defun customize-group (&optional group
)
1047 "Customize GROUP, which must be a customization group."
1048 (interactive (list (customize-read-group)))
1049 (when (stringp group
)
1050 (if (string-equal "" group
)
1052 (setq group
(intern group
))))
1053 (let ((name (format "*Customize Group: %s*"
1054 (custom-unlispify-tag-name group
))))
1055 (if (get-buffer name
)
1056 (pop-to-buffer name
)
1057 (custom-buffer-create
1058 (list (list group
'custom-group
))
1060 (concat " for group "
1061 (custom-unlispify-tag-name group
))))))
1064 (defun customize-group-other-window (&optional group
)
1065 "Customize GROUP, which must be a customization group, in another window."
1066 (interactive (list (customize-read-group)))
1067 (let ((pop-up-windows t
)
1068 (same-window-buffer-names nil
)
1069 (same-window-regexps nil
))
1070 (customize-group group
)))
1073 (defalias 'customize-variable
'customize-option
)
1076 (defun customize-option (symbol)
1077 "Customize SYMBOL, which must be a user option variable."
1078 (interactive (custom-variable-prompt))
1080 (error "No variable specified"))
1081 (let ((basevar (indirect-variable symbol
)))
1082 (custom-buffer-create (list (list basevar
'custom-variable
))
1083 (format "*Customize Option: %s*"
1084 (custom-unlispify-tag-name basevar
)))
1085 (unless (eq symbol basevar
)
1086 (message "`%s' is an alias for `%s'" symbol basevar
))))
1089 (defalias 'customize-variable-other-window
'customize-option-other-window
)
1092 (defun customize-option-other-window (symbol)
1093 "Customize SYMBOL, which must be a user option variable.
1094 Show the buffer in another window, but don't select it."
1095 (interactive (custom-variable-prompt))
1097 (error "No variable specified"))
1098 (let ((basevar (indirect-variable symbol
)))
1099 (custom-buffer-create-other-window
1100 (list (list basevar
'custom-variable
))
1101 (format "*Customize Option: %s*" (custom-unlispify-tag-name basevar
)))
1102 (unless (eq symbol basevar
)
1103 (message "`%s' is an alias for `%s'" symbol basevar
))))
1105 (defvar customize-changed-options-previous-release
"21.1"
1106 "Version for `customize-changed-options' to refer back to by default.")
1108 ;; Packages will update this variable, so make it available.
1110 (defvar customize-package-emacs-version-alist nil
1111 "Alist mapping versions of a package to Emacs versions.
1112 We use this for packages that have their own names, but are released
1113 as part of Emacs itself.
1115 Each elements looks like this:
1117 (PACKAGE (PVERSION . EVERSION)...)
1119 Here PACKAGE is the name of a package, as a symbol. After
1120 PACKAGE come one or more elements, each associating a
1121 package version PVERSION with the first Emacs version
1122 EVERSION in which it (or a subsequent version of PACKAGE)
1123 was first released. Both PVERSION and EVERSION are strings.
1124 PVERSION should be a string that this package used in
1125 the :package-version keyword for `defcustom', `defgroup',
1128 For example, the MH-E package updates this alist as follows:
1130 (add-to-list 'customize-package-emacs-version-alist
1131 '(MH-E (\"6.0\" . \"22.1\") (\"6.1\" . \"22.1\")
1132 (\"7.0\" . \"22.1\") (\"7.1\" . \"22.1\")
1133 (\"7.2\" . \"22.1\") (\"7.3\" . \"22.1\")
1134 (\"7.4\" . \"22.1\") (\"8.0\" . \"22.1\")))
1136 The value of PACKAGE needs to be unique and it needs to match the
1137 PACKAGE value appearing in the :package-version keyword. Since
1138 the user might see the value in a error message, a good choice is
1139 the official name of the package, such as MH-E or Gnus.")
1142 (defalias 'customize-changed
'customize-changed-options
)
1145 (defun customize-changed-options (since-version)
1146 "Customize all settings whose meanings have changed in Emacs itself.
1147 This includes new user option variables and faces, and new
1148 customization groups, as well as older options and faces whose meanings
1149 or default values have changed since the previous major Emacs release.
1151 With argument SINCE-VERSION (a string), customize all settings
1152 that were added or redefined since that version."
1156 (read-from-minibuffer
1157 (format "Customize options changed, since version (default %s): "
1158 customize-changed-options-previous-release
))))
1159 (if (equal since-version
"")
1160 (setq since-version nil
)
1161 (unless (condition-case nil
1162 (numberp (read since-version
))
1164 (signal 'wrong-type-argument
(list 'numberp since-version
))))
1165 (unless since-version
1166 (setq since-version customize-changed-options-previous-release
))
1168 ;; Load the information for versions since since-version. We use
1169 ;; custom-load-symbol for this.
1170 (put 'custom-versions-load-alist
'custom-loads nil
)
1171 (dolist (elt custom-versions-load-alist
)
1172 (if (customize-version-lessp since-version
(car elt
))
1173 (dolist (load (cdr elt
))
1174 (custom-add-load 'custom-versions-load-alist load
))))
1175 (custom-load-symbol 'custom-versions-load-alist
)
1176 (put 'custom-versions-load-alist
'custom-loads nil
)
1181 (let* ((package-version (get symbol
'custom-package-version
))
1183 (or (and package-version
1184 (customize-package-emacs-version symbol
1186 (get symbol
'custom-version
))))
1188 (when (customize-version-lessp since-version version
)
1189 (if (or (get symbol
'custom-group
)
1190 (get symbol
'group-documentation
))
1191 (push (list symbol
'custom-group
) found
))
1192 (if (custom-variable-p symbol
)
1193 (push (list symbol
'custom-variable
) found
))
1194 (if (custom-facep symbol
)
1195 (push (list symbol
'custom-face
) found
)))))))
1197 (custom-buffer-create (custom-sort-items found t
'first
)
1198 "*Customize Changed Options*")
1199 (error "No user option defaults have been changed since Emacs %s"
1202 (defun customize-package-emacs-version (symbol package-version
)
1203 "Return the Emacs version in which SYMBOL's meaning last changed.
1204 PACKAGE-VERSION has the form (PACKAGE . VERSION). We use
1205 `customize-package-emacs-version-alist' to find the version of
1206 Emacs that is associated with version VERSION of PACKAGE."
1207 (let (package-versions emacs-version
)
1208 ;; Use message instead of error since we want user to be able to
1209 ;; see the rest of the symbols even if a package author has
1210 ;; botched things up.
1211 (cond ((not (listp package-version
))
1212 (message "Invalid package-version value for %s" symbol
))
1213 ((setq package-versions
(assq (car package-version
)
1214 customize-package-emacs-version-alist
))
1216 (cdr (assoc (cdr package-version
) package-versions
)))
1217 (unless emacs-version
1218 (message "%s version %s not found in %s" symbol
1219 (cdr package-version
)
1220 "customize-package-emacs-version-alist")))
1222 (message "Package %s version %s lists no corresponding Emacs version"
1223 (car package-version
)
1224 (cdr package-version
))))
1227 (defun customize-version-lessp (version1 version2
)
1228 ;; Why are the versions strings, and given that they are, why aren't
1229 ;; they converted to numbers and compared as such here? -- fx
1231 ;; In case someone made a mistake and left out the quotes
1232 ;; in the :version value.
1233 (if (numberp version2
)
1234 (setq version2
(prin1-to-string version2
)))
1235 (let (major1 major2 minor1 minor2
)
1236 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version1
)
1237 (setq major1
(read (or (match-string 1 version1
)
1239 (setq minor1
(read (or (match-string 3 version1
)
1241 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version2
)
1242 (setq major2
(read (or (match-string 1 version2
)
1244 (setq minor2
(read (or (match-string 3 version2
)
1246 (or (< major1 major2
)
1247 (and (= major1 major2
)
1248 (< minor1 minor2
)))))
1251 (defun customize-face (&optional face
)
1252 "Customize FACE, which should be a face name or nil.
1253 If FACE is nil, customize all faces. If FACE is actually a
1254 face-alias, customize the face it is aliased to.
1256 Interactively, when point is on text which has a face specified,
1257 suggest to customize that face, if it's customizable."
1258 (interactive (list (read-face-name "Customize face" "all faces" t
)))
1259 (if (member face
'(nil ""))
1260 (setq face
(face-list)))
1261 (if (and (listp face
) (null (cdr face
)))
1262 (setq face
(car face
)))
1264 (custom-buffer-create
1266 (mapcar (lambda (s) (list s
'custom-face
)) face
)
1268 "*Customize Faces*")
1269 ;; If FACE is actually an alias, customize the face it is aliased to.
1270 (if (get face
'face-alias
)
1271 (setq face
(get face
'face-alias
)))
1272 (unless (facep face
)
1273 (error "Invalid face %S" face
))
1274 (custom-buffer-create
1275 (list (list face
'custom-face
))
1276 (format "*Customize Face: %s*"
1277 (custom-unlispify-tag-name face
)))))
1280 (defun customize-face-other-window (&optional face
)
1281 "Show customization buffer for face FACE in other window.
1282 If FACE is actually a face-alias, customize the face it is aliased to.
1284 Interactively, when point is on text which has a face specified,
1285 suggest to customize that face, if it's customizable."
1286 (interactive (list (read-face-name "Customize face" "all faces" t
)))
1287 (let ((pop-up-windows t
)
1288 (same-window-buffer-names nil
)
1289 (same-window-regexps nil
))
1290 (customize-face face
)))
1292 (defalias 'customize-customized
'customize-unsaved
)
1295 (defun customize-unsaved ()
1296 "Customize all user options set in this session but not saved."
1299 (mapatoms (lambda (symbol)
1300 (and (or (get symbol
'customized-face
)
1301 (get symbol
'customized-face-comment
))
1302 (custom-facep symbol
)
1303 (push (list symbol
'custom-face
) found
))
1304 (and (or (get symbol
'customized-value
)
1305 (get symbol
'customized-variable-comment
))
1307 (push (list symbol
'custom-variable
) found
))))
1309 (error "No user options are set but unsaved")
1310 (custom-buffer-create (custom-sort-items found t nil
)
1311 "*Customize Unsaved*"))))
1314 (defun customize-rogue ()
1315 "Customize all user variables modified outside customize."
1318 (mapatoms (lambda (symbol)
1319 (let ((cval (or (get symbol
'customized-value
)
1320 (get symbol
'saved-value
)
1321 (get symbol
'standard-value
))))
1322 (when (and cval
;Declared with defcustom.
1323 (default-boundp symbol
) ;Has a value.
1324 (not (equal (eval (car cval
))
1325 ;; Which does not match customize.
1326 (default-value symbol
))))
1327 (push (list symbol
'custom-variable
) found
)))))
1329 (error "No rogue user options")
1330 (custom-buffer-create (custom-sort-items found t nil
)
1331 "*Customize Rogue*"))))
1333 (defun customize-saved ()
1334 "Customize all already saved user options."
1337 (mapatoms (lambda (symbol)
1338 (and (or (get symbol
'saved-face
)
1339 (get symbol
'saved-face-comment
))
1340 (custom-facep symbol
)
1341 (push (list symbol
'custom-face
) found
))
1342 (and (or (get symbol
'saved-value
)
1343 (get symbol
'saved-variable-comment
))
1345 (push (list symbol
'custom-variable
) found
))))
1347 (error "No saved user options")
1348 (custom-buffer-create (custom-sort-items found t nil
)
1349 "*Customize Saved*"))))
1352 (defun customize-apropos (regexp &optional all
)
1353 "Customize all loaded options, faces and groups matching REGEXP.
1354 If ALL is `options', include only options.
1355 If ALL is `faces', include only faces.
1356 If ALL is `groups', include only groups.
1357 If ALL is t (interactively, with prefix arg), include variables
1358 that are not customizable options, as well as faces and groups
1359 \(but we recommend using `apropos-variable' instead)."
1360 (interactive "sCustomize (regexp): \nP")
1362 (mapatoms (lambda (symbol)
1363 (when (string-match regexp
(symbol-name symbol
))
1364 (when (and (not (memq all
'(faces options
)))
1365 (get symbol
'custom-group
))
1366 (push (list symbol
'custom-group
) found
))
1367 (when (and (not (memq all
'(options groups
)))
1368 (custom-facep symbol
))
1369 (push (list symbol
'custom-face
) found
))
1370 (when (and (not (memq all
'(groups faces
)))
1372 (eq (indirect-variable symbol
) symbol
)
1373 (or (get symbol
'saved-value
)
1374 (custom-variable-p symbol
)
1375 (and (not (memq all
'(nil options
)))
1376 (get symbol
'variable-documentation
))))
1377 (push (list symbol
'custom-variable
) found
)))))
1379 (error "No %s matching %s"
1382 (format "customizable %s"
1383 (if (memq all
'(options faces groups
))
1387 (custom-buffer-create
1388 (custom-sort-items found t custom-buffer-order-groups
)
1389 "*Customize Apropos*"))))
1392 (defun customize-apropos-options (regexp &optional arg
)
1393 "Customize all loaded customizable options matching REGEXP.
1394 With prefix arg, include variables that are not customizable options
1395 \(but we recommend using `apropos-variable' instead)."
1396 (interactive "sCustomize options (regexp): \nP")
1397 (customize-apropos regexp
(or arg
'options
)))
1400 (defun customize-apropos-faces (regexp)
1401 "Customize all loaded faces matching REGEXP."
1402 (interactive "sCustomize faces (regexp): \n")
1403 (customize-apropos regexp
'faces
))
1406 (defun customize-apropos-groups (regexp)
1407 "Customize all loaded groups matching REGEXP."
1408 (interactive "sCustomize groups (regexp): \n")
1409 (customize-apropos regexp
'groups
))
1413 (defcustom custom-buffer-style
'links
1414 "Control the presentation style for customization buffers.
1415 The value should be a symbol, one of:
1417 brackets: groups nest within each other with big horizontal brackets.
1418 links: groups have links to subgroups."
1419 :type
'(radio (const brackets
)
1421 :group
'custom-buffer
)
1423 (defcustom custom-buffer-done-kill nil
1424 "*Non-nil means exiting a Custom buffer should kill it."
1427 :group
'custom-buffer
)
1429 (defcustom custom-buffer-indent
3
1430 "Number of spaces to indent nested groups."
1432 :group
'custom-buffer
)
1434 (defun custom-get-fresh-buffer (name)
1435 "Get a fresh new buffer with name NAME.
1436 If the buffer already exist, clean it up to be like new.
1437 Beware: it's not quite like new. Good enough for custom, but maybe
1439 ;; To be more complete, we should also kill all permanent-local variables,
1440 ;; but it's not needed for custom.
1441 (let ((buf (get-buffer name
)))
1442 (when (and buf
(buffer-local-value 'buffer-file-name buf
))
1443 ;; This will check if the file is not saved.
1447 (get-buffer-create name
)
1448 (with-current-buffer buf
1449 (kill-all-local-variables)
1450 (run-hooks 'kill-buffer-hook
)
1451 ;; Delete overlays before erasing the buffer so the overlay hooks
1452 ;; don't get run spuriously when we erase the buffer.
1453 (let ((ols (overlay-lists)))
1454 (dolist (ol (nconc (car ols
) (cdr ols
)))
1455 (delete-overlay ol
)))
1460 (defun custom-buffer-create (options &optional name description
)
1461 "Create a buffer containing OPTIONS.
1462 Optional NAME is the name of the buffer.
1463 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1464 SYMBOL is a customization option, and WIDGET is a widget for editing
1466 (pop-to-buffer (custom-get-fresh-buffer (or name
"*Customization*")))
1467 (custom-buffer-create-internal options description
))
1470 (defun custom-buffer-create-other-window (options &optional name description
)
1471 "Create a buffer containing OPTIONS, and display it in another window.
1472 The result includes selecting that window.
1473 Optional NAME is the name of the buffer.
1474 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1475 SYMBOL is a customization option, and WIDGET is a widget for editing
1477 (unless name
(setq name
"*Customization*"))
1478 (let ((pop-up-windows t
)
1479 (same-window-buffer-names nil
)
1480 (same-window-regexps nil
))
1481 (pop-to-buffer (custom-get-fresh-buffer name
))
1482 (custom-buffer-create-internal options description
)))
1484 (defcustom custom-reset-button-menu nil
1485 "If non-nil, only show a single reset button in customize buffers.
1486 This button will have a menu with all three reset operations."
1488 :group
'custom-buffer
)
1490 (defcustom custom-buffer-verbose-help t
1491 "If non-nil, include explanatory text in the customization buffer."
1493 :group
'custom-buffer
)
1495 (defun Custom-buffer-done (&rest ignore
)
1496 "Exit current Custom buffer according to `custom-buffer-done-kill'."
1498 (quit-window custom-buffer-done-kill
))
1500 (defvar custom-button nil
1501 "Face used for buttons in customization buffers.")
1503 (defvar custom-button-mouse nil
1504 "Mouse face used for buttons in customization buffers.")
1506 (defvar custom-button-pressed nil
1507 "Face used for pressed buttons in customization buffers.")
1509 (defcustom custom-raised-buttons
(not (equal (face-valid-attribute-values :box
)
1510 '(("unspecified" . unspecified
))))
1511 "If non-nil, indicate active buttons in a `raised-button' style.
1512 Otherwise use brackets."
1515 :group
'custom-buffer
1516 :set
(lambda (variable value
)
1517 (custom-set-default variable value
)
1519 (if value
'custom-button
'custom-button-unraised
))
1520 (setq custom-button-mouse
1521 (if value
'custom-button-mouse
'highlight
))
1522 (setq custom-button-pressed
1524 'custom-button-pressed
1525 'custom-button-pressed-unraised
))))
1527 (defun custom-buffer-create-internal (options &optional description
)
1529 (let ((init-file (or custom-file user-init-file
)))
1530 ;; Insert verbose help at the top of the custom buffer.
1531 (when custom-buffer-verbose-help
1532 (widget-insert "Editing a setting changes only the text in this buffer."
1535 To set apply your changes, use the Save or Set buttons.
1536 Saving a change normally works by editing your init file."
1538 Currently, these settings cannot be saved for future Emacs sessions,
1539 possibly because you started Emacs with `-q'.")
1540 "\nFor details, see ")
1541 (widget-create 'custom-manual
1542 :tag
"Saving Customizations"
1543 "(emacs)Saving Customizations")
1544 (widget-insert " in the ")
1545 (widget-create 'custom-manual
1547 :help-echo
"Read the Emacs manual."
1549 (widget-insert "."))
1550 ;; Insert custom command buttons if the toolbar is not in use.
1552 (widget-insert "\n")
1553 (when (not (and tool-bar-mode
(display-graphic-p)))
1554 (if custom-buffer-verbose-help
1556 Operate on all settings in this buffer that are not marked HIDDEN:\n"))
1557 (let ((button (lambda (tag action active help icon
)
1560 (widget-create 'push-button
:tag tag
1561 :help-echo help
:action action
))))
1562 (commands custom-commands
))
1563 (apply button
(pop commands
)) ; Set for current session
1564 (apply button
(pop commands
)) ; Save for future sessions
1565 (if custom-reset-button-menu
1568 (widget-create 'push-button
1570 :help-echo
"Show a menu with reset operations."
1571 :mouse-down-action
'ignore
1572 :action
'custom-reset
))
1573 (widget-insert "\n")
1574 (apply button
(pop commands
)) ; Undo edits
1575 (apply button
(pop commands
)) ; Reset to saved
1576 (apply button
(pop commands
)) ; Erase customization
1578 (pop commands
) ; Help (omitted)
1579 (apply button
(pop commands
))))) ; Exit
1580 (widget-insert "\n\n"))
1582 ;; Now populate the custom buffer.
1583 (message "Creating customization items...")
1584 (buffer-disable-undo)
1585 (setq custom-options
1586 (if (= (length options
) 1)
1587 (mapcar (lambda (entry)
1588 (widget-create (nth 1 entry
)
1589 :documentation-shown t
1590 :custom-state
'unknown
1591 :tag
(custom-unlispify-tag-name
1593 :value
(nth 0 entry
)))
1596 (length (length options
)))
1597 (mapcar (lambda (entry)
1599 (message "Creating customization items ...%2d%%"
1600 (/ (* 100.0 count
) length
))
1601 (widget-create (nth 1 entry
)
1602 :tag
(custom-unlispify-tag-name
1604 :value
(nth 0 entry
))
1605 (setq count
(1+ count
))
1606 (unless (eq (preceding-char) ?
\n)
1607 (widget-insert "\n"))
1608 (widget-insert "\n")))
1610 (unless (eq (preceding-char) ?
\n)
1611 (widget-insert "\n"))
1612 (message "Creating customization items ...done")
1613 (message "Resetting customization items...")
1614 (unless (eq custom-buffer-style
'tree
)
1615 (mapc 'custom-magic-reset custom-options
))
1616 (message "Resetting customization items...done")
1617 (message "Creating customization setup...")
1619 (buffer-enable-undo)
1620 (goto-char (point-min))
1621 (message "Creating customization setup...done"))
1623 ;;; The Tree Browser.
1626 (defun customize-browse (&optional group
)
1627 "Create a tree browser for the customize hierarchy."
1630 (setq group
'emacs
))
1631 (let ((name "*Customize Browser*"))
1632 (pop-to-buffer (custom-get-fresh-buffer name
)))
1634 (widget-insert (format "\
1635 %s buttons; type RET or click mouse-1
1636 on a button to invoke its action.
1637 Invoke [+] to expand a group, and [-] to collapse an expanded group.\n"
1638 (if custom-raised-buttons
1639 "`Raised' text indicates"
1640 "Square brackets indicate")))
1643 (if custom-browse-only-groups
1645 Invoke the [Group] button below to edit that item in another window.\n\n")
1646 (widget-insert "Invoke the ")
1647 (widget-create 'item
1650 :tag-glyph
"folder")
1651 (widget-insert ", ")
1652 (widget-create 'item
1656 (widget-insert ", and ")
1657 (widget-create 'item
1660 :tag-glyph
"option")
1661 (widget-insert " buttons below to edit that
1662 item in another window.\n\n"))
1663 (let ((custom-buffer-style 'tree
))
1664 (widget-create 'custom-group
1666 :custom-state
'unknown
1667 :tag
(custom-unlispify-tag-name group
)
1670 (goto-char (point-min)))
1672 (define-widget 'custom-browse-visibility
'item
1673 "Control visibility of items in the customize tree browser."
1675 :action
'custom-browse-visibility-action
)
1677 (defun custom-browse-visibility-action (widget &rest ignore
)
1678 (let ((custom-buffer-style 'tree
))
1679 (custom-toggle-parent widget
)))
1681 (define-widget 'custom-browse-group-tag
'custom-group-link
1682 "Show parent in other window when activated."
1685 :action
'custom-browse-group-tag-action
)
1687 (defun custom-browse-group-tag-action (widget &rest ignore
)
1688 (let ((parent (widget-get widget
:parent
)))
1689 (customize-group-other-window (widget-value parent
))))
1691 (define-widget 'custom-browse-variable-tag
'custom-group-link
1692 "Show parent in other window when activated."
1695 :action
'custom-browse-variable-tag-action
)
1697 (defun custom-browse-variable-tag-action (widget &rest ignore
)
1698 (let ((parent (widget-get widget
:parent
)))
1699 (customize-variable-other-window (widget-value parent
))))
1701 (define-widget 'custom-browse-face-tag
'custom-group-link
1702 "Show parent in other window when activated."
1705 :action
'custom-browse-face-tag-action
)
1707 (defun custom-browse-face-tag-action (widget &rest ignore
)
1708 (let ((parent (widget-get widget
:parent
)))
1709 (customize-face-other-window (widget-value parent
))))
1711 (defconst custom-browse-alist
'((" " "space")
1717 (defun custom-browse-insert-prefix (prefix)
1718 "Insert PREFIX. On XEmacs convert it to line graphics."
1719 ;; Fixme: do graphics.
1720 (if nil
; (string-match "XEmacs" emacs-version)
1723 (while (not (string-equal prefix
""))
1724 (let ((entry (substring prefix
0 3)))
1725 (setq prefix
(substring prefix
3))
1726 (let ((overlay (make-overlay (1- (point)) (point) nil t nil
))
1727 (name (nth 1 (assoc entry custom-browse-alist
))))
1728 (overlay-put overlay
'end-glyph
(widget-glyph-find name entry
))
1729 (overlay-put overlay
'start-open t
)
1730 (overlay-put overlay
'end-open t
)))))
1733 ;;; Modification of Basic Widgets.
1735 ;; We add extra properties to the basic widgets needed here. This is
1736 ;; fine, as long as we are careful to stay within out own namespace.
1738 ;; We want simple widgets to be displayed by default, but complex
1739 ;; widgets to be hidden.
1741 (widget-put (get 'item
'widget-type
) :custom-show t
)
1742 (widget-put (get 'editable-field
'widget-type
)
1743 :custom-show
(lambda (widget value
)
1744 (let ((pp (pp-to-string value
)))
1745 (cond ((string-match "\n" pp
)
1750 (widget-put (get 'menu-choice
'widget-type
) :custom-show t
)
1752 ;;; The `custom-manual' Widget.
1754 (define-widget 'custom-manual
'info-link
1755 "Link to the manual entry for this customization option."
1756 :help-echo
"Read the manual entry for this option."
1757 :keymap custom-mode-link-map
1758 :follow-link
'mouse-face
1759 :button-face
'custom-link
1760 :mouse-face
'highlight
1761 :pressed-face
'highlight
1764 ;;; The `custom-magic' Widget.
1766 (defgroup custom-magic-faces nil
1767 "Faces used by the magic button."
1768 :group
'custom-faces
1769 :group
'custom-buffer
)
1771 (defface custom-invalid
'((((class color
))
1772 (:foreground
"yellow1" :background
"red1"))
1774 (:weight bold
:slant italic
:underline t
)))
1775 "Face used when the customize item is invalid."
1776 :group
'custom-magic-faces
)
1777 ;; backward-compatibility alias
1778 (put 'custom-invalid-face
'face-alias
'custom-invalid
)
1780 (defface custom-rogue
'((((class color
))
1781 (:foreground
"pink" :background
"black"))
1784 "Face used when the customize item is not defined for customization."
1785 :group
'custom-magic-faces
)
1786 ;; backward-compatibility alias
1787 (put 'custom-rogue-face
'face-alias
'custom-rogue
)
1789 (defface custom-modified
'((((min-colors 88) (class color
))
1790 (:foreground
"white" :background
"blue1"))
1792 (:foreground
"white" :background
"blue"))
1794 (:slant italic
:bold
)))
1795 "Face used when the customize item has been modified."
1796 :group
'custom-magic-faces
)
1797 ;; backward-compatibility alias
1798 (put 'custom-modified-face
'face-alias
'custom-modified
)
1800 (defface custom-set
'((((min-colors 88) (class color
))
1801 (:foreground
"blue1" :background
"white"))
1803 (:foreground
"blue" :background
"white"))
1806 "Face used when the customize item has been set."
1807 :group
'custom-magic-faces
)
1808 ;; backward-compatibility alias
1809 (put 'custom-set-face
'face-alias
'custom-set
)
1811 (defface custom-changed
'((((min-colors 88) (class color
))
1812 (:foreground
"white" :background
"blue1"))
1814 (:foreground
"white" :background
"blue"))
1817 "Face used when the customize item has been changed."
1818 :group
'custom-magic-faces
)
1819 ;; backward-compatibility alias
1820 (put 'custom-changed-face
'face-alias
'custom-changed
)
1822 (defface custom-themed
'((((min-colors 88) (class color
))
1823 (:foreground
"white" :background
"blue1"))
1825 (:foreground
"white" :background
"blue"))
1828 "Face used when the customize item has been set by a theme."
1829 :group
'custom-magic-faces
)
1831 (defface custom-saved
'((t (:underline t
)))
1832 "Face used when the customize item has been saved."
1833 :group
'custom-magic-faces
)
1834 ;; backward-compatibility alias
1835 (put 'custom-saved-face
'face-alias
'custom-saved
)
1837 (defconst custom-magic-alist
1838 '((nil "#" underline
"\
1839 UNINITIALIZED, you should not see this.")
1840 (unknown "?" italic
"\
1841 UNKNOWN, you should not see this.")
1842 (hidden "-" default
"\
1843 HIDDEN, invoke \"Show\" in the previous line to show." "\
1844 group now hidden, invoke \"Show\", above, to show contents.")
1845 (invalid "x" custom-invalid
"\
1846 INVALID, the displayed value cannot be set.")
1847 (modified "*" custom-modified
"\
1848 EDITED, shown value does not take effect until you set or save it." "\
1849 something in this group has been edited but not set.")
1850 (set "+" custom-set
"\
1851 SET for current session only." "\
1852 something in this group has been set but not saved.")
1853 (changed ":" custom-changed
"\
1854 CHANGED outside Customize; operating on it here may be unreliable." "\
1855 something in this group has been changed outside customize.")
1856 (saved "!" custom-saved
"\
1858 something in this group has been set and saved.")
1859 (themed "o" custom-themed
"\
1861 visible group members are all at standard values.")
1862 (rogue "@" custom-rogue
"\
1863 NO CUSTOMIZATION DATA; not intended to be customized." "\
1864 something in this group is not prepared for customization.")
1865 (standard " " nil
"\
1867 visible group members are all at standard values."))
1868 "Alist of customize option states.
1869 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1871 STATE is one of the following symbols:
1874 For internal use, should never occur.
1876 For internal use, should never occur.
1878 This item is not being displayed.
1880 This item is modified, but has an invalid form.
1882 This item is modified, and has a valid form.
1884 This item has been set but not saved.
1886 The current value of this item has been changed outside Customize.
1888 This item is marked for saving.
1890 This item has no customization information.
1892 This item is unchanged from the standard setting.
1894 MAGIC is a string used to present that state.
1896 FACE is a face used to present the state.
1898 ITEM-DESC is a string describing the state for options.
1900 GROUP-DESC is a string describing the state for groups. If this is
1901 left out, ITEM-DESC will be used.
1903 The string %c in either description will be replaced with the
1904 category of the item. These are `group'. `option', and `face'.
1906 The list should be sorted most significant first.")
1908 (defcustom custom-magic-show
'long
1909 "If non-nil, show textual description of the state.
1910 If `long', show a full-line description, not just one word."
1911 :type
'(choice (const :tag
"no" nil
)
1913 (other :tag
"short" short
))
1914 :group
'custom-buffer
)
1916 (defcustom custom-magic-show-hidden
'(option face
)
1917 "Control whether the State button is shown for hidden items.
1918 The value should be a list with the custom categories where the State
1919 button should be visible. Possible categories are `group', `option',
1921 :type
'(set (const group
) (const option
) (const face
))
1922 :group
'custom-buffer
)
1924 (defcustom custom-magic-show-button nil
1925 "Show a \"magic\" button indicating the state of each customization option."
1927 :group
'custom-buffer
)
1929 (define-widget 'custom-magic
'default
1930 "Show and manipulate state for a customization option."
1932 :action
'widget-parent-action
1935 :value-create
'custom-magic-value-create
1936 :value-delete
'widget-children-value-delete
)
1938 (defun widget-magic-mouse-down-action (widget &optional event
)
1939 ;; Non-nil unless hidden.
1940 (not (eq (widget-get (widget-get (widget-get widget
:parent
) :parent
)
1944 (defun custom-magic-value-create (widget)
1945 "Create compact status report for WIDGET."
1946 (let* ((parent (widget-get widget
:parent
))
1947 (state (widget-get parent
:custom-state
))
1948 (hidden (eq state
'hidden
))
1949 (entry (assq state custom-magic-alist
))
1950 (magic (nth 1 entry
))
1951 (face (nth 2 entry
))
1952 (category (widget-get parent
:custom-category
))
1953 (text (or (and (eq category
'group
)
1956 (form (widget-get parent
:custom-form
))
1958 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text
)
1959 (setq text
(concat (match-string 1 text
)
1960 (symbol-name category
)
1961 (match-string 2 text
))))
1962 (when (and custom-magic-show
1964 (memq category custom-magic-show-hidden
)))
1966 (when (and (eq category
'group
)
1967 (not (and (eq custom-buffer-style
'links
)
1968 (> (widget-get parent
:custom-level
) 1))))
1969 (insert-char ?\
(* custom-buffer-indent
1970 (widget-get parent
:custom-level
))))
1971 (push (widget-create-child-and-convert
1973 :help-echo
"Change the state of this item."
1974 :format
(if hidden
"%t" "%[%t%]")
1975 :button-prefix
'widget-push-button-prefix
1976 :button-suffix
'widget-push-button-suffix
1977 :mouse-down-action
'widget-magic-mouse-down-action
1981 (let ((start (point)))
1982 (if (eq custom-magic-show
'long
)
1984 (insert (symbol-name state
)))
1985 (cond ((eq form
'lisp
)
1987 ((eq form
'mismatch
)
1988 (insert " (mismatch)")))
1989 (put-text-property start
(point) 'face
'custom-state
))
1991 (when (and (eq category
'group
)
1992 (not (and (eq custom-buffer-style
'links
)
1993 (> (widget-get parent
:custom-level
) 1))))
1994 (insert-char ?\
(* custom-buffer-indent
1995 (widget-get parent
:custom-level
))))
1996 (when custom-magic-show-button
1997 (when custom-magic-show
1998 (let ((indent (widget-get parent
:indent
)))
2000 (insert-char ? indent
))))
2001 (push (widget-create-child-and-convert
2003 :mouse-down-action
'widget-magic-mouse-down-action
2007 :help-echo
"Change the state."
2008 :format
(if hidden
"%t" "%[%t%]")
2009 :tag
(if (memq form
'(lisp mismatch
))
2010 (concat "(" magic
")")
2011 (concat "[" magic
"]")))
2014 (widget-put widget
:children children
)))
2016 (defun custom-magic-reset (widget)
2017 "Redraw the :custom-magic property of WIDGET."
2018 (let ((magic (widget-get widget
:custom-magic
)))
2019 (widget-value-set magic
(widget-value magic
))))
2021 ;;; The `custom' Widget.
2023 (defface custom-button
2024 '((((type x w32 mac
) (class color
)) ; Like default modeline
2025 (:box
(:line-width
2 :style released-button
)
2026 :background
"lightgrey" :foreground
"black"))
2029 "Face for custom buffer buttons if `custom-raised-buttons' is non-nil."
2031 :group
'custom-faces
)
2032 ;; backward-compatibility alias
2033 (put 'custom-button-face
'face-alias
'custom-button
)
2035 (defface custom-button-mouse
2036 '((((type x w32 mac
) (class color
))
2037 (:box
(:line-width
2 :style released-button
)
2038 :background
"grey90" :foreground
"black"))
2041 "Mouse face for custom buffer buttons if `custom-raised-buttons' is non-nil."
2043 :group
'custom-faces
)
2045 (defface custom-button-unraised
2046 '((t :inherit underline
))
2047 "Face for custom buffer buttons if `custom-raised-buttons' is nil."
2049 :group
'custom-faces
)
2052 (if custom-raised-buttons
'custom-button
'custom-button-unraised
))
2054 (setq custom-button-mouse
2055 (if custom-raised-buttons
'custom-button-mouse
'highlight
))
2057 (defface custom-button-pressed
2058 '((((type x w32 mac
) (class color
))
2059 (:box
(:line-width
2 :style pressed-button
)
2060 :background
"lightgrey" :foreground
"black"))
2062 (:inverse-video t
)))
2063 "Face for pressed custom buttons if `custom-raised-buttons' is non-nil."
2065 :group
'custom-faces
)
2066 ;; backward-compatibility alias
2067 (put 'custom-button-pressed-face
'face-alias
'custom-button-pressed
)
2069 (defface custom-button-pressed-unraised
2070 '((default :inherit custom-button-unraised
)
2071 (((class color
) (background light
)) :foreground
"magenta4")
2072 (((class color
) (background dark
)) :foreground
"violet"))
2073 "Face for pressed custom buttons if `custom-raised-buttons' is nil."
2075 :group
'custom-faces
)
2077 (setq custom-button-pressed
2078 (if custom-raised-buttons
2079 'custom-button-pressed
2080 'custom-button-pressed-unraised
))
2082 (defface custom-documentation
'((t nil
))
2083 "Face used for documentation strings in customization buffers."
2084 :group
'custom-faces
)
2085 ;; backward-compatibility alias
2086 (put 'custom-documentation-face
'face-alias
'custom-documentation
)
2088 (defface custom-state
'((((class color
)
2090 (:foreground
"lime green"))
2093 (:foreground
"dark green"))
2095 "Face used for State descriptions in the customize buffer."
2096 :group
'custom-faces
)
2097 ;; backward-compatibility alias
2098 (put 'custom-state-face
'face-alias
'custom-state
)
2100 (defface custom-link
2101 '((t :inherit link
))
2102 "Face for links in customization buffers."
2104 :group
'custom-faces
)
2106 (define-widget 'custom
'default
2107 "Customize a user option."
2109 :convert-widget
'custom-convert-widget
2110 :notify
'custom-notify
2113 :custom-state
'hidden
2114 :documentation-property
'widget-subclass-responsibility
2115 :value-create
'widget-subclass-responsibility
2116 :value-delete
'widget-children-value-delete
2117 :value-get
'widget-value-value-get
2118 :validate
'widget-children-validate
2119 :match
(lambda (widget value
) (symbolp value
)))
2121 (defun custom-convert-widget (widget)
2122 "Initialize :value and :tag from :args in WIDGET."
2123 (let ((args (widget-get widget
:args
)))
2125 (widget-put widget
:value
(widget-apply widget
2126 :value-to-internal
(car args
)))
2127 (widget-put widget
:tag
(custom-unlispify-tag-name (car args
)))
2128 (widget-put widget
:args nil
)))
2131 (defun custom-notify (widget &rest args
)
2132 "Keep track of changes."
2133 (let ((state (widget-get widget
:custom-state
)))
2134 (unless (eq state
'modified
)
2135 (unless (memq state
'(nil unknown hidden
))
2136 (widget-put widget
:custom-state
'modified
))
2137 (custom-magic-reset widget
)
2138 (apply 'widget-default-notify widget args
))))
2140 (defun custom-redraw (widget)
2141 "Redraw WIDGET with current settings."
2142 (let ((line (count-lines (point-min) (point)))
2143 (column (current-column))
2145 (from (marker-position (widget-get widget
:from
)))
2146 (to (marker-position (widget-get widget
:to
))))
2148 (widget-value-set widget
(widget-value widget
))
2149 (custom-redraw-magic widget
))
2150 (when (and (>= pos from
) (<= pos to
))
2155 (goto-line (1+ line
)))
2156 (move-to-column column
))
2159 (defun custom-redraw-magic (widget)
2160 "Redraw WIDGET state with current settings."
2162 (let ((magic (widget-get widget
:custom-magic
)))
2164 (widget-value-set magic
(widget-value magic
))
2165 (when (setq widget
(widget-get widget
:group
))
2166 (custom-group-state-update widget
)))
2168 (setq widget nil
)))))
2171 (defun custom-show (widget value
)
2172 "Non-nil if WIDGET should be shown with VALUE by default."
2173 (let ((show (widget-get widget
:custom-show
)))
2179 (funcall show widget value
)))))
2181 (defun custom-load-widget (widget)
2182 "Load all dependencies for WIDGET."
2183 (custom-load-symbol (widget-value widget
)))
2185 (defun custom-unloaded-symbol-p (symbol)
2186 "Return non-nil if the dependencies of SYMBOL have not yet been loaded."
2188 (loads (get symbol
'custom-loads
))
2191 (setq load
(car loads
)
2193 (cond ((symbolp load
)
2194 (unless (featurep load
)
2196 ((assoc load load-history
))
2197 ((assoc (locate-library load
) load-history
)
2203 (defun custom-unloaded-widget-p (widget)
2204 "Return non-nil if the dependencies of WIDGET have not yet been loaded."
2205 (custom-unloaded-symbol-p (widget-value widget
)))
2207 (defun custom-toggle-hide (widget)
2208 "Toggle visibility of WIDGET."
2209 (custom-load-widget widget
)
2210 (let ((state (widget-get widget
:custom-state
)))
2211 (cond ((memq state
'(invalid modified
))
2212 (error "There are unset changes"))
2214 (widget-put widget
:custom-state
'unknown
))
2216 (widget-put widget
:documentation-shown nil
)
2217 (widget-put widget
:custom-state
'hidden
)))
2218 (custom-redraw widget
)
2221 (defun custom-toggle-parent (widget &rest ignore
)
2222 "Toggle visibility of parent of WIDGET."
2223 (custom-toggle-hide (widget-get widget
:parent
)))
2225 (defun custom-add-see-also (widget &optional prefix
)
2226 "Add `See also ...' to WIDGET if there are any links.
2227 Insert PREFIX first if non-nil."
2228 (let* ((symbol (widget-get widget
:value
))
2229 (links (get symbol
'custom-links
))
2230 (many (> (length links
) 2))
2231 (buttons (widget-get widget
:buttons
))
2232 (indent (widget-get widget
:indent
)))
2235 (insert-char ?\ indent
))
2238 (insert "See also ")
2240 (push (widget-create-child-and-convert
2242 :button-face
'custom-link
2243 :mouse-face
'highlight
2244 :pressed-face
'highlight
)
2246 (setq links
(cdr links
))
2255 (widget-put widget
:buttons buttons
))))
2257 (defun custom-add-parent-links (widget &optional initial-string
)
2258 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
2259 The value is non-nil if any parents were found.
2260 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
2261 (let ((name (widget-value widget
))
2262 (type (widget-type widget
))
2263 (buttons (widget-get widget
:buttons
))
2266 (insert (or initial-string
"Parent groups:"))
2267 (mapatoms (lambda (symbol)
2268 (when (member (list name type
) (get symbol
'custom-group
))
2270 (push (widget-create-child-and-convert
2271 widget
'custom-group-link
2272 :tag
(custom-unlispify-tag-name symbol
)
2275 (setq parents
(cons symbol parents
)))))
2276 (and (null (get name
'custom-links
)) ;No links of its own.
2277 (= (length parents
) 1) ;A single parent.
2278 (let* ((links (delq nil
(mapcar (lambda (w)
2279 (unless (eq (widget-type w
)
2282 (get (car parents
) 'custom-links
))))
2283 (many (> (length links
) 2)))
2285 (insert "\nParent documentation: ")
2287 (push (widget-create-child-and-convert
2289 :button-face
'custom-link
2290 :mouse-face
'highlight
2291 :pressed-face
'highlight
)
2293 (setq links
(cdr links
))
2304 (delete-region start
(point)))
2305 (widget-put widget
:buttons buttons
)
2308 ;;; The `custom-comment' Widget.
2310 ;; like the editable field
2311 (defface custom-comment
'((((type tty
))
2312 :background
"yellow3"
2313 :foreground
"black")
2314 (((class grayscale color
)
2316 :background
"gray85")
2317 (((class grayscale color
)
2319 :background
"dim gray")
2322 "Face used for comments on variables or faces"
2324 :group
'custom-faces
)
2325 ;; backward-compatibility alias
2326 (put 'custom-comment-face
'face-alias
'custom-comment
)
2328 ;; like font-lock-comment-face
2329 (defface custom-comment-tag
2330 '((((class color
) (background dark
)) (:foreground
"gray80"))
2331 (((class color
) (background light
)) (:foreground
"blue4"))
2332 (((class grayscale
) (background light
))
2333 (:foreground
"DimGray" :weight bold
:slant italic
))
2334 (((class grayscale
) (background dark
))
2335 (:foreground
"LightGray" :weight bold
:slant italic
))
2337 "Face used for variables or faces comment tags"
2338 :group
'custom-faces
)
2339 ;; backward-compatibility alias
2340 (put 'custom-comment-tag-face
'face-alias
'custom-comment-tag
)
2342 (define-widget 'custom-comment
'string
2345 :help-echo
"Edit a comment here."
2346 :sample-face
'custom-comment-tag-face
2347 :value-face
'custom-comment-face
2349 :create
'custom-comment-create
)
2351 (defun custom-comment-create (widget)
2352 (let* ((null-comment (equal "" (widget-value widget
))))
2353 (if (or (widget-get (widget-get widget
:parent
) :comment-shown
)
2355 (widget-default-create widget
)
2356 ;; `widget-default-delete' expects markers in these slots --
2357 ;; maybe it shouldn't.
2358 (widget-put widget
:from
(point-marker))
2359 (widget-put widget
:to
(point-marker)))))
2361 (defun custom-comment-hide (widget)
2362 (widget-put (widget-get widget
:parent
) :comment-shown nil
))
2364 ;; Those functions are for the menu. WIDGET is NOT the comment widget. It's
2365 ;; the global custom one
2366 (defun custom-comment-show (widget)
2367 (widget-put widget
:comment-shown t
)
2368 (custom-redraw widget
)
2371 (defun custom-comment-invisible-p (widget)
2372 (let ((val (widget-value (widget-get widget
:comment-widget
))))
2374 (not (widget-get widget
:comment-shown
)))))
2376 ;;; The `custom-variable' Widget.
2378 ;; When this was underlined blue, users confused it with a
2379 ;; Mosaic-style hyperlink...
2380 (defface custom-variable-tag
2383 (:foreground
"light blue" :weight bold
))
2384 (((min-colors 88) (class color
)
2386 (:foreground
"blue1" :weight bold
))
2389 (:foreground
"blue" :weight bold
))
2391 "Face used for unpushable variable tags."
2392 :group
'custom-faces
)
2393 ;; backward-compatibility alias
2394 (put 'custom-variable-tag-face
'face-alias
'custom-variable-tag
)
2396 (defface custom-variable-button
'((t (:underline t
:weight bold
)))
2397 "Face used for pushable variable tags."
2398 :group
'custom-faces
)
2399 ;; backward-compatibility alias
2400 (put 'custom-variable-button-face
'face-alias
'custom-variable-button
)
2402 (defcustom custom-variable-default-form
'edit
2403 "Default form of displaying variable values."
2404 :type
'(choice (const edit
)
2406 :group
'custom-buffer
2409 (defun custom-variable-documentation (variable)
2410 "Return documentation of VARIABLE for use in Custom buffer.
2411 Normally just return the docstring. But if VARIABLE automatically
2412 becomes buffer local when set, append a message to that effect."
2413 (if (and (local-variable-if-set-p variable
)
2414 (or (not (local-variable-p variable
))
2416 (local-variable-if-set-p variable
))))
2417 (concat (documentation-property variable
'variable-documentation
)
2419 This variable automatically becomes buffer-local when set outside Custom.
2420 However, setting it through Custom sets the default value.")
2421 (documentation-property variable
'variable-documentation
)))
2423 (define-widget 'custom-variable
'custom
2424 "Customize variable."
2426 :help-echo
"Set or reset this variable."
2427 :documentation-property
#'custom-variable-documentation
2428 :custom-category
'option
2430 :custom-menu
'custom-variable-menu-create
2431 :custom-form nil
; defaults to value of `custom-variable-default-form'
2432 :value-create
'custom-variable-value-create
2433 :action
'custom-variable-action
2434 :custom-set
'custom-variable-set
2435 :custom-save
'custom-variable-save
2436 :custom-reset-current
'custom-redraw
2437 :custom-reset-saved
'custom-variable-reset-saved
2438 :custom-reset-standard
'custom-variable-reset-standard
2439 :custom-standard-value
'custom-variable-standard-value
)
2441 (defun custom-variable-type (symbol)
2442 "Return a widget suitable for editing the value of SYMBOL.
2443 If SYMBOL has a `custom-type' property, use that.
2444 Otherwise, try matching SYMBOL against `custom-guess-name-alist' and
2445 try matching its doc string against `custom-guess-doc-alist'."
2446 (let* ((type (or (get symbol
'custom-type
)
2447 (and (not (get symbol
'standard-value
))
2448 (custom-guess-type symbol
))
2450 (options (get symbol
'custom-options
))
2451 (tmp (if (listp type
)
2452 (copy-sequence type
)
2455 (widget-put tmp
:options options
))
2458 (defun custom-variable-value-create (widget)
2459 "Here is where you edit the variable's value."
2460 (custom-load-widget widget
)
2461 (unless (widget-get widget
:custom-form
)
2462 (widget-put widget
:custom-form custom-variable-default-form
))
2463 (let* ((buttons (widget-get widget
:buttons
))
2464 (children (widget-get widget
:children
))
2465 (form (widget-get widget
:custom-form
))
2466 (state (widget-get widget
:custom-state
))
2467 (symbol (widget-get widget
:value
))
2468 (tag (widget-get widget
:tag
))
2469 (type (custom-variable-type symbol
))
2470 (conv (widget-convert type
))
2471 (get (or (get symbol
'custom-get
) 'default-value
))
2472 (prefix (widget-get widget
:custom-prefix
))
2473 (last (widget-get widget
:custom-last
))
2474 (value (if (default-boundp symbol
)
2475 (funcall get symbol
)
2476 (widget-get conv
:value
))))
2477 ;; If the widget is new, the child determines whether it is hidden.
2479 ((custom-show type value
)
2480 (setq state
'unknown
))
2482 (setq state
'hidden
)))
2483 ;; If we don't know the state, see if we need to edit it in lisp form.
2484 (when (eq state
'unknown
)
2485 (unless (widget-apply conv
:match value
)
2486 ;; (widget-apply (widget-convert type) :match value)
2487 (setq form
'mismatch
)))
2488 ;; Now we can create the child widget.
2489 (cond ((eq custom-buffer-style
'tree
)
2490 (insert prefix
(if last
" `--- " " |--- "))
2491 (push (widget-create-child-and-convert
2492 widget
'custom-browse-variable-tag
)
2494 (insert " " tag
"\n")
2495 (widget-put widget
:buttons buttons
))
2497 ;; Indicate hidden value.
2498 (push (widget-create-child-and-convert
2501 :sample-face
'custom-variable-tag-face
2505 (push (widget-create-child-and-convert
2507 :help-echo
"Show the value of this option."
2509 :action
'custom-toggle-parent
2512 ((memq form
'(lisp mismatch
))
2513 ;; In lisp mode edit the saved value when possible.
2514 (let* ((value (cond ((get symbol
'saved-value
)
2515 (car (get symbol
'saved-value
)))
2516 ((get symbol
'standard-value
)
2517 (car (get symbol
'standard-value
)))
2518 ((default-boundp symbol
)
2519 (custom-quote (funcall get symbol
)))
2521 (custom-quote (widget-get conv
:value
))))))
2522 (insert (symbol-name symbol
) ": ")
2523 (push (widget-create-child-and-convert
2525 :help-echo
"Hide the value of this option."
2528 :action
'custom-toggle-parent
2532 (push (widget-create-child-and-convert
2534 :button-face
'custom-variable-button-face
2536 :tag
(symbol-name symbol
)
2542 (let* ((format (widget-get type
:format
))
2543 tag-format value-format
)
2544 (unless (string-match ":" format
)
2545 (error "Bad format"))
2546 (setq tag-format
(substring format
0 (match-end 0)))
2547 (setq value-format
(substring format
(match-end 0)))
2548 (push (widget-create-child-and-convert
2551 :action
'custom-tag-action
2552 :help-echo
"Change value of this option."
2553 :mouse-down-action
'custom-tag-mouse-down-action
2554 :button-face
'custom-variable-button-face
2555 :sample-face
'custom-variable-tag-face
2559 (push (widget-create-child-and-convert
2561 :help-echo
"Hide the value of this option."
2564 :action
'custom-toggle-parent
2567 (push (widget-create-child-and-convert
2569 :format value-format
2572 (unless (eq custom-buffer-style
'tree
)
2573 (unless (eq (preceding-char) ?
\n)
2574 (widget-insert "\n"))
2575 ;; Create the magic button.
2576 (let ((magic (widget-create-child-and-convert
2577 widget
'custom-magic nil
)))
2578 (widget-put widget
:custom-magic magic
)
2579 (push magic buttons
))
2580 (widget-put widget
:buttons buttons
)
2581 ;; Insert documentation.
2582 (widget-put widget
:documentation-indent
3)
2583 (widget-add-documentation-string-button
2584 widget
:visibility-widget
'custom-visibility
)
2586 ;; The comment field
2587 (unless (eq state
'hidden
)
2588 (let* ((comment (get symbol
'variable-comment
))
2590 (widget-create-child-and-convert
2591 widget
'custom-comment
2593 :value
(or comment
""))))
2594 (widget-put widget
:comment-widget comment-widget
)
2595 ;; Don't push it !!! Custom assumes that the first child is the
2597 (setq children
(append children
(list comment-widget
)))))
2598 ;; Update the rest of the properties properties.
2599 (widget-put widget
:custom-form form
)
2600 (widget-put widget
:children children
)
2601 ;; Now update the state.
2602 (if (eq state
'hidden
)
2603 (widget-put widget
:custom-state state
)
2604 (custom-variable-state-set widget
))
2606 (unless (eq state
'hidden
)
2607 (when (eq (widget-get widget
:custom-level
) 1)
2608 (custom-add-parent-links widget
))
2609 (custom-add-see-also widget
)))))
2611 (defun custom-tag-action (widget &rest args
)
2612 "Pass :action to first child of WIDGET's parent."
2613 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2616 (defun custom-tag-mouse-down-action (widget &rest args
)
2617 "Pass :mouse-down-action to first child of WIDGET's parent."
2618 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2619 :mouse-down-action args
))
2621 (defun custom-variable-state-set (widget)
2622 "Set the state of WIDGET."
2623 (let* ((symbol (widget-value widget
))
2624 (get (or (get symbol
'custom-get
) 'default-value
))
2625 (value (if (default-boundp symbol
)
2626 (funcall get symbol
)
2627 (widget-get widget
:value
)))
2628 (comment (get symbol
'variable-comment
))
2631 (state (cond ((progn (setq tmp
(get symbol
'customized-value
))
2633 (get symbol
'customized-variable-comment
))
2635 (if (condition-case nil
2636 (and (equal value
(eval (car tmp
)))
2637 (equal comment temp
))
2641 ((progn (setq tmp
(get symbol
'theme-value
))
2642 (setq temp
(get symbol
'saved-variable-comment
))
2644 (if (condition-case nil
2645 (and (equal comment temp
)
2648 (car (custom-variable-theme-value
2652 ((eq (caar tmp
) 'user
) 'saved
)
2653 ((eq (caar tmp
) 'changed
)
2654 (if (condition-case nil
2658 (car (get symbol
'standard-value
)))))
2660 ;; The value was originally set outside
2661 ;; custom, but it was set to the standard
2662 ;; value (probably an autoloaded defcustom).
2667 ((setq tmp
(get symbol
'standard-value
))
2668 (if (condition-case nil
2669 (and (equal value
(eval (car tmp
)))
2670 (equal comment nil
))
2675 (widget-put widget
:custom-state state
)))
2677 (defun custom-variable-standard-value (widget)
2678 (get (widget-value widget
) 'standard-value
))
2680 (defvar custom-variable-menu
2681 `(("Set for Current Session" custom-variable-set
2683 (eq (widget-get widget
:custom-state
) 'modified
)))
2684 ,@(when (or custom-file user-init-file
)
2685 '(("Save for Future Sessions" custom-variable-save
2687 (memq (widget-get widget
:custom-state
)
2688 '(modified set changed rogue
))))))
2689 ("Undo Edits" custom-redraw
2691 (and (default-boundp (widget-value widget
))
2692 (memq (widget-get widget
:custom-state
) '(modified changed
)))))
2693 ("Reset to Saved" custom-variable-reset-saved
2695 (and (or (get (widget-value widget
) 'saved-value
)
2696 (get (widget-value widget
) 'saved-variable-comment
))
2697 (memq (widget-get widget
:custom-state
)
2698 '(modified set changed rogue
)))))
2699 ,@(when (or custom-file user-init-file
)
2700 '(("Erase Customization" custom-variable-reset-standard
2702 (and (get (widget-value widget
) 'standard-value
)
2703 (memq (widget-get widget
:custom-state
)
2704 '(modified set changed saved rogue
)))))))
2705 ("Set to Backup Value" custom-variable-reset-backup
2707 (get (widget-value widget
) 'backup-value
)))
2708 ("---" ignore ignore
)
2709 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
2710 ("---" ignore ignore
)
2711 ("Show Current Value" custom-variable-edit
2713 (eq (widget-get widget
:custom-form
) 'lisp
)))
2714 ("Show Saved Lisp Expression" custom-variable-edit-lisp
2716 (eq (widget-get widget
:custom-form
) 'edit
))))
2717 "Alist of actions for the `custom-variable' widget.
2718 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2719 the menu entry, ACTION is the function to call on the widget when the
2720 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2721 widget as an argument, and returns non-nil if ACTION is valid on that
2722 widget. If FILTER is nil, ACTION is always valid.")
2724 (defun custom-variable-action (widget &optional event
)
2725 "Show the menu for `custom-variable' WIDGET.
2726 Optional EVENT is the location for the menu."
2727 (if (eq (widget-get widget
:custom-state
) 'hidden
)
2728 (custom-toggle-hide widget
)
2729 (unless (eq (widget-get widget
:custom-state
) 'modified
)
2730 (custom-variable-state-set widget
))
2731 (custom-redraw-magic widget
)
2732 (let* ((completion-ignore-case t
)
2733 (answer (widget-choose (concat "Operation on "
2734 (custom-unlispify-tag-name
2735 (widget-get widget
:value
)))
2736 (custom-menu-filter custom-variable-menu
2740 (funcall answer widget
)))))
2742 (defun custom-variable-edit (widget)
2743 "Edit value of WIDGET."
2744 (widget-put widget
:custom-state
'unknown
)
2745 (widget-put widget
:custom-form
'edit
)
2746 (custom-redraw widget
))
2748 (defun custom-variable-edit-lisp (widget)
2749 "Edit the Lisp representation of the value of WIDGET."
2750 (widget-put widget
:custom-state
'unknown
)
2751 (widget-put widget
:custom-form
'lisp
)
2752 (custom-redraw widget
))
2754 (defun custom-variable-set (widget)
2755 "Set the current value for the variable being edited by WIDGET."
2756 (let* ((form (widget-get widget
:custom-form
))
2757 (state (widget-get widget
:custom-state
))
2758 (child (car (widget-get widget
:children
)))
2759 (symbol (widget-value widget
))
2760 (set (or (get symbol
'custom-set
) 'set-default
))
2761 (comment-widget (widget-get widget
:comment-widget
))
2762 (comment (widget-value comment-widget
))
2764 (cond ((eq state
'hidden
)
2765 (error "Cannot set hidden variable"))
2766 ((setq val
(widget-apply child
:validate
))
2767 (goto-char (widget-get val
:from
))
2768 (error "%s" (widget-get val
:error
)))
2769 ((memq form
'(lisp mismatch
))
2770 (when (equal comment
"")
2772 ;; Make the comment invisible by hand if it's empty
2773 (custom-comment-hide comment-widget
))
2774 (custom-variable-backup-value widget
)
2775 (custom-push-theme 'theme-value symbol
'user
2776 'set
(custom-quote (widget-value child
)))
2777 (funcall set symbol
(eval (setq val
(widget-value child
))))
2778 (put symbol
'customized-value
(list val
))
2779 (put symbol
'variable-comment comment
)
2780 (put symbol
'customized-variable-comment comment
))
2782 (when (equal comment
"")
2784 ;; Make the comment invisible by hand if it's empty
2785 (custom-comment-hide comment-widget
))
2786 (custom-variable-backup-value widget
)
2787 (custom-push-theme 'theme-value symbol
'user
2788 'set
(custom-quote (widget-value child
)))
2789 (funcall set symbol
(setq val
(widget-value child
)))
2790 (put symbol
'customized-value
(list (custom-quote val
)))
2791 (put symbol
'variable-comment comment
)
2792 (put symbol
'customized-variable-comment comment
)))
2793 (custom-variable-state-set widget
)
2794 (custom-redraw-magic widget
)))
2796 (defun custom-variable-save (widget)
2797 "Set and save the value for the variable being edited by WIDGET."
2798 (let* ((form (widget-get widget
:custom-form
))
2799 (state (widget-get widget
:custom-state
))
2800 (child (car (widget-get widget
:children
)))
2801 (symbol (widget-value widget
))
2802 (set (or (get symbol
'custom-set
) 'set-default
))
2803 (comment-widget (widget-get widget
:comment-widget
))
2804 (comment (widget-value comment-widget
))
2806 (cond ((eq state
'hidden
)
2807 (error "Cannot set hidden variable"))
2808 ((setq val
(widget-apply child
:validate
))
2809 (goto-char (widget-get val
:from
))
2810 (error "Saving %s: %s" symbol
(widget-get val
:error
)))
2811 ((memq form
'(lisp mismatch
))
2812 (when (equal comment
"")
2814 ;; Make the comment invisible by hand if it's empty
2815 (custom-comment-hide comment-widget
))
2816 (put symbol
'saved-value
(list (widget-value child
)))
2817 (custom-push-theme 'theme-value symbol
'user
2818 'set
(custom-quote (widget-value child
)))
2819 (funcall set symbol
(eval (widget-value child
)))
2820 (put symbol
'variable-comment comment
)
2821 (put symbol
'saved-variable-comment comment
))
2823 (when (equal comment
"")
2825 ;; Make the comment invisible by hand if it's empty
2826 (custom-comment-hide comment-widget
))
2827 (put symbol
'saved-value
2828 (list (custom-quote (widget-value child
))))
2829 (custom-push-theme 'theme-value symbol
'user
2830 'set
(custom-quote (widget-value child
)))
2831 (funcall set symbol
(widget-value child
))
2832 (put symbol
'variable-comment comment
)
2833 (put symbol
'saved-variable-comment comment
)))
2834 (put symbol
'customized-value nil
)
2835 (put symbol
'customized-variable-comment nil
)
2837 (custom-variable-state-set widget
)
2838 (custom-redraw-magic widget
)))
2840 (defun custom-variable-reset-saved (widget)
2841 "Restore the saved value for the variable being edited by WIDGET.
2842 This also updates the buffer to show that value.
2843 The value that was current before this operation
2844 becomes the backup value, so you can get it again."
2845 (let* ((symbol (widget-value widget
))
2846 (set (or (get symbol
'custom-set
) 'set-default
))
2847 (value (get symbol
'saved-value
))
2848 (comment (get symbol
'saved-variable-comment
)))
2849 (cond ((or value comment
)
2850 (put symbol
'variable-comment comment
)
2851 (custom-variable-backup-value widget
)
2852 (custom-push-theme 'theme-value symbol
'user
'set
(car-safe value
))
2854 (funcall set symbol
(eval (car value
)))
2857 (error "No saved value for %s" symbol
)))
2858 (put symbol
'customized-value nil
)
2859 (put symbol
'customized-variable-comment nil
)
2860 (widget-put widget
:custom-state
'unknown
)
2861 ;; This call will possibly make the comment invisible
2862 (custom-redraw widget
)))
2864 (defun custom-variable-reset-standard (widget)
2865 "Restore the standard setting for the variable being edited by WIDGET.
2866 This operation eliminates any saved setting for the variable,
2867 restoring it to the state of a variable that has never been customized.
2868 The value that was current before this operation
2869 becomes the backup value, so you can get it again."
2870 (let* ((symbol (widget-value widget
)))
2871 (if (get symbol
'standard-value
)
2872 (custom-variable-backup-value widget
)
2873 (error "No standard setting known for %S" symbol
))
2874 (put symbol
'variable-comment nil
)
2875 (put symbol
'customized-value nil
)
2876 (put symbol
'customized-variable-comment nil
)
2877 (custom-push-theme 'theme-value symbol
'user
'reset
)
2878 (custom-theme-recalc-variable symbol
)
2879 (when (or (get symbol
'saved-value
) (get symbol
'saved-variable-comment
))
2880 (put symbol
'saved-value nil
)
2881 (put symbol
'saved-variable-comment nil
)
2883 (widget-put widget
:custom-state
'unknown
)
2884 ;; This call will possibly make the comment invisible
2885 (custom-redraw widget
)))
2887 (defun custom-variable-backup-value (widget)
2888 "Back up the current value for WIDGET's variable.
2889 The backup value is kept in the car of the `backup-value' property."
2890 (let* ((symbol (widget-value widget
))
2891 (get (or (get symbol
'custom-get
) 'default-value
))
2892 (type (custom-variable-type symbol
))
2893 (conv (widget-convert type
))
2894 (value (if (default-boundp symbol
)
2895 (funcall get symbol
)
2896 (widget-get conv
:value
))))
2897 (put symbol
'backup-value
(list value
))))
2899 (defun custom-variable-reset-backup (widget)
2900 "Restore the backup value for the variable being edited by WIDGET.
2901 The value that was current before this operation
2902 becomes the backup value, so you can use this operation repeatedly
2903 to switch between two values."
2904 (let* ((symbol (widget-value widget
))
2905 (set (or (get symbol
'custom-set
) 'set-default
))
2906 (value (get symbol
'backup-value
))
2907 (comment-widget (widget-get widget
:comment-widget
))
2908 (comment (widget-value comment-widget
)))
2911 (custom-variable-backup-value widget
)
2912 (custom-push-theme 'theme-value symbol
'user
'set value
)
2914 (funcall set symbol
(car value
))
2916 (error "No backup value for %s" symbol
))
2917 (put symbol
'customized-value
(list (car value
)))
2918 (put symbol
'variable-comment comment
)
2919 (put symbol
'customized-variable-comment comment
)
2920 (custom-variable-state-set widget
)
2921 ;; This call will possibly make the comment invisible
2922 (custom-redraw widget
)))
2924 ;;; The `custom-visibility' Widget
2926 (define-widget 'custom-visibility
'visibility
2927 "Show or hide a documentation string."
2928 :button-face
'custom-visibility
2929 :pressed-face
'custom-visibility
2930 :mouse-face
'highlight
2931 :pressed-face
'highlight
)
2933 (defface custom-visibility
2934 '((t :height
0.8 :inherit link
))
2935 "Face for the `custom-visibility' widget."
2937 :group
'custom-faces
)
2939 ;;; The `custom-face-edit' Widget.
2941 (define-widget 'custom-face-edit
'checklist
2942 "Edit face attributes."
2946 :button-args
'(:help-echo
"Control whether this attribute has any effect.")
2947 :value-to-internal
'custom-face-edit-fix-value
2948 :match
(lambda (widget value
)
2949 (widget-checklist-match widget
2950 (custom-face-edit-fix-value widget value
)))
2951 :convert-widget
'custom-face-edit-convert-widget
2952 :args
(mapcar (lambda (att)
2955 :sibling-args
(widget-get (nth 1 att
) :sibling-args
)
2956 (list 'const
:format
"" :value
(nth 0 att
))
2958 custom-face-attributes
))
2960 (defun custom-face-edit-fix-value (widget value
)
2961 "Ignoring WIDGET, convert :bold and :italic in VALUE to new form.
2962 Also change :reverse-video to :inverse-video."
2966 (let ((key (car value
))
2967 (val (car (cdr value
))))
2968 (cond ((eq key
:italic
)
2969 (push :slant result
)
2970 (push (if val
'italic
'normal
) result
))
2972 (push :weight result
)
2973 (push (if val
'bold
'normal
) result
))
2974 ((eq key
:reverse-video
)
2975 (push :inverse-video result
)
2979 (push val result
))))
2980 (setq value
(cdr (cdr value
))))
2981 (setq result
(nreverse result
))
2985 (defun custom-face-edit-convert-widget (widget)
2986 "Convert :args as widget types in WIDGET."
2989 :args
(mapcar (lambda (arg)
2991 :deactivate
'custom-face-edit-deactivate
2992 :activate
'custom-face-edit-activate
2993 :delete
'custom-face-edit-delete
))
2994 (widget-get widget
:args
)))
2997 (defun custom-face-edit-deactivate (widget)
2998 "Make face widget WIDGET inactive for user modifications."
2999 (unless (widget-get widget
:inactive
)
3000 (let ((tag (custom-face-edit-attribute-tag widget
))
3001 (from (copy-marker (widget-get widget
:from
)))
3002 (value (widget-value widget
))
3003 (inhibit-read-only t
)
3004 (inhibit-modification-hooks t
))
3007 (widget-default-delete widget
)
3008 (insert tag
": *\n")
3009 (widget-put widget
:inactive
3010 (cons value
(cons from
(- (point) from
))))))))
3012 (defun custom-face-edit-activate (widget)
3013 "Make face widget WIDGET inactive for user modifications."
3014 (let ((inactive (widget-get widget
:inactive
))
3015 (inhibit-read-only t
)
3016 (inhibit-modification-hooks t
))
3017 (when (consp inactive
)
3019 (goto-char (car (cdr inactive
)))
3020 (delete-region (point) (+ (point) (cdr (cdr inactive
))))
3021 (widget-put widget
:inactive nil
)
3022 (widget-apply widget
:create
)
3023 (widget-value-set widget
(car inactive
))
3026 (defun custom-face-edit-delete (widget)
3027 "Remove WIDGET from the buffer."
3028 (let ((inactive (widget-get widget
:inactive
))
3029 (inhibit-read-only t
)
3030 (inhibit-modification-hooks t
))
3032 ;; Widget is alive, we don't have to do anything special
3033 (widget-default-delete widget
)
3034 ;; WIDGET is already deleted because we did so to inactivate it;
3035 ;; now just get rid of the label we put in its place.
3036 (delete-region (car (cdr inactive
))
3037 (+ (car (cdr inactive
)) (cdr (cdr inactive
))))
3038 (widget-put widget
:inactive nil
))))
3041 (defun custom-face-edit-attribute-tag (widget)
3042 "Returns the first :tag property in WIDGET or one of its children."
3043 (let ((tag (widget-get widget
:tag
)))
3044 (or (and (not (equal tag
"")) tag
)
3045 (let ((children (widget-get widget
:children
)))
3046 (while (and (null tag
) children
)
3047 (setq tag
(custom-face-edit-attribute-tag (pop children
))))
3050 ;;; The `custom-display' Widget.
3052 (define-widget 'custom-display
'menu-choice
3053 "Select a display type."
3056 :help-echo
"Specify frames where the face attributes should be used."
3057 :args
'((const :tag
"all" t
)
3058 (const :tag
"defaults" default
)
3062 :args
((group :sibling-args
(:help-echo
"\
3063 Only match the specified window systems.")
3064 (const :format
"Type: "
3066 (checklist :inline t
3069 :sibling-args
(:help-echo
"\
3070 The X11 Window System.")
3072 (const :format
"PM "
3073 :sibling-args
(:help-echo
"\
3074 OS/2 Presentation Manager.")
3076 (const :format
"W32 "
3077 :sibling-args
(:help-echo
"\
3080 (const :format
"MAC "
3081 :sibling-args
(:help-echo
"\
3084 (const :format
"DOS "
3085 :sibling-args
(:help-echo
"\
3088 (const :format
"TTY%n"
3089 :sibling-args
(:help-echo
"\
3090 Plain text terminals.")
3092 (group :sibling-args
(:help-echo
"\
3093 Only match the frames with the specified color support.")
3094 (const :format
"Class: "
3096 (checklist :inline t
3098 (const :format
"Color "
3099 :sibling-args
(:help-echo
"\
3100 Match color frames.")
3102 (const :format
"Grayscale "
3103 :sibling-args
(:help-echo
"\
3104 Match grayscale frames.")
3106 (const :format
"Monochrome%n"
3107 :sibling-args
(:help-echo
"\
3108 Match frames with no color support.")
3110 (group :sibling-args
(:help-echo
"\
3111 The minimum number of colors the frame should support.")
3112 (const :format
"" min-colors
)
3113 (integer :tag
"Minimum number of colors" ))
3114 (group :sibling-args
(:help-echo
"\
3115 Only match frames with the specified intensity.")
3117 Background brightness: "
3119 (checklist :inline t
3121 (const :format
"Light "
3122 :sibling-args
(:help-echo
"\
3123 Match frames with light backgrounds.")
3125 (const :format
"Dark\n"
3126 :sibling-args
(:help-echo
"\
3127 Match frames with dark backgrounds.")
3129 (group :sibling-args
(:help-echo
"\
3130 Only match frames that support the specified face attributes.")
3131 (const :format
"Supports attributes:" supports
)
3132 (custom-face-edit :inline t
:format
"%n%v"))))))
3134 ;;; The `custom-face' Widget.
3136 (defface custom-face-tag
3137 `((t (:weight bold
:height
1.2 :inherit variable-pitch
)))
3138 "Face used for face tags."
3139 :group
'custom-faces
)
3140 ;; backward-compatibility alias
3141 (put 'custom-face-tag-face
'face-alias
'custom-face-tag
)
3143 (defcustom custom-face-default-form
'selected
3144 "Default form of displaying face definition."
3145 :type
'(choice (const all
)
3148 :group
'custom-buffer
3151 (define-widget 'custom-face
'custom
3153 :sample-face
'custom-face-tag-face
3154 :help-echo
"Set or reset this face."
3155 :documentation-property
#'face-doc-string
3156 :value-create
'custom-face-value-create
3157 :action
'custom-face-action
3158 :custom-category
'face
3159 :custom-form nil
; defaults to value of `custom-face-default-form'
3160 :custom-set
'custom-face-set
3161 :custom-save
'custom-face-save
3162 :custom-reset-current
'custom-redraw
3163 :custom-reset-saved
'custom-face-reset-saved
3164 :custom-reset-standard
'custom-face-reset-standard
3165 :custom-standard-value
'custom-face-standard-value
3166 :custom-menu
'custom-face-menu-create
)
3168 (define-widget 'custom-face-all
'editable-list
3169 "An editable list of display specifications and attributes."
3170 :entry-format
"%i %d %v"
3171 :insert-button-args
'(:help-echo
"Insert new display specification here.")
3172 :append-button-args
'(:help-echo
"Append new display specification here.")
3173 :delete-button-args
'(:help-echo
"Delete this display specification.")
3174 :args
'((group :format
"%v" custom-display custom-face-edit
)))
3176 (defconst custom-face-all
(widget-convert 'custom-face-all
)
3177 "Converted version of the `custom-face-all' widget.")
3179 (define-widget 'custom-display-unselected
'item
3180 "A display specification that doesn't match the selected display."
3181 :match
'custom-display-unselected-match
)
3183 (defun custom-display-unselected-match (widget value
)
3184 "Non-nil if VALUE is an unselected display specification."
3185 (not (face-spec-set-match-display value
(selected-frame))))
3187 (define-widget 'custom-face-selected
'group
3188 "Edit the attributes of the selected display in a face specification."
3189 :args
'((choice :inline t
3190 (group :tag
"With Defaults" :inline t
3191 (group (const :tag
"" default
)
3192 (custom-face-edit :tag
" Default\n Attributes"))
3195 (group custom-display-unselected sexp
))
3196 (group (sexp :format
"")
3197 (custom-face-edit :tag
" Overriding\n Attributes"))
3201 (group :tag
"No Defaults" :inline t
3204 (group custom-display-unselected sexp
))
3205 (group (sexp :format
"")
3206 (custom-face-edit :tag
"\n Attributes"))
3213 (defconst custom-face-selected
(widget-convert 'custom-face-selected
)
3214 "Converted version of the `custom-face-selected' widget.")
3216 (defun custom-filter-face-spec (spec filter-index
&optional default-filter
)
3217 "Return a canonicalized version of SPEC using.
3218 FILTER-INDEX is the index in the entry for each attribute in
3219 `custom-face-attributes' at which the appropriate filter function can be
3220 found, and DEFAULT-FILTER is the filter to apply for attributes that
3222 (mapcar (lambda (entry)
3223 ;; Filter a single face-spec entry
3224 (let ((tests (car entry
))
3226 ;; Handle both old- and new-style attribute syntax
3227 (if (listp (car (cdr entry
)))
3230 (filtered-attrs nil
))
3231 ;; Filter each face attribute
3232 (while unfiltered-attrs
3233 (let* ((attr (pop unfiltered-attrs
))
3234 (pre-filtered-value (pop unfiltered-attrs
))
3236 (or (nth filter-index
(assq attr custom-face-attributes
))
3240 (funcall filter pre-filtered-value
)
3241 pre-filtered-value
)))
3242 (push filtered-value filtered-attrs
)
3243 (push attr filtered-attrs
)))
3245 (list tests filtered-attrs
)))
3248 (defun custom-pre-filter-face-spec (spec)
3249 "Return SPEC changed as necessary for editing by the face customization widget.
3250 SPEC must be a full face spec."
3251 (custom-filter-face-spec spec
2))
3253 (defun custom-post-filter-face-spec (spec)
3254 "Return the customized SPEC in a form suitable for setting the face."
3255 (custom-filter-face-spec spec
3))
3257 (defun custom-face-value-create (widget)
3258 "Create a list of the display specifications for WIDGET."
3259 (let ((buttons (widget-get widget
:buttons
))
3261 (symbol (widget-get widget
:value
))
3262 (tag (widget-get widget
:tag
))
3263 (state (widget-get widget
:custom-state
))
3265 (is-last (widget-get widget
:custom-last
))
3266 (prefix (widget-get widget
:custom-prefix
)))
3268 (setq tag
(prin1-to-string symbol
)))
3269 (cond ((eq custom-buffer-style
'tree
)
3270 (insert prefix
(if is-last
" `--- " " |--- "))
3271 (push (widget-create-child-and-convert
3272 widget
'custom-browse-face-tag
)
3274 (insert " " tag
"\n")
3275 (widget-put widget
:buttons buttons
))
3279 (widget-specify-sample widget begin
(point))
3280 (if (eq custom-buffer-style
'face
)
3282 (if (string-match "face\\'" tag
)
3284 (insert " face: ")))
3286 (push (widget-create-child-and-convert widget
'item
3293 (push (widget-create-child-and-convert
3295 :help-echo
"Hide or show this face."
3298 :action
'custom-toggle-parent
3299 (not (eq state
'hidden
)))
3303 (let ((magic (widget-create-child-and-convert
3304 widget
'custom-magic nil
)))
3305 (widget-put widget
:custom-magic magic
)
3306 (push magic buttons
))
3308 (widget-put widget
:buttons buttons
)
3309 ;; Insert documentation.
3310 (widget-add-documentation-string-button
3311 widget
:visibility-widget
'custom-visibility
)
3313 ;; The comment field
3314 (unless (eq state
'hidden
)
3315 (let* ((comment (get symbol
'face-comment
))
3317 (widget-create-child-and-convert
3318 widget
'custom-comment
3320 :value
(or comment
""))))
3321 (widget-put widget
:comment-widget comment-widget
)
3322 (push comment-widget children
)))
3324 (unless (eq state
'hidden
)
3325 (when (eq (widget-get widget
:custom-level
) 1)
3326 (custom-add-parent-links widget
))
3327 (custom-add-see-also widget
))
3329 (unless (eq (preceding-char) ?
\n)
3331 (unless (eq state
'hidden
)
3332 (message "Creating face editor...")
3333 (custom-load-widget widget
)
3334 (unless (widget-get widget
:custom-form
)
3335 (widget-put widget
:custom-form custom-face-default-form
))
3336 (let* ((symbol (widget-value widget
))
3337 (spec (or (get symbol
'customized-face
)
3338 (get symbol
'saved-face
)
3339 (get symbol
'face-defface-spec
)
3340 ;; Attempt to construct it.
3341 (list (list t
(custom-face-attributes-get
3342 symbol
(selected-frame))))))
3343 (form (widget-get widget
:custom-form
))
3344 (indent (widget-get widget
:indent
))
3346 ;; If the user has changed this face in some other way,
3347 ;; edit it as the user has specified it.
3348 (if (not (face-spec-match-p symbol spec
(selected-frame)))
3349 (setq spec
(list (list t
(face-attr-construct symbol
(selected-frame))))))
3350 (setq spec
(custom-pre-filter-face-spec spec
))
3351 (setq edit
(widget-create-child-and-convert
3353 (cond ((and (eq form
'selected
)
3354 (widget-apply custom-face-selected
3356 (when indent
(insert-char ?\ indent
))
3357 'custom-face-selected
)
3358 ((and (not (eq form
'lisp
))
3359 (widget-apply custom-face-all
3363 (when indent
(insert-char ?\ indent
))
3366 (custom-face-state-set widget
)
3367 (push edit children
)
3368 (widget-put widget
:children children
))
3369 (message "Creating face editor...done"))))))
3371 (defvar custom-face-menu
3372 `(("Set for Current Session" custom-face-set
)
3373 ,@(when (or custom-file user-init-file
)
3374 '(("Save for Future Sessions" custom-face-save
)))
3375 ("Undo Edits" custom-redraw
3377 (memq (widget-get widget
:custom-state
) '(modified changed
))))
3378 ("Reset to Saved" custom-face-reset-saved
3380 (or (get (widget-value widget
) 'saved-face
)
3381 (get (widget-value widget
) 'saved-face-comment
))))
3382 ,@(when (or custom-file user-init-file
)
3383 '(("Erase Customization" custom-face-reset-standard
3385 (get (widget-value widget
) 'face-defface-spec
)))))
3386 ("---" ignore ignore
)
3387 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
3388 ("---" ignore ignore
)
3389 ("For Current Display" custom-face-edit-selected
3391 (not (eq (widget-get widget
:custom-form
) 'selected
))))
3392 ("For All Kinds of Displays" custom-face-edit-all
3394 (not (eq (widget-get widget
:custom-form
) 'all
))))
3395 ("Show Lisp Expression" custom-face-edit-lisp
3397 (not (eq (widget-get widget
:custom-form
) 'lisp
)))))
3398 "Alist of actions for the `custom-face' widget.
3399 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3400 the menu entry, ACTION is the function to call on the widget when the
3401 menu is selected, and FILTER is a predicate which takes a `custom-face'
3402 widget as an argument, and returns non-nil if ACTION is valid on that
3403 widget. If FILTER is nil, ACTION is always valid.")
3405 (defun custom-face-edit-selected (widget)
3406 "Edit selected attributes of the value of WIDGET."
3407 (widget-put widget
:custom-state
'unknown
)
3408 (widget-put widget
:custom-form
'selected
)
3409 (custom-redraw widget
))
3411 (defun custom-face-edit-all (widget)
3412 "Edit all attributes of the value of WIDGET."
3413 (widget-put widget
:custom-state
'unknown
)
3414 (widget-put widget
:custom-form
'all
)
3415 (custom-redraw widget
))
3417 (defun custom-face-edit-lisp (widget)
3418 "Edit the Lisp representation of the value of WIDGET."
3419 (widget-put widget
:custom-state
'unknown
)
3420 (widget-put widget
:custom-form
'lisp
)
3421 (custom-redraw widget
))
3423 (defun custom-face-state-set (widget)
3424 "Set the state of WIDGET."
3425 (let* ((symbol (widget-value widget
))
3426 (comment (get symbol
'face-comment
))
3430 (setq tmp
(get symbol
'customized-face
))
3431 (setq temp
(get symbol
'customized-face-comment
))
3433 (if (equal temp comment
)
3437 (setq tmp
(get symbol
'saved-face
))
3438 (setq temp
(get symbol
'saved-face-comment
))
3440 (if (equal temp comment
)
3442 ((eq 'user
(caar (get symbol
'theme-face
)))
3444 ((eq 'changed
(caar (get symbol
'theme-face
)))
3448 ((get symbol
'face-defface-spec
)
3449 (if (equal comment nil
)
3454 ;; If the user called set-face-attribute to change the default
3455 ;; for new frames, this face is "set outside of Customize".
3456 (if (and (not (eq state
'rogue
))
3457 (get symbol
'face-modified
))
3458 (setq state
'changed
))
3459 (widget-put widget
:custom-state state
)))
3461 (defun custom-face-action (widget &optional event
)
3462 "Show the menu for `custom-face' WIDGET.
3463 Optional EVENT is the location for the menu."
3464 (if (eq (widget-get widget
:custom-state
) 'hidden
)
3465 (custom-toggle-hide widget
)
3466 (let* ((completion-ignore-case t
)
3467 (symbol (widget-get widget
:value
))
3468 (answer (widget-choose (concat "Operation on "
3469 (custom-unlispify-tag-name symbol
))
3470 (custom-menu-filter custom-face-menu
3474 (funcall answer widget
)))))
3476 (defun custom-face-set (widget)
3477 "Make the face attributes in WIDGET take effect."
3478 (let* ((symbol (widget-value widget
))
3479 (child (car (widget-get widget
:children
)))
3480 (value (custom-post-filter-face-spec (widget-value child
)))
3481 (comment-widget (widget-get widget
:comment-widget
))
3482 (comment (widget-value comment-widget
)))
3483 (when (equal comment
"")
3485 ;; Make the comment invisible by hand if it's empty
3486 (custom-comment-hide comment-widget
))
3487 (put symbol
'customized-face value
)
3488 (custom-push-theme 'theme-face symbol
'user
'set value
)
3489 (if (face-spec-choose value
)
3490 (face-spec-set symbol value
)
3491 ;; face-set-spec ignores empty attribute lists, so just give it
3492 ;; something harmless instead.
3493 (face-spec-set symbol
'((t :foreground unspecified
))))
3494 (put symbol
'customized-face-comment comment
)
3495 (put symbol
'face-comment comment
)
3496 (custom-face-state-set widget
)
3497 (custom-redraw-magic widget
)))
3499 (defun custom-face-save (widget)
3500 "Save in `.emacs' the face attributes in WIDGET."
3501 (let* ((symbol (widget-value widget
))
3502 (child (car (widget-get widget
:children
)))
3503 (value (custom-post-filter-face-spec (widget-value child
)))
3504 (comment-widget (widget-get widget
:comment-widget
))
3505 (comment (widget-value comment-widget
)))
3506 (when (equal comment
"")
3508 ;; Make the comment invisible by hand if it's empty
3509 (custom-comment-hide comment-widget
))
3510 (custom-push-theme 'theme-face symbol
'user
'set value
)
3511 (if (face-spec-choose value
)
3512 (face-spec-set symbol value
)
3513 ;; face-set-spec ignores empty attribute lists, so just give it
3514 ;; something harmless instead.
3515 (face-spec-set symbol
'((t :foreground unspecified
))))
3516 (unless (eq (widget-get widget
:custom-state
) 'standard
)
3517 (put symbol
'saved-face value
))
3518 (put symbol
'customized-face nil
)
3519 (put symbol
'face-comment comment
)
3520 (put symbol
'customized-face-comment nil
)
3521 (put symbol
'saved-face-comment comment
)
3523 (custom-face-state-set widget
)
3524 (custom-redraw-magic widget
)))
3526 ;; For backward compatibility.
3527 (define-obsolete-function-alias 'custom-face-save-command
'custom-face-save
3530 (defun custom-face-reset-saved (widget)
3531 "Restore WIDGET to the face's default attributes."
3532 (let* ((symbol (widget-value widget
))
3533 (child (car (widget-get widget
:children
)))
3534 (value (get symbol
'saved-face
))
3535 (comment (get symbol
'saved-face-comment
))
3536 (comment-widget (widget-get widget
:comment-widget
)))
3537 (unless (or value comment
)
3538 (error "No saved value for this face"))
3539 (put symbol
'customized-face nil
)
3540 (put symbol
'customized-face-comment nil
)
3541 (custom-push-theme 'theme-face symbol
'user
'set value
)
3542 (face-spec-set symbol value
)
3543 (put symbol
'face-comment comment
)
3544 (widget-value-set child value
)
3545 ;; This call manages the comment visibility
3546 (widget-value-set comment-widget
(or comment
""))
3547 (custom-face-state-set widget
)
3548 (custom-redraw-magic widget
)))
3550 (defun custom-face-standard-value (widget)
3551 (get (widget-value widget
) 'face-defface-spec
))
3553 (defun custom-face-reset-standard (widget)
3554 "Restore WIDGET to the face's standard attribute values.
3555 This operation eliminates any saved attributes for the face,
3556 restoring it to the state of a face that has never been customized."
3557 (let* ((symbol (widget-value widget
))
3558 (child (car (widget-get widget
:children
)))
3559 (value (get symbol
'face-defface-spec
))
3560 (comment-widget (widget-get widget
:comment-widget
)))
3562 (error "No standard setting for this face"))
3563 (put symbol
'customized-face nil
)
3564 (put symbol
'customized-face-comment nil
)
3565 (custom-push-theme 'theme-face symbol
'user
'reset
)
3566 (face-spec-set symbol value
)
3567 (custom-theme-recalc-face symbol
)
3568 (when (or (get symbol
'saved-face
) (get symbol
'saved-face-comment
))
3569 (put symbol
'saved-face nil
)
3570 (put symbol
'saved-face-comment nil
)
3572 (put symbol
'face-comment nil
)
3573 (widget-value-set child
3574 (custom-pre-filter-face-spec
3575 (list (list t
(custom-face-attributes-get
3577 ;; This call manages the comment visibility
3578 (widget-value-set comment-widget
"")
3579 (custom-face-state-set widget
)
3580 (custom-redraw-magic widget
)))
3582 ;;; The `face' Widget.
3584 (defvar widget-face-prompt-value-history nil
3585 "History of input to `widget-face-prompt-value'.")
3587 (define-widget 'face
'symbol
3588 "A Lisp face name (with sample)."
3589 :format
"%{%t%}: (%{sample%}) %v"
3592 :sample-face-get
'widget-face-sample-face-get
3593 :notify
'widget-face-notify
3594 :match
(lambda (widget value
) (facep value
))
3595 :complete-function
(lambda ()
3597 (lisp-complete-symbol 'facep
))
3598 :prompt-match
'facep
3599 :prompt-history
'widget-face-prompt-value-history
3600 :validate
(lambda (widget)
3601 (unless (facep (widget-value widget
))
3603 :error
(format "Invalid face: %S"
3604 (widget-value widget
)))
3607 (defun widget-face-sample-face-get (widget)
3608 (let ((value (widget-value widget
)))
3613 (defun widget-face-notify (widget child
&optional event
)
3614 "Update the sample, and notify the parent."
3615 (overlay-put (widget-get widget
:sample-overlay
)
3616 'face
(widget-apply widget
:sample-face-get
))
3617 (widget-default-notify widget child event
))
3620 ;;; The `hook' Widget.
3622 (define-widget 'hook
'list
3623 "An Emacs Lisp hook."
3624 :value-to-internal
(lambda (widget value
)
3625 (if (and value
(symbolp value
))
3628 :match
(lambda (widget value
)
3630 (widget-group-match widget value
)))
3631 ;; Avoid adding undefined functions to the hook, especially for
3632 ;; things like `find-file-hook' or even more basic ones, to avoid
3634 :set
(lambda (symbol value
)
3637 (add-hook symbol elt
))))
3638 :convert-widget
'custom-hook-convert-widget
3641 (defun custom-hook-convert-widget (widget)
3642 ;; Handle `:options'.
3643 (let* ((options (widget-get widget
:options
))
3644 (other `(editable-list :inline t
3645 :entry-format
"%i %d%v"
3646 (function :format
" %v")))
3648 (list `(checklist :inline t
3649 ,@(mapcar (lambda (entry)
3650 `(function-item ,entry
))
3654 (widget-put widget
:args args
)
3657 ;;; The `custom-group-link' Widget.
3659 (define-widget 'custom-group-link
'link
3660 "Show parent in other window when activated."
3661 :button-face
'custom-link
3662 :mouse-face
'highlight
3663 :pressed-face
'highlight
3664 :help-echo
"Create customization buffer for this group."
3665 :keymap custom-mode-link-map
3666 :follow-link
'mouse-face
3667 :action
'custom-group-link-action
)
3669 (defun custom-group-link-action (widget &rest ignore
)
3670 (customize-group (widget-value widget
)))
3672 ;;; The `custom-group' Widget.
3674 (defcustom custom-group-tag-faces nil
3675 ;; In XEmacs, this ought to play games with font size.
3676 ;; Fixme: make it do so in Emacs.
3677 "Face used for group tags.
3678 The first member is used for level 1 groups, the second for level 2,
3679 and so forth. The remaining group tags are shown with `custom-group-tag'."
3680 :type
'(repeat face
)
3681 :group
'custom-faces
)
3683 (defface custom-group-tag-1
3686 (:foreground
"pink" :weight bold
:height
1.2 :inherit variable-pitch
))
3687 (((min-colors 88) (class color
)
3689 (:foreground
"red1" :weight bold
:height
1.2 :inherit variable-pitch
))
3692 (:foreground
"red" :weight bold
:height
1.2 :inherit variable-pitch
))
3694 "Face used for group tags."
3695 :group
'custom-faces
)
3696 ;; backward-compatibility alias
3697 (put 'custom-group-tag-face-1
'face-alias
'custom-group-tag-1
)
3699 (defface custom-group-tag
3702 (:foreground
"light blue" :weight bold
:height
1.2 :inherit variable-pitch
))
3703 (((min-colors 88) (class color
)
3705 (:foreground
"blue1" :weight bold
:height
1.2 :inherit variable-pitch
))
3708 (:foreground
"blue" :weight bold
:height
1.2 :inherit variable-pitch
))
3710 "Face used for low level group tags."
3711 :group
'custom-faces
)
3712 ;; backward-compatibility alias
3713 (put 'custom-group-tag-face
'face-alias
'custom-group-tag
)
3715 (define-widget 'custom-group
'custom
3718 :sample-face-get
'custom-group-sample-face-get
3719 :documentation-property
'group-documentation
3720 :help-echo
"Set or reset all members of this group."
3721 :value-create
'custom-group-value-create
3722 :action
'custom-group-action
3723 :custom-category
'group
3724 :custom-set
'custom-group-set
3725 :custom-save
'custom-group-save
3726 :custom-reset-current
'custom-group-reset-current
3727 :custom-reset-saved
'custom-group-reset-saved
3728 :custom-reset-standard
'custom-group-reset-standard
3729 :custom-menu
'custom-group-menu-create
)
3731 (defun custom-group-sample-face-get (widget)
3732 ;; Use :sample-face.
3733 (or (nth (1- (widget-get widget
:custom-level
)) custom-group-tag-faces
)
3736 (define-widget 'custom-group-visibility
'visibility
3737 "An indicator and manipulator for hidden group contents."
3738 :create
'custom-group-visibility-create
)
3740 (defun custom-group-visibility-create (widget)
3741 (let ((visible (widget-value widget
)))
3743 (insert "--------")))
3744 (widget-default-create widget
))
3746 (defun custom-group-members (symbol groups-only
)
3747 "Return SYMBOL's custom group members.
3748 If GROUPS-ONLY non-nil, return only those members that are groups."
3749 (if (not groups-only
)
3750 (get symbol
'custom-group
)
3752 (dolist (entry (get symbol
'custom-group
))
3753 (when (eq (nth 1 entry
) 'custom-group
)
3754 (push entry members
)))
3755 (nreverse members
))))
3757 (defun custom-group-value-create (widget)
3758 "Insert a customize group for WIDGET in the current buffer."
3759 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
3760 (custom-load-widget widget
))
3761 (let* ((state (widget-get widget
:custom-state
))
3762 (level (widget-get widget
:custom-level
))
3763 ;; (indent (widget-get widget :indent))
3764 (prefix (widget-get widget
:custom-prefix
))
3765 (buttons (widget-get widget
:buttons
))
3766 (tag (widget-get widget
:tag
))
3767 (symbol (widget-value widget
))
3768 (members (custom-group-members symbol
3769 (and (eq custom-buffer-style
'tree
)
3770 custom-browse-only-groups
))))
3771 (cond ((and (eq custom-buffer-style
'tree
)
3773 (or members
(custom-unloaded-widget-p widget
)))
3774 (custom-browse-insert-prefix prefix
)
3775 (push (widget-create-child-and-convert
3776 widget
'custom-browse-visibility
3777 ;; :tag-glyph "plus"
3781 ;; (widget-glyph-insert nil "-- " "horizontal")
3782 (push (widget-create-child-and-convert
3783 widget
'custom-browse-group-tag
)
3785 (insert " " tag
"\n")
3786 (widget-put widget
:buttons buttons
))
3787 ((and (eq custom-buffer-style
'tree
)
3788 (zerop (length members
)))
3789 (custom-browse-insert-prefix prefix
)
3791 ;; (widget-glyph-insert nil "[ ]" "empty")
3792 ;; (widget-glyph-insert nil "-- " "horizontal")
3793 (push (widget-create-child-and-convert
3794 widget
'custom-browse-group-tag
)
3796 (insert " " tag
"\n")
3797 (widget-put widget
:buttons buttons
))
3798 ((eq custom-buffer-style
'tree
)
3799 (custom-browse-insert-prefix prefix
)
3800 (if (zerop (length members
))
3802 (custom-browse-insert-prefix prefix
)
3804 ;; (widget-glyph-insert nil "[ ]" "empty")
3805 ;; (widget-glyph-insert nil "-- " "horizontal")
3806 (push (widget-create-child-and-convert
3807 widget
'custom-browse-group-tag
)
3809 (insert " " tag
"\n")
3810 (widget-put widget
:buttons buttons
))
3811 (push (widget-create-child-and-convert
3812 widget
'custom-browse-visibility
3813 ;; :tag-glyph "minus"
3817 ;; (widget-glyph-insert nil "-\\ " "top")
3818 (push (widget-create-child-and-convert
3819 widget
'custom-browse-group-tag
)
3821 (insert " " tag
"\n")
3822 (widget-put widget
:buttons buttons
)
3823 (message "Creating group...")
3824 (let* ((members (custom-sort-items members
3825 custom-browse-sort-alphabetically
3826 custom-browse-order-groups
))
3827 (prefixes (widget-get widget
:custom-prefixes
))
3828 (custom-prefix-list (custom-prefix-add symbol prefixes
))
3829 (extra-prefix (if (widget-get widget
:custom-last
)
3832 (prefix (concat prefix extra-prefix
))
3835 (setq entry
(car members
)
3836 members
(cdr members
))
3837 (push (widget-create-child-and-convert
3838 widget
(nth 1 entry
)
3840 :tag
(custom-unlispify-tag-name (nth 0 entry
))
3841 :custom-prefixes custom-prefix-list
3842 :custom-level
(1+ level
)
3843 :custom-last
(null members
)
3844 :value
(nth 0 entry
)
3845 :custom-prefix prefix
)
3847 (widget-put widget
:children
(reverse children
)))
3848 (message "Creating group...done")))
3851 ;; Create level indicator.
3853 (if (eq custom-buffer-style
'links
)
3854 (push (widget-create-child-and-convert
3855 widget
'custom-group-link
3859 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3861 (push (widget-create-child-and-convert
3862 widget
'custom-group-visibility
3863 :help-echo
"Show members of this group."
3864 :action
'custom-toggle-parent
3865 (not (eq state
'hidden
)))
3868 ;; Create magic button.
3869 (let ((magic (widget-create-child-and-convert
3870 widget
'custom-magic nil
)))
3871 (widget-put widget
:custom-magic magic
)
3872 (push magic buttons
))
3874 (widget-put widget
:buttons buttons
)
3875 ;; Insert documentation.
3876 (if (and (eq custom-buffer-style
'links
) (> level
1))
3877 (widget-put widget
:documentation-indent
0))
3878 (widget-add-documentation-string-button
3879 widget
:visibility-widget
'custom-visibility
))
3883 ;; Add parent groups references above the group.
3884 (if t
;;; This should test that the buffer
3885 ;;; was made to display a group.
3887 (if (custom-add-parent-links widget
3890 ;; Create level indicator.
3891 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3894 (let ((start (point)))
3895 (insert tag
" group: ")
3896 (widget-specify-sample widget start
(point)))
3897 (insert (widget-docstring widget
))
3898 ;; Create visibility indicator.
3899 (unless (eq custom-buffer-style
'links
)
3901 (push (widget-create-child-and-convert
3903 :help-echo
"Hide members of this group."
3904 :action
'custom-toggle-parent
3905 (not (eq state
'hidden
)))
3908 ;; Create more dashes.
3909 ;; Use 76 instead of 75 to compensate for the temporary "<"
3910 ;; added by `widget-insert'.
3911 (insert-char ?-
(- 76 (current-column)
3912 (* custom-buffer-indent level
)))
3914 ;; Create magic button.
3915 (let ((magic (widget-create-child-and-convert
3916 widget
'custom-magic
3919 (widget-put widget
:custom-magic magic
)
3920 (push magic buttons
))
3922 (widget-put widget
:buttons buttons
)
3923 ;; Insert documentation.
3924 (widget-add-documentation-string-button
3925 widget
:visibility-widget
'custom-visibility
)
3928 (if nil
;;; This should test that the buffer
3929 ;;; was not made to display a group.
3931 (insert-char ?\ custom-buffer-indent
)
3932 (custom-add-parent-links widget
)))
3933 (custom-add-see-also widget
3934 (make-string (* custom-buffer-indent level
)
3937 (message "Creating group...")
3938 (let* ((members (custom-sort-items members
3939 custom-buffer-sort-alphabetically
3940 custom-buffer-order-groups
))
3941 (prefixes (widget-get widget
:custom-prefixes
))
3942 (custom-prefix-list (custom-prefix-add symbol prefixes
))
3943 (length (length members
))
3945 (children (mapcar (lambda (entry)
3946 (widget-insert "\n")
3948 Creating group members... %2d%%"
3949 (/ (* 100.0 count
) length
))
3950 (setq count
(1+ count
))
3952 (widget-create-child-and-convert
3953 widget
(nth 1 entry
)
3955 :tag
(custom-unlispify-tag-name
3957 :custom-prefixes custom-prefix-list
3958 :custom-level
(1+ level
)
3959 :value
(nth 0 entry
))
3960 (unless (eq (preceding-char) ?
\n)
3961 (widget-insert "\n"))))
3963 (message "Creating group magic...")
3964 (mapc 'custom-magic-reset children
)
3965 (message "Creating group state...")
3966 (widget-put widget
:children children
)
3967 (custom-group-state-update widget
)
3968 (message "Creating group... done"))
3971 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3972 (insert "\\- " (widget-get widget
:tag
) " group end ")
3973 (insert-char ?-
(- 75 (current-column) (* custom-buffer-indent level
)))
3976 (defvar custom-group-menu
3977 `(("Set for Current Session" custom-group-set
3979 (eq (widget-get widget
:custom-state
) 'modified
)))
3980 ,@(when (or custom-file user-init-file
)
3981 '(("Save for Future Sessions" custom-group-save
3983 (memq (widget-get widget
:custom-state
) '(modified set
))))))
3984 ("Undo Edits" custom-group-reset-current
3986 (memq (widget-get widget
:custom-state
) '(modified))))
3987 ("Reset to Saved" custom-group-reset-saved
3989 (memq (widget-get widget
:custom-state
) '(modified set
))))
3990 ,@(when (or custom-file user-init-file
)
3991 '(("Erase Customization" custom-group-reset-standard
3993 (memq (widget-get widget
:custom-state
) '(modified set saved
)))))))
3994 "Alist of actions for the `custom-group' widget.
3995 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3996 the menu entry, ACTION is the function to call on the widget when the
3997 menu is selected, and FILTER is a predicate which takes a `custom-group'
3998 widget as an argument, and returns non-nil if ACTION is valid on that
3999 widget. If FILTER is nil, ACTION is always valid.")
4001 (defun custom-group-action (widget &optional event
)
4002 "Show the menu for `custom-group' WIDGET.
4003 Optional EVENT is the location for the menu."
4004 (if (eq (widget-get widget
:custom-state
) 'hidden
)
4005 (custom-toggle-hide widget
)
4006 (let* ((completion-ignore-case t
)
4007 (answer (widget-choose (concat "Operation on "
4008 (custom-unlispify-tag-name
4009 (widget-get widget
:value
)))
4010 (custom-menu-filter custom-group-menu
4014 (funcall answer widget
)))))
4016 (defun custom-group-set (widget)
4017 "Set changes in all modified group members."
4018 (dolist (child (widget-get widget
:children
))
4019 (when (eq (widget-get child
:custom-state
) 'modified
)
4020 (widget-apply child
:custom-set
))))
4022 (defun custom-group-save (widget)
4023 "Save all modified group members."
4024 (dolist (child (widget-get widget
:children
))
4025 (when (memq (widget-get child
:custom-state
) '(modified set
))
4026 (widget-apply child
:custom-save
))))
4028 (defun custom-group-reset-current (widget)
4029 "Reset all modified group members."
4030 (dolist (child (widget-get widget
:children
))
4031 (when (eq (widget-get child
:custom-state
) 'modified
)
4032 (widget-apply child
:custom-reset-current
))))
4034 (defun custom-group-reset-saved (widget)
4035 "Reset all modified or set group members."
4036 (dolist (child (widget-get widget
:children
))
4037 (when (memq (widget-get child
:custom-state
) '(modified set
))
4038 (widget-apply child
:custom-reset-saved
))))
4040 (defun custom-group-reset-standard (widget)
4041 "Reset all modified, set, or saved group members."
4042 (dolist (child (widget-get widget
:children
))
4043 (when (memq (widget-get child
:custom-state
)
4044 '(modified set saved
))
4045 (widget-apply child
:custom-reset-standard
))))
4047 (defun custom-group-state-update (widget)
4049 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
4050 (let* ((children (widget-get widget
:children
))
4051 (states (mapcar (lambda (child)
4052 (widget-get child
:custom-state
))
4054 (magics custom-magic-alist
)
4057 (let ((magic (car (car magics
))))
4058 (if (and (not (eq magic
'hidden
))
4059 (memq magic states
))
4062 (setq magics
(cdr magics
)))))
4063 (widget-put widget
:custom-state found
)))
4064 (custom-magic-reset widget
))
4066 ;;; Reading and writing the custom file.
4069 (defcustom custom-file nil
4070 "File used for storing customization information.
4071 The default is nil, which means to use your init file
4072 as specified by `user-init-file'. If the value is not nil,
4073 it should be an absolute file name.
4075 You can set this option through Custom, if you carefully read the
4076 last paragraph below. However, usually it is simpler to write
4077 something like the following in your init file:
4079 \(setq custom-file \"~/.emacs-custom.el\")
4082 Note that both lines are necessary: the first line tells Custom to
4083 save all customizations in this file, but does not load it.
4085 When you change this variable outside Custom, look in the
4086 previous custom file \(usually your init file) for the
4087 forms `(custom-set-variables ...)' and `(custom-set-faces ...)',
4088 and copy them (whichever ones you find) to the new custom file.
4089 This will preserve your existing customizations.
4091 If you save this option using Custom, Custom will write all
4092 currently saved customizations, including the new one for this
4093 option itself, into the file you specify, overwriting any
4094 `custom-set-variables' and `custom-set-faces' forms already
4095 present in that file. It will not delete any customizations from
4096 the old custom file. You should do that manually if that is what you
4097 want. You also have to put something like `\(load \"CUSTOM-FILE\")
4098 in your init file, where CUSTOM-FILE is the actual name of the
4099 file. Otherwise, Emacs will not load the file when it starts up,
4100 and hence will not set `custom-file' to that file either."
4101 :type
'(choice (const :tag
"Your Emacs init file" nil
)
4102 (file :format
"%t:%v%d"
4104 "Please read entire docstring below before setting \
4105 this through Custom.
4106 Click om \"More\" \(or position point there and press RETURN)
4107 if only the first line of the docstring is shown."))
4110 (defun custom-file ()
4111 "Return the file name for saving customizations."
4114 (let ((user-init-file user-init-file
)
4116 (if (eq system-type
'ms-dos
) "~/_emacs" "~/.emacs")))
4117 (when (null user-init-file
)
4118 (if (or (file-exists-p default-init-file
)
4119 (and (eq system-type
'windows-nt
)
4120 (file-exists-p "~/_emacs")))
4121 ;; Started with -q, i.e. the file containing
4122 ;; Custom settings hasn't been read. Saving
4123 ;; settings there would overwrite other settings.
4124 (error "Saving settings from \"emacs -q\" would overwrite existing customizations"))
4125 (setq user-init-file default-init-file
))
4129 (defun custom-save-all ()
4130 "Save all customizations in `custom-file'."
4131 (when (and (null custom-file
) init-file-had-error
)
4132 (error "Cannot save customizations; init file was not fully loaded"))
4133 (let* ((filename (custom-file))
4138 (recentf-expand-file-name (custom-file)))
4141 (old-buffer (find-buffer-visiting filename
)))
4142 (with-current-buffer (let ((find-file-visit-truename t
))
4143 (or old-buffer
(find-file-noselect filename
)))
4144 (unless (eq major-mode
'emacs-lisp-mode
)
4146 (let ((inhibit-read-only t
))
4147 (custom-save-variables)
4148 (custom-save-faces))
4149 (let ((file-precious-flag t
))
4152 (kill-buffer (current-buffer))))))
4155 (defun customize-save-customized ()
4156 "Save all user options which have been set in this session."
4158 (mapatoms (lambda (symbol)
4159 (let ((face (get symbol
'customized-face
))
4160 (value (get symbol
'customized-value
))
4161 (face-comment (get symbol
'customized-face-comment
))
4163 (get symbol
'customized-variable-comment
)))
4165 (put symbol
'saved-face face
)
4166 (custom-push-theme 'theme-face symbol
'user
'set value
)
4167 (put symbol
'customized-face nil
))
4169 (put symbol
'saved-value value
)
4170 (custom-push-theme 'theme-value symbol
'user
'set value
)
4171 (put symbol
'customized-value nil
))
4172 (when variable-comment
4173 (put symbol
'saved-variable-comment variable-comment
)
4174 (put symbol
'customized-variable-comment nil
))
4176 (put symbol
'saved-face-comment face-comment
)
4177 (put symbol
'customized-face-comment nil
)))))
4178 ;; We really should update all custom buffers here.
4181 ;; Editing the custom file contents in a buffer.
4183 (defun custom-save-delete (symbol)
4184 "Delete all calls to SYMBOL from the contents of the current buffer.
4185 Leave point at the old location of the first such call,
4186 or (if there were none) at the end of the buffer.
4188 This function does not save the buffer."
4189 (goto-char (point-min))
4190 ;; Skip all whitespace and comments.
4191 (while (forward-comment 1))
4193 (save-excursion (forward-sexp (buffer-size)))) ; Test for scan errors.
4196 (while t
;; We exit this loop only via throw.
4197 ;; Skip all whitespace and comments.
4198 (while (forward-comment 1))
4199 (let ((start (point))
4200 (sexp (condition-case nil
4201 (read (current-buffer))
4202 (end-of-file (throw 'found nil
)))))
4203 (when (and (listp sexp
)
4204 (eq (car sexp
) symbol
))
4205 (delete-region start
(point))
4207 (setq first
(point)))))))
4210 ;; Move in front of local variables, otherwise long Custom
4211 ;; entries would make them ineffective.
4212 (let ((pos (point-max))
4213 (case-fold-search t
))
4215 (goto-char (point-max))
4216 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
4218 (when (search-forward "Local Variables:" nil t
)
4219 (setq pos
(line-beginning-position))))
4222 (defun custom-save-variables ()
4223 "Save all customized variables in `custom-file'."
4225 (custom-save-delete 'custom-set-variables
)
4226 (let ((standard-output (current-buffer))
4227 (saved-list (make-list 1 0))
4229 ;; First create a sorted list of saved variables.
4232 (if (and (get symbol
'saved-value
)
4233 ;; ignore theme values
4234 (or (null (get symbol
'theme-value
))
4235 (eq 'user
(caar (get symbol
'theme-value
)))))
4236 (nconc saved-list
(list symbol
)))))
4237 (setq saved-list
(sort (cdr saved-list
) 'string
<))
4240 (princ "(custom-set-variables
4241 ;; custom-set-variables was added by Custom.
4242 ;; If you edit it by hand, you could mess it up, so be careful.
4243 ;; Your init file should contain only one such instance.
4244 ;; If there is more than one, they won't work right.\n")
4245 (dolist (symbol saved-list
)
4246 (let ((spec (car-safe (get symbol
'theme-value
)))
4247 (value (get symbol
'saved-value
))
4248 (requests (get symbol
'custom-requests
))
4249 (now (and (not (custom-variable-p symbol
))
4251 (eq (get symbol
'force-value
)
4253 (comment (get symbol
'saved-variable-comment
)))
4254 ;; Check REQUESTS for validity.
4255 (dolist (request requests
)
4256 (when (and (symbolp request
) (not (featurep request
)))
4257 (message "Unknown requested feature: %s" request
)
4258 (setq requests
(delq request requests
))))
4259 ;; Is there anything customized about this variable?
4260 (when (or (and spec
(eq (car spec
) 'user
))
4262 (and (null spec
) (get symbol
'saved-value
)))
4263 ;; Output an element for this variable.
4264 ;; It has the form (SYMBOL VALUE-FORM NOW REQUESTS COMMENT).
4265 ;; SYMBOL is the variable name.
4266 ;; VALUE-FORM is an expression to return the customized value.
4267 ;; NOW if non-nil means always set the variable immediately
4268 ;; when the customizations are reloaded. This is used
4269 ;; for rogue variables
4270 ;; REQUESTS is a list of packages to load before setting the
4271 ;; variable. Each element of it will be passed to `require'.
4272 ;; COMMENT is whatever comment the user has specified
4273 ;; with the customize facility.
4280 (when (or now requests comment
)
4283 (when (or requests comment
)
4293 (unless (looking-at "\n")
4296 (defun custom-save-faces ()
4297 "Save all customized faces in `custom-file'."
4299 (custom-save-delete 'custom-reset-faces
)
4300 (custom-save-delete 'custom-set-faces
)
4301 (let ((standard-output (current-buffer))
4302 (saved-list (make-list 1 0))
4304 ;; First create a sorted list of saved faces.
4307 (if (and (get symbol
'saved-face
)
4308 (eq 'user
(car (car-safe (get symbol
'theme-face
)))))
4309 (nconc saved-list
(list symbol
)))))
4310 (setq saved-list
(sort (cdr saved-list
) 'string
<))
4311 ;; The default face must be first, since it affects the others.
4312 (if (memq 'default saved-list
)
4313 (setq saved-list
(cons 'default
(delq 'default saved-list
))))
4316 (princ "(custom-set-faces
4317 ;; custom-set-faces was added by Custom.
4318 ;; If you edit it by hand, you could mess it up, so be careful.
4319 ;; Your init file should contain only one such instance.
4320 ;; If there is more than one, they won't work right.\n")
4321 (dolist (symbol saved-list
)
4322 (let ((spec (car-safe (get symbol
'theme-face
)))
4323 (value (get symbol
'saved-face
))
4324 (now (not (or (get symbol
'face-defface-spec
)
4325 (and (not (custom-facep symbol
))
4326 (not (get symbol
'force-face
))))))
4327 (comment (get symbol
'saved-face-comment
)))
4328 (when (or (and spec
(eq (nth 0 spec
) 'user
))
4330 (and (null spec
) (get symbol
'saved-face
)))
4331 ;; Don't print default face here.
4338 (when (or now comment
)
4348 (unless (looking-at "\n")
4351 ;;; The Customize Menu.
4355 (defcustom custom-menu-nesting
2
4356 "Maximum nesting in custom menus."
4358 :group
'custom-menu
)
4360 (defun custom-face-menu-create (widget symbol
)
4361 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
4362 (vector (custom-unlispify-menu-entry symbol
)
4363 `(customize-face ',symbol
)
4366 (defun custom-variable-menu-create (widget symbol
)
4367 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
4368 (let ((type (get symbol
'custom-type
)))
4369 (unless (listp type
)
4370 (setq type
(list type
)))
4371 (if (and type
(widget-get type
:custom-menu
))
4372 (widget-apply type
:custom-menu symbol
)
4373 (vector (custom-unlispify-menu-entry symbol
)
4374 `(customize-variable ',symbol
)
4377 ;; Add checkboxes to boolean variable entries.
4378 (widget-put (get 'boolean
'widget-type
)
4379 :custom-menu
(lambda (widget symbol
)
4380 (vector (custom-unlispify-menu-entry symbol
)
4381 `(customize-variable ',symbol
)
4383 ':selected symbol
)))
4385 (defun custom-group-menu-create (widget symbol
)
4386 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
4387 `( ,(custom-unlispify-menu-entry symbol t
)
4388 :filter
(lambda (&rest junk
)
4389 (let* ((menu (custom-menu-create ',symbol
)))
4390 (if (consp menu
) (cdr menu
) menu
)))))
4393 (defun custom-menu-create (symbol)
4394 "Create menu for customization group SYMBOL.
4395 The menu is in a format applicable to `easy-menu-define'."
4396 (let* ((deactivate-mark nil
)
4397 (item (vector (custom-unlispify-menu-entry symbol
)
4398 `(customize-group ',symbol
)
4400 (if (and (or (not (boundp 'custom-menu-nesting
))
4401 (>= custom-menu-nesting
0))
4403 (custom-load-symbol symbol
)
4404 (< (length (get symbol
'custom-group
)) widget-menu-max-size
)))
4405 (let ((custom-prefix-list (custom-prefix-add symbol
4406 custom-prefix-list
))
4407 (members (custom-sort-items (get symbol
'custom-group
)
4408 custom-menu-sort-alphabetically
4409 custom-menu-order-groups
)))
4410 `(,(custom-unlispify-menu-entry symbol t
)
4413 ,@(mapcar (lambda (entry)
4414 (widget-apply (if (listp (nth 1 entry
))
4416 (list (nth 1 entry
)))
4417 :custom-menu
(nth 0 entry
)))
4422 (defun customize-menu-create (symbol &optional name
)
4423 "Return a customize menu for customization group SYMBOL.
4424 If optional NAME is given, use that as the name of the menu.
4425 Otherwise the menu will be named `Customize'.
4426 The format is suitable for use with `easy-menu-define'."
4428 (setq name
"Customize"))
4430 :filter
(lambda (&rest junk
)
4431 (let ((menu (custom-menu-create ',symbol
)))
4432 (if (consp menu
) (cdr menu
) menu
)))))
4434 ;;; Toolbar and menubar support
4437 Custom-mode-menu custom-mode-map
4438 "Menu used in customization buffers."
4439 (nconc (list "Custom"
4440 (customize-menu-create 'customize
))
4441 (mapcar (lambda (arg)
4442 (let ((tag (nth 0 arg
))
4443 (command (nth 1 arg
))
4444 (active (nth 2 arg
))
4446 (vector tag command
:active
(eval active
) :help help
)))
4449 (defvar tool-bar-map
)
4450 (defvar custom-tool-bar-map
4451 (if (display-graphic-p)
4452 (let ((map (make-sparse-keymap)))
4455 (tool-bar-local-item-from-menu
4456 (nth 1 arg
) (nth 4 arg
) map custom-mode-map
))
4460 ;;; The Custom Mode.
4462 (defun Custom-no-edit (pos &optional event
)
4463 "Invoke button at POS, or refuse to allow editing of Custom buffer."
4465 (error "You can't edit this part of the Custom buffer"))
4467 (defun Custom-newline (pos &optional event
)
4468 "Invoke button at POS, or refuse to allow editing of Custom buffer."
4470 (let ((button (get-char-property pos
'button
)))
4472 (widget-apply-action button event
)
4473 (error "You can't edit this part of the Custom buffer"))))
4475 (defvar custom-field-keymap
4476 (let ((map (copy-keymap widget-field-keymap
)))
4477 (define-key map
"\C-c\C-c" 'Custom-set
)
4478 (define-key map
"\C-x\C-s" 'Custom-save
)
4480 "Keymap used inside editable fields in customization buffers.")
4482 (widget-put (get 'editable-field
'widget-type
) :keymap custom-field-keymap
)
4484 (defun Custom-goto-parent ()
4485 "Go to the parent group listed at the top of this buffer.
4486 If several parents are listed, go to the first of them."
4489 (goto-char (point-min))
4490 (if (search-forward "\nParent groups: " nil t
)
4491 (let* ((button (get-char-property (point) 'button
))
4492 (parent (downcase (widget-get button
:tag
))))
4493 (customize-group parent
)))))
4495 (defcustom custom-mode-hook nil
4496 "Hook called when entering Custom mode."
4498 :group
'custom-buffer
)
4500 (defun custom-state-buffer-message (widget)
4501 (if (eq (widget-get (widget-get widget
:parent
) :custom-state
) 'modified
)
4502 (message "To install your edits, invoke [State] and choose the Set operation")))
4504 (defun custom-mode ()
4505 "Major mode for editing customization buffers.
4507 The following commands are available:
4510 Move to next button, link or editable field. \\[widget-forward]
4511 Move to previous button, link or editable field. \\[advertised-widget-backward]
4512 \\<custom-field-keymap>\
4513 Complete content of editable text field. \\[widget-complete]
4514 \\<custom-mode-map>\
4515 Invoke button under the mouse pointer. \\[widget-button-click]
4516 Invoke button under point. \\[widget-button-press]
4517 Set all options from current text. \\[Custom-set]
4518 Make values in current text permanent. \\[Custom-save]
4519 Make text match actual option values. \\[Custom-reset-current]
4520 Reset options to permanent settings. \\[Custom-reset-saved]
4521 Erase customizations; set options
4522 and buffer text to the standard values. \\[Custom-reset-standard]
4524 Entry to this mode calls the value of `custom-mode-hook'
4525 if that value is non-nil."
4526 (kill-all-local-variables)
4527 (setq major-mode
'custom-mode
4529 (use-local-map custom-mode-map
)
4530 (easy-menu-add Custom-mode-menu
)
4531 (set (make-local-variable 'tool-bar-map
) custom-tool-bar-map
)
4532 (make-local-variable 'custom-options
)
4533 (make-local-variable 'custom-local-buffer
)
4534 (make-local-variable 'widget-documentation-face
)
4535 (setq widget-documentation-face
'custom-documentation
)
4536 (make-local-variable 'widget-button-face
)
4537 (setq widget-button-face custom-button
)
4539 ;; We need this because of the "More" button on docstrings.
4540 ;; Otherwise clicking on "More" can push point offscreen, which
4541 ;; causes the window to recenter on point, which pushes the
4542 ;; newly-revealed docstring offscreen; which is annoying. -- cyd.
4543 (set (make-local-variable 'widget-button-click-moves-point
) t
)
4545 (set (make-local-variable 'widget-button-pressed-face
) custom-button-pressed
)
4546 (set (make-local-variable 'widget-mouse-face
) custom-button-mouse
)
4548 ;; When possible, use relief for buttons, not bracketing. This test
4549 ;; may not be optimal.
4550 (when custom-raised-buttons
4551 (set (make-local-variable 'widget-push-button-prefix
) "")
4552 (set (make-local-variable 'widget-push-button-suffix
) "")
4553 (set (make-local-variable 'widget-link-prefix
) "")
4554 (set (make-local-variable 'widget-link-suffix
) ""))
4555 (add-hook 'widget-edit-functions
'custom-state-buffer-message nil t
)
4556 (run-mode-hooks 'custom-mode-hook
))
4558 (put 'custom-mode
'mode-class
'special
)
4561 '("^No user option defaults have been changed since Emacs "
4563 "^No \\(?:customized\\|rogue\\|saved\\) user options"
4564 "^No customizable items matching "
4565 "^There are unset changes"
4566 "^Cannot set hidden variable"
4567 "^No \\(?:saved\\|backup\\) value for "
4568 "^No standard setting known for "
4569 "^No standard setting for this face"
4570 "^Saving settings from \"emacs -q\" would overwrite existing customizations"))
4571 (add-to-list 'debug-ignored-errors regexp
))
4577 ;; arch-tag: 64533aa4-1b1a-48c3-8812-f9dc718e8a6f
4578 ;;; cus-edit.el ends here