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 2, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 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
)))
1037 (defun customize-group (&optional group prompt-for-group other-window
)
1038 "Customize GROUP, which must be a customization group."
1041 (or prompt-for-group
(called-interactively-p))
1042 (let ((completion-ignore-case t
))
1044 (completing-read "Customize group (default emacs): "
1047 (or (and (get symbol
'custom-loads
)
1048 (not (get symbol
'custom-autoload
)))
1049 (get symbol
'custom-group
)))
1051 (when (stringp group
)
1052 (if (string-equal "" group
)
1054 (setq group
(intern group
))))
1055 (let ((name (format "*Customize Group: %s*"
1056 (custom-unlispify-tag-name group
))))
1057 (if (get-buffer name
)
1059 (let ((pop-up-windows t
)
1060 (same-window-buffer-names nil
)
1061 (same-window-regexps nil
))
1062 (pop-to-buffer name
))
1063 (pop-to-buffer name
))
1064 (funcall (if other-window
1065 'custom-buffer-create-other-window
1066 'custom-buffer-create
)
1067 (list (list group
'custom-group
))
1069 (concat " for group "
1070 (custom-unlispify-tag-name group
))))))
1073 (defun customize-group-other-window (&optional group
)
1074 "Customize GROUP, which must be a customization group, in another window."
1076 (customize-group group t t
))
1079 (defalias 'customize-variable
'customize-option
)
1082 (defun customize-option (symbol)
1083 "Customize SYMBOL, which must be a user option variable."
1084 (interactive (custom-variable-prompt))
1086 (error "No variable specified"))
1087 (let ((basevar (indirect-variable symbol
)))
1088 (custom-buffer-create (list (list basevar
'custom-variable
))
1089 (format "*Customize Option: %s*"
1090 (custom-unlispify-tag-name basevar
)))
1091 (unless (eq symbol basevar
)
1092 (message "`%s' is an alias for `%s'" symbol basevar
))))
1095 (defalias 'customize-variable-other-window
'customize-option-other-window
)
1098 (defun customize-option-other-window (symbol)
1099 "Customize SYMBOL, which must be a user option variable.
1100 Show the buffer in another window, but don't select it."
1101 (interactive (custom-variable-prompt))
1103 (error "No variable specified"))
1104 (let ((basevar (indirect-variable symbol
)))
1105 (custom-buffer-create-other-window
1106 (list (list basevar
'custom-variable
))
1107 (format "*Customize Option: %s*" (custom-unlispify-tag-name basevar
)))
1108 (unless (eq symbol basevar
)
1109 (message "`%s' is an alias for `%s'" symbol basevar
))))
1111 (defvar customize-changed-options-previous-release
"21.1"
1112 "Version for `customize-changed-options' to refer back to by default.")
1114 ;; Packages will update this variable, so make it available.
1116 (defvar customize-package-emacs-version-alist nil
1117 "Alist mapping versions of a package to Emacs versions.
1118 We use this for packages that have their own names, but are released
1119 as part of Emacs itself.
1121 Each elements looks like this:
1123 (PACKAGE (PVERSION . EVERSION)...)
1125 Here PACKAGE is the name of a package, as a symbol. After
1126 PACKAGE come one or more elements, each associating a
1127 package version PVERSION with the first Emacs version
1128 EVERSION in which it (or a subsequent version of PACKAGE)
1129 was first released. Both PVERSION and EVERSION are strings.
1130 PVERSION should be a string that this package used in
1131 the :package-version keyword for `defcustom', `defgroup',
1134 For example, the MH-E package updates this alist as follows:
1136 (add-to-list 'customize-package-emacs-version-alist
1137 '(MH-E (\"6.0\" . \"22.1\") (\"6.1\" . \"22.1\")
1138 (\"7.0\" . \"22.1\") (\"7.1\" . \"22.1\")
1139 (\"7.2\" . \"22.1\") (\"7.3\" . \"22.1\")
1140 (\"7.4\" . \"22.1\") (\"8.0\" . \"22.1\")))
1142 The value of PACKAGE needs to be unique and it needs to match the
1143 PACKAGE value appearing in the :package-version keyword. Since
1144 the user might see the value in a error message, a good choice is
1145 the official name of the package, such as MH-E or Gnus.")
1148 (defalias 'customize-changed
'customize-changed-options
)
1151 (defun customize-changed-options (since-version)
1152 "Customize all settings whose meanings have changed in Emacs itself.
1153 This includes new user option variables and faces, and new
1154 customization groups, as well as older options and faces whose meanings
1155 or default values have changed since the previous major Emacs release.
1157 With argument SINCE-VERSION (a string), customize all settings
1158 that were added or redefined since that version."
1162 (read-from-minibuffer
1163 (format "Customize options changed, since version (default %s): "
1164 customize-changed-options-previous-release
))))
1165 (if (equal since-version
"")
1166 (setq since-version nil
)
1167 (unless (condition-case nil
1168 (numberp (read since-version
))
1170 (signal 'wrong-type-argument
(list 'numberp since-version
))))
1171 (unless since-version
1172 (setq since-version customize-changed-options-previous-release
))
1174 ;; Load the information for versions since since-version. We use
1175 ;; custom-load-symbol for this.
1176 (put 'custom-versions-load-alist
'custom-loads nil
)
1177 (dolist (elt custom-versions-load-alist
)
1178 (if (customize-version-lessp since-version
(car elt
))
1179 (dolist (load (cdr elt
))
1180 (custom-add-load 'custom-versions-load-alist load
))))
1181 (custom-load-symbol 'custom-versions-load-alist
)
1182 (put 'custom-versions-load-alist
'custom-loads nil
)
1187 (let* ((package-version (get symbol
'custom-package-version
))
1189 (or (and package-version
1190 (customize-package-emacs-version symbol
1192 (get symbol
'custom-version
))))
1194 (when (customize-version-lessp since-version version
)
1195 (if (or (get symbol
'custom-group
)
1196 (get symbol
'group-documentation
))
1197 (push (list symbol
'custom-group
) found
))
1198 (if (custom-variable-p symbol
)
1199 (push (list symbol
'custom-variable
) found
))
1200 (if (custom-facep symbol
)
1201 (push (list symbol
'custom-face
) found
)))))))
1203 (custom-buffer-create (custom-sort-items found t
'first
)
1204 "*Customize Changed Options*")
1205 (error "No user option defaults have been changed since Emacs %s"
1208 (defun customize-package-emacs-version (symbol package-version
)
1209 "Return the Emacs version in which SYMBOL's meaning last changed.
1210 PACKAGE-VERSION has the form (PACKAGE . VERSION). We use
1211 `customize-package-emacs-version-alist' to find the version of
1212 Emacs that is associated with version VERSION of PACKAGE."
1213 (let (package-versions emacs-version
)
1214 ;; Use message instead of error since we want user to be able to
1215 ;; see the rest of the symbols even if a package author has
1216 ;; botched things up.
1217 (cond ((not (listp package-version
))
1218 (message "Invalid package-version value for %s" symbol
))
1219 ((setq package-versions
(assq (car package-version
)
1220 customize-package-emacs-version-alist
))
1222 (cdr (assoc (cdr package-version
) package-versions
)))
1223 (unless emacs-version
1224 (message "%s version %s not found in %s" symbol
1225 (cdr package-version
)
1226 "customize-package-emacs-version-alist")))
1228 (message "Package %s version %s lists no corresponding Emacs version"
1229 (car package-version
)
1230 (cdr package-version
))))
1233 (defun customize-version-lessp (version1 version2
)
1234 ;; Why are the versions strings, and given that they are, why aren't
1235 ;; they converted to numbers and compared as such here? -- fx
1237 ;; In case someone made a mistake and left out the quotes
1238 ;; in the :version value.
1239 (if (numberp version2
)
1240 (setq version2
(prin1-to-string version2
)))
1241 (let (major1 major2 minor1 minor2
)
1242 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version1
)
1243 (setq major1
(read (or (match-string 1 version1
)
1245 (setq minor1
(read (or (match-string 3 version1
)
1247 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version2
)
1248 (setq major2
(read (or (match-string 1 version2
)
1250 (setq minor2
(read (or (match-string 3 version2
)
1252 (or (< major1 major2
)
1253 (and (= major1 major2
)
1254 (< minor1 minor2
)))))
1257 (defun customize-face (&optional face prompt-for-face other-window
)
1258 "Customize FACE, which should be a face name or nil.
1259 If FACE is nil, customize all faces. If FACE is actually a
1260 face-alias, customize the face it is aliased to.
1262 Interactively, when point is on text which has a face specified,
1263 suggest to customize that face, if it's customizable."
1266 (or prompt-for-face
(called-interactively-p))
1267 (setq face
(read-face-name "Customize face" "all faces" t
)))
1268 (if (member face
'(nil ""))
1269 (setq face
(face-list)))
1270 (if (and (listp face
) (null (cdr face
)))
1271 (setq face
(car face
)))
1272 (let ((create-buffer-fn (if other-window
1273 'custom-buffer-create-other-window
1274 'custom-buffer-create
)))
1276 (funcall create-buffer-fn
1279 (list s
'custom-face
))
1282 "*Customize Faces*")
1283 ;; If FACE is actually an alias, customize the face it is aliased to.
1284 (if (get face
'face-alias
)
1285 (setq face
(get face
'face-alias
)))
1286 (unless (facep face
)
1287 (error "Invalid face %S" face
))
1288 (funcall create-buffer-fn
1289 (list (list face
'custom-face
))
1290 (format "*Customize Face: %s*"
1291 (custom-unlispify-tag-name face
))))))
1294 (defun customize-face-other-window (&optional face
)
1295 "Show customization buffer for face FACE in other window.
1296 If FACE is actually a face-alias, customize the face it is aliased to.
1298 Interactively, when point is on text which has a face specified,
1299 suggest to customize that face, if it's customizable."
1301 (customize-face face t t
))
1303 (defalias 'customize-customized
'customize-unsaved
)
1306 (defun customize-unsaved ()
1307 "Customize all user options set in this session but not saved."
1310 (mapatoms (lambda (symbol)
1311 (and (or (get symbol
'customized-face
)
1312 (get symbol
'customized-face-comment
))
1313 (custom-facep symbol
)
1314 (push (list symbol
'custom-face
) found
))
1315 (and (or (get symbol
'customized-value
)
1316 (get symbol
'customized-variable-comment
))
1318 (push (list symbol
'custom-variable
) found
))))
1320 (error "No user options are set but unsaved")
1321 (custom-buffer-create (custom-sort-items found t nil
)
1322 "*Customize Unsaved*"))))
1325 (defun customize-rogue ()
1326 "Customize all user variables modified outside customize."
1329 (mapatoms (lambda (symbol)
1330 (let ((cval (or (get symbol
'customized-value
)
1331 (get symbol
'saved-value
)
1332 (get symbol
'standard-value
))))
1333 (when (and cval
;Declared with defcustom.
1334 (default-boundp symbol
) ;Has a value.
1335 (not (equal (eval (car cval
))
1336 ;; Which does not match customize.
1337 (default-value symbol
))))
1338 (push (list symbol
'custom-variable
) found
)))))
1340 (error "No rogue user options")
1341 (custom-buffer-create (custom-sort-items found t nil
)
1342 "*Customize Rogue*"))))
1344 (defun customize-saved ()
1345 "Customize all already saved user options."
1348 (mapatoms (lambda (symbol)
1349 (and (or (get symbol
'saved-face
)
1350 (get symbol
'saved-face-comment
))
1351 (custom-facep symbol
)
1352 (push (list symbol
'custom-face
) found
))
1353 (and (or (get symbol
'saved-value
)
1354 (get symbol
'saved-variable-comment
))
1356 (push (list symbol
'custom-variable
) found
))))
1358 (error "No saved user options")
1359 (custom-buffer-create (custom-sort-items found t nil
)
1360 "*Customize Saved*"))))
1363 (defun customize-apropos (regexp &optional all
)
1364 "Customize all loaded options, faces and groups matching REGEXP.
1365 If ALL is `options', include only options.
1366 If ALL is `faces', include only faces.
1367 If ALL is `groups', include only groups.
1368 If ALL is t (interactively, with prefix arg), include variables
1369 that are not customizable options, as well as faces and groups
1370 \(but we recommend using `apropos-variable' instead)."
1371 (interactive "sCustomize regexp: \nP")
1373 (mapatoms (lambda (symbol)
1374 (when (string-match regexp
(symbol-name symbol
))
1375 (when (and (not (memq all
'(faces options
)))
1376 (get symbol
'custom-group
))
1377 (push (list symbol
'custom-group
) found
))
1378 (when (and (not (memq all
'(options groups
)))
1379 (custom-facep symbol
))
1380 (push (list symbol
'custom-face
) found
))
1381 (when (and (not (memq all
'(groups faces
)))
1383 (eq (indirect-variable symbol
) symbol
)
1384 (or (get symbol
'saved-value
)
1385 (custom-variable-p symbol
)
1386 (and (not (memq all
'(nil options
)))
1387 (get symbol
'variable-documentation
))))
1388 (push (list symbol
'custom-variable
) found
)))))
1390 (error "No customizable items matching %s" regexp
)
1391 (custom-buffer-create
1392 (custom-sort-items found t custom-buffer-order-groups
)
1393 "*Customize Apropos*"))))
1396 (defun customize-apropos-options (regexp &optional arg
)
1397 "Customize all loaded customizable options matching REGEXP.
1398 With prefix arg, include variables that are not customizable options
1399 \(but we recommend using `apropos-variable' instead)."
1400 (interactive "sCustomize regexp: \nP")
1401 (customize-apropos regexp
(or arg
'options
)))
1404 (defun customize-apropos-faces (regexp)
1405 "Customize all loaded faces matching REGEXP."
1406 (interactive "sCustomize regexp: \n")
1407 (customize-apropos regexp
'faces
))
1410 (defun customize-apropos-groups (regexp)
1411 "Customize all loaded groups matching REGEXP."
1412 (interactive "sCustomize regexp: \n")
1413 (customize-apropos regexp
'groups
))
1417 (defcustom custom-buffer-style
'links
1418 "Control the presentation style for customization buffers.
1419 The value should be a symbol, one of:
1421 brackets: groups nest within each other with big horizontal brackets.
1422 links: groups have links to subgroups."
1423 :type
'(radio (const brackets
)
1425 :group
'custom-buffer
)
1427 (defcustom custom-buffer-done-kill nil
1428 "*Non-nil means exiting a Custom buffer should kill it."
1431 :group
'custom-buffer
)
1433 (defcustom custom-buffer-indent
3
1434 "Number of spaces to indent nested groups."
1436 :group
'custom-buffer
)
1438 (defun custom-get-fresh-buffer (name)
1439 "Get a fresh new buffer with name NAME.
1440 If the buffer already exist, clean it up to be like new.
1441 Beware: it's not quite like new. Good enough for custom, but maybe
1443 ;; To be more complete, we should also kill all permanent-local variables,
1444 ;; but it's not needed for custom.
1445 (let ((buf (get-buffer name
)))
1446 (when (and buf
(buffer-local-value 'buffer-file-name buf
))
1447 ;; This will check if the file is not saved.
1451 (get-buffer-create name
)
1452 (with-current-buffer buf
1453 (kill-all-local-variables)
1454 (run-hooks 'kill-buffer-hook
)
1455 ;; Delete overlays before erasing the buffer so the overlay hooks
1456 ;; don't get run spuriously when we erase the buffer.
1457 (let ((ols (overlay-lists)))
1458 (dolist (ol (nconc (car ols
) (cdr ols
)))
1459 (delete-overlay ol
)))
1464 (defun custom-buffer-create (options &optional name description
)
1465 "Create a buffer containing OPTIONS.
1466 Optional NAME is the name of the buffer.
1467 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1468 SYMBOL is a customization option, and WIDGET is a widget for editing
1470 (pop-to-buffer (custom-get-fresh-buffer (or name
"*Customization*")))
1471 (custom-buffer-create-internal options description
))
1474 (defun custom-buffer-create-other-window (options &optional name description
)
1475 "Create a buffer containing OPTIONS, and display it in another window.
1476 The result includes selecting that window.
1477 Optional NAME is the name of the buffer.
1478 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1479 SYMBOL is a customization option, and WIDGET is a widget for editing
1481 (unless name
(setq name
"*Customization*"))
1482 (let ((pop-up-windows t
)
1483 (same-window-buffer-names nil
)
1484 (same-window-regexps nil
))
1485 (pop-to-buffer (custom-get-fresh-buffer name
))
1486 (custom-buffer-create-internal options description
)))
1488 (defcustom custom-reset-button-menu nil
1489 "If non-nil, only show a single reset button in customize buffers.
1490 This button will have a menu with all three reset operations."
1492 :group
'custom-buffer
)
1494 (defcustom custom-buffer-verbose-help t
1495 "If non-nil, include explanatory text in the customization buffer."
1497 :group
'custom-buffer
)
1499 (defun Custom-buffer-done (&rest ignore
)
1500 "Exit current Custom buffer according to `custom-buffer-done-kill'."
1502 (quit-window custom-buffer-done-kill
))
1504 (defvar custom-button nil
1505 "Face used for buttons in customization buffers.")
1507 (defvar custom-button-mouse nil
1508 "Mouse face used for buttons in customization buffers.")
1510 (defvar custom-button-pressed nil
1511 "Face used for pressed buttons in customization buffers.")
1513 (defcustom custom-raised-buttons
(not (equal (face-valid-attribute-values :box
)
1514 '(("unspecified" . unspecified
))))
1515 "If non-nil, indicate active buttons in a `raised-button' style.
1516 Otherwise use brackets."
1519 :group
'custom-buffer
1520 :set
(lambda (variable value
)
1521 (custom-set-default variable value
)
1523 (if value
'custom-button
'custom-button-unraised
))
1524 (setq custom-button-mouse
1525 (if value
'custom-button-mouse
'highlight
))
1526 (setq custom-button-pressed
1528 'custom-button-pressed
1529 'custom-button-pressed-unraised
))))
1531 (defun custom-buffer-create-internal (options &optional description
)
1533 (let ((init-file (or custom-file user-init-file
)))
1534 ;; Insert verbose help at the top of the custom buffer.
1535 (when custom-buffer-verbose-help
1536 (widget-insert "Editing a setting changes only the text in this buffer."
1539 To set apply your changes, use the Save or Set buttons.
1540 Saving a change normally works by editing your init file."
1542 Currently, these settings cannot be saved for future Emacs sessions,
1543 possibly because you started Emacs with `-q'.")
1544 "\nFor details, see ")
1545 (widget-create 'custom-manual
1546 :tag
"Saving Customizations"
1547 "(emacs)Saving Customizations")
1548 (widget-insert " in the ")
1549 (widget-create 'custom-manual
1551 :help-echo
"Read the Emacs manual."
1553 (widget-insert "."))
1554 ;; Insert custom command buttons if the toolbar is not in use.
1556 (widget-insert "\n")
1557 (when (not (and tool-bar-mode
(display-graphic-p)))
1558 (if custom-buffer-verbose-help
1560 Operate on all settings in this buffer that are not marked HIDDEN:\n"))
1561 (let ((button (lambda (tag action active help icon
)
1564 (widget-create 'push-button
:tag tag
1565 :help-echo help
:action action
))))
1566 (commands custom-commands
))
1567 (apply button
(pop commands
)) ; Set for current session
1568 (apply button
(pop commands
)) ; Save for future sessions
1569 (if custom-reset-button-menu
1572 (widget-create 'push-button
1574 :help-echo
"Show a menu with reset operations."
1575 :mouse-down-action
'ignore
1576 :action
'custom-reset
))
1577 (widget-insert "\n")
1578 (apply button
(pop commands
)) ; Undo edits
1579 (apply button
(pop commands
)) ; Reset to saved
1580 (apply button
(pop commands
)) ; Erase customization
1582 (pop commands
) ; Help (omitted)
1583 (apply button
(pop commands
))))) ; Exit
1584 (widget-insert "\n\n"))
1586 ;; Now populate the custom buffer.
1587 (message "Creating customization items...")
1588 (buffer-disable-undo)
1589 (setq custom-options
1590 (if (= (length options
) 1)
1591 (mapcar (lambda (entry)
1592 (widget-create (nth 1 entry
)
1593 :documentation-shown t
1594 :custom-state
'unknown
1595 :tag
(custom-unlispify-tag-name
1597 :value
(nth 0 entry
)))
1600 (length (length options
)))
1601 (mapcar (lambda (entry)
1603 (message "Creating customization items ...%2d%%"
1604 (/ (* 100.0 count
) length
))
1605 (widget-create (nth 1 entry
)
1606 :tag
(custom-unlispify-tag-name
1608 :value
(nth 0 entry
))
1609 (setq count
(1+ count
))
1610 (unless (eq (preceding-char) ?
\n)
1611 (widget-insert "\n"))
1612 (widget-insert "\n")))
1614 (unless (eq (preceding-char) ?
\n)
1615 (widget-insert "\n"))
1616 (message "Creating customization items ...done")
1617 (message "Resetting customization items...")
1618 (unless (eq custom-buffer-style
'tree
)
1619 (mapc 'custom-magic-reset custom-options
))
1620 (message "Resetting customization items...done")
1621 (message "Creating customization setup...")
1623 (buffer-enable-undo)
1624 (goto-char (point-min))
1625 (message "Creating customization setup...done"))
1627 ;;; The Tree Browser.
1630 (defun customize-browse (&optional group
)
1631 "Create a tree browser for the customize hierarchy."
1634 (setq group
'emacs
))
1635 (let ((name "*Customize Browser*"))
1636 (pop-to-buffer (custom-get-fresh-buffer name
)))
1638 (widget-insert (format "\
1639 %s buttons; type RET or click mouse-1
1640 on a button to invoke its action.
1641 Invoke [+] to expand a group, and [-] to collapse an expanded group.\n"
1642 (if custom-raised-buttons
1643 "`Raised' text indicates"
1644 "Square brackets indicate")))
1647 (if custom-browse-only-groups
1649 Invoke the [Group] button below to edit that item in another window.\n\n")
1650 (widget-insert "Invoke the ")
1651 (widget-create 'item
1654 :tag-glyph
"folder")
1655 (widget-insert ", ")
1656 (widget-create 'item
1660 (widget-insert ", and ")
1661 (widget-create 'item
1664 :tag-glyph
"option")
1665 (widget-insert " buttons below to edit that
1666 item in another window.\n\n"))
1667 (let ((custom-buffer-style 'tree
))
1668 (widget-create 'custom-group
1670 :custom-state
'unknown
1671 :tag
(custom-unlispify-tag-name group
)
1674 (goto-char (point-min)))
1676 (define-widget 'custom-browse-visibility
'item
1677 "Control visibility of items in the customize tree browser."
1679 :action
'custom-browse-visibility-action
)
1681 (defun custom-browse-visibility-action (widget &rest ignore
)
1682 (let ((custom-buffer-style 'tree
))
1683 (custom-toggle-parent widget
)))
1685 (define-widget 'custom-browse-group-tag
'custom-group-link
1686 "Show parent in other window when activated."
1689 :action
'custom-browse-group-tag-action
)
1691 (defun custom-browse-group-tag-action (widget &rest ignore
)
1692 (let ((parent (widget-get widget
:parent
)))
1693 (customize-group-other-window (widget-value parent
))))
1695 (define-widget 'custom-browse-variable-tag
'custom-group-link
1696 "Show parent in other window when activated."
1699 :action
'custom-browse-variable-tag-action
)
1701 (defun custom-browse-variable-tag-action (widget &rest ignore
)
1702 (let ((parent (widget-get widget
:parent
)))
1703 (customize-variable-other-window (widget-value parent
))))
1705 (define-widget 'custom-browse-face-tag
'custom-group-link
1706 "Show parent in other window when activated."
1709 :action
'custom-browse-face-tag-action
)
1711 (defun custom-browse-face-tag-action (widget &rest ignore
)
1712 (let ((parent (widget-get widget
:parent
)))
1713 (customize-face-other-window (widget-value parent
))))
1715 (defconst custom-browse-alist
'((" " "space")
1721 (defun custom-browse-insert-prefix (prefix)
1722 "Insert PREFIX. On XEmacs convert it to line graphics."
1723 ;; Fixme: do graphics.
1724 (if nil
; (string-match "XEmacs" emacs-version)
1727 (while (not (string-equal prefix
""))
1728 (let ((entry (substring prefix
0 3)))
1729 (setq prefix
(substring prefix
3))
1730 (let ((overlay (make-overlay (1- (point)) (point) nil t nil
))
1731 (name (nth 1 (assoc entry custom-browse-alist
))))
1732 (overlay-put overlay
'end-glyph
(widget-glyph-find name entry
))
1733 (overlay-put overlay
'start-open t
)
1734 (overlay-put overlay
'end-open t
)))))
1737 ;;; Modification of Basic Widgets.
1739 ;; We add extra properties to the basic widgets needed here. This is
1740 ;; fine, as long as we are careful to stay within out own namespace.
1742 ;; We want simple widgets to be displayed by default, but complex
1743 ;; widgets to be hidden.
1745 (widget-put (get 'item
'widget-type
) :custom-show t
)
1746 (widget-put (get 'editable-field
'widget-type
)
1747 :custom-show
(lambda (widget value
)
1748 (let ((pp (pp-to-string value
)))
1749 (cond ((string-match "\n" pp
)
1754 (widget-put (get 'menu-choice
'widget-type
) :custom-show t
)
1756 ;;; The `custom-manual' Widget.
1758 (define-widget 'custom-manual
'info-link
1759 "Link to the manual entry for this customization option."
1760 :help-echo
"Read the manual entry for this option."
1761 :keymap custom-mode-link-map
1762 :follow-link
'mouse-face
1763 :button-face
'custom-link
1764 :mouse-face
'highlight
1765 :pressed-face
'highlight
1768 ;;; The `custom-magic' Widget.
1770 (defgroup custom-magic-faces nil
1771 "Faces used by the magic button."
1772 :group
'custom-faces
1773 :group
'custom-buffer
)
1775 (defface custom-invalid
'((((class color
))
1776 (:foreground
"yellow1" :background
"red1"))
1778 (:weight bold
:slant italic
:underline t
)))
1779 "Face used when the customize item is invalid."
1780 :group
'custom-magic-faces
)
1781 ;; backward-compatibility alias
1782 (put 'custom-invalid-face
'face-alias
'custom-invalid
)
1784 (defface custom-rogue
'((((class color
))
1785 (:foreground
"pink" :background
"black"))
1788 "Face used when the customize item is not defined for customization."
1789 :group
'custom-magic-faces
)
1790 ;; backward-compatibility alias
1791 (put 'custom-rogue-face
'face-alias
'custom-rogue
)
1793 (defface custom-modified
'((((min-colors 88) (class color
))
1794 (:foreground
"white" :background
"blue1"))
1796 (:foreground
"white" :background
"blue"))
1798 (:slant italic
:bold
)))
1799 "Face used when the customize item has been modified."
1800 :group
'custom-magic-faces
)
1801 ;; backward-compatibility alias
1802 (put 'custom-modified-face
'face-alias
'custom-modified
)
1804 (defface custom-set
'((((min-colors 88) (class color
))
1805 (:foreground
"blue1" :background
"white"))
1807 (:foreground
"blue" :background
"white"))
1810 "Face used when the customize item has been set."
1811 :group
'custom-magic-faces
)
1812 ;; backward-compatibility alias
1813 (put 'custom-set-face
'face-alias
'custom-set
)
1815 (defface custom-changed
'((((min-colors 88) (class color
))
1816 (:foreground
"white" :background
"blue1"))
1818 (:foreground
"white" :background
"blue"))
1821 "Face used when the customize item has been changed."
1822 :group
'custom-magic-faces
)
1823 ;; backward-compatibility alias
1824 (put 'custom-changed-face
'face-alias
'custom-changed
)
1826 (defface custom-themed
'((((min-colors 88) (class color
))
1827 (:foreground
"white" :background
"blue1"))
1829 (:foreground
"white" :background
"blue"))
1832 "Face used when the customize item has been set by a theme."
1833 :group
'custom-magic-faces
)
1835 (defface custom-saved
'((t (:underline t
)))
1836 "Face used when the customize item has been saved."
1837 :group
'custom-magic-faces
)
1838 ;; backward-compatibility alias
1839 (put 'custom-saved-face
'face-alias
'custom-saved
)
1841 (defconst custom-magic-alist
1842 '((nil "#" underline
"\
1843 UNINITIALIZED, you should not see this.")
1844 (unknown "?" italic
"\
1845 UNKNOWN, you should not see this.")
1846 (hidden "-" default
"\
1847 HIDDEN, invoke \"Show\" in the previous line to show." "\
1848 group now hidden, invoke \"Show\", above, to show contents.")
1849 (invalid "x" custom-invalid
"\
1850 INVALID, the displayed value cannot be set.")
1851 (modified "*" custom-modified
"\
1852 EDITED, shown value does not take effect until you set or save it." "\
1853 something in this group has been edited but not set.")
1854 (set "+" custom-set
"\
1855 SET for current session only." "\
1856 something in this group has been set but not saved.")
1857 (changed ":" custom-changed
"\
1858 CHANGED outside Customize; operating on it here may be unreliable." "\
1859 something in this group has been changed outside customize.")
1860 (saved "!" custom-saved
"\
1862 something in this group has been set and saved.")
1863 (themed "o" custom-themed
"\
1865 visible group members are all at standard values.")
1866 (rogue "@" custom-rogue
"\
1867 NO CUSTOMIZATION DATA; not intended to be customized." "\
1868 something in this group is not prepared for customization.")
1869 (standard " " nil
"\
1871 visible group members are all at standard values."))
1872 "Alist of customize option states.
1873 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1875 STATE is one of the following symbols:
1878 For internal use, should never occur.
1880 For internal use, should never occur.
1882 This item is not being displayed.
1884 This item is modified, but has an invalid form.
1886 This item is modified, and has a valid form.
1888 This item has been set but not saved.
1890 The current value of this item has been changed outside Customize.
1892 This item is marked for saving.
1894 This item has no customization information.
1896 This item is unchanged from the standard setting.
1898 MAGIC is a string used to present that state.
1900 FACE is a face used to present the state.
1902 ITEM-DESC is a string describing the state for options.
1904 GROUP-DESC is a string describing the state for groups. If this is
1905 left out, ITEM-DESC will be used.
1907 The string %c in either description will be replaced with the
1908 category of the item. These are `group'. `option', and `face'.
1910 The list should be sorted most significant first.")
1912 (defcustom custom-magic-show
'long
1913 "If non-nil, show textual description of the state.
1914 If `long', show a full-line description, not just one word."
1915 :type
'(choice (const :tag
"no" nil
)
1917 (other :tag
"short" short
))
1918 :group
'custom-buffer
)
1920 (defcustom custom-magic-show-hidden
'(option face
)
1921 "Control whether the State button is shown for hidden items.
1922 The value should be a list with the custom categories where the State
1923 button should be visible. Possible categories are `group', `option',
1925 :type
'(set (const group
) (const option
) (const face
))
1926 :group
'custom-buffer
)
1928 (defcustom custom-magic-show-button nil
1929 "Show a \"magic\" button indicating the state of each customization option."
1931 :group
'custom-buffer
)
1933 (define-widget 'custom-magic
'default
1934 "Show and manipulate state for a customization option."
1936 :action
'widget-parent-action
1939 :value-create
'custom-magic-value-create
1940 :value-delete
'widget-children-value-delete
)
1942 (defun widget-magic-mouse-down-action (widget &optional event
)
1943 ;; Non-nil unless hidden.
1944 (not (eq (widget-get (widget-get (widget-get widget
:parent
) :parent
)
1948 (defun custom-magic-value-create (widget)
1949 "Create compact status report for WIDGET."
1950 (let* ((parent (widget-get widget
:parent
))
1951 (state (widget-get parent
:custom-state
))
1952 (hidden (eq state
'hidden
))
1953 (entry (assq state custom-magic-alist
))
1954 (magic (nth 1 entry
))
1955 (face (nth 2 entry
))
1956 (category (widget-get parent
:custom-category
))
1957 (text (or (and (eq category
'group
)
1960 (form (widget-get parent
:custom-form
))
1962 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text
)
1963 (setq text
(concat (match-string 1 text
)
1964 (symbol-name category
)
1965 (match-string 2 text
))))
1966 (when (and custom-magic-show
1968 (memq category custom-magic-show-hidden
)))
1970 (when (and (eq category
'group
)
1971 (not (and (eq custom-buffer-style
'links
)
1972 (> (widget-get parent
:custom-level
) 1))))
1973 (insert-char ?\
(* custom-buffer-indent
1974 (widget-get parent
:custom-level
))))
1975 (push (widget-create-child-and-convert
1977 :help-echo
"Change the state of this item."
1978 :format
(if hidden
"%t" "%[%t%]")
1979 :button-prefix
'widget-push-button-prefix
1980 :button-suffix
'widget-push-button-suffix
1981 :mouse-down-action
'widget-magic-mouse-down-action
1985 (let ((start (point)))
1986 (if (eq custom-magic-show
'long
)
1988 (insert (symbol-name state
)))
1989 (cond ((eq form
'lisp
)
1991 ((eq form
'mismatch
)
1992 (insert " (mismatch)")))
1993 (put-text-property start
(point) 'face
'custom-state
))
1995 (when (and (eq category
'group
)
1996 (not (and (eq custom-buffer-style
'links
)
1997 (> (widget-get parent
:custom-level
) 1))))
1998 (insert-char ?\
(* custom-buffer-indent
1999 (widget-get parent
:custom-level
))))
2000 (when custom-magic-show-button
2001 (when custom-magic-show
2002 (let ((indent (widget-get parent
:indent
)))
2004 (insert-char ? indent
))))
2005 (push (widget-create-child-and-convert
2007 :mouse-down-action
'widget-magic-mouse-down-action
2011 :help-echo
"Change the state."
2012 :format
(if hidden
"%t" "%[%t%]")
2013 :tag
(if (memq form
'(lisp mismatch
))
2014 (concat "(" magic
")")
2015 (concat "[" magic
"]")))
2018 (widget-put widget
:children children
)))
2020 (defun custom-magic-reset (widget)
2021 "Redraw the :custom-magic property of WIDGET."
2022 (let ((magic (widget-get widget
:custom-magic
)))
2023 (widget-value-set magic
(widget-value magic
))))
2025 ;;; The `custom' Widget.
2027 (defface custom-button
2028 '((((type x w32 mac
) (class color
)) ; Like default modeline
2029 (:box
(:line-width
2 :style released-button
)
2030 :background
"lightgrey" :foreground
"black"))
2033 "Face for custom buffer buttons if `custom-raised-buttons' is non-nil."
2035 :group
'custom-faces
)
2036 ;; backward-compatibility alias
2037 (put 'custom-button-face
'face-alias
'custom-button
)
2039 (defface custom-button-mouse
2040 '((((type x w32 mac
) (class color
))
2041 (:box
(:line-width
2 :style released-button
)
2042 :background
"grey90" :foreground
"black"))
2045 "Mouse face for custom buffer buttons if `custom-raised-buttons' is non-nil."
2047 :group
'custom-faces
)
2049 (defface custom-button-unraised
2050 '((t :inherit underline
))
2051 "Face for custom buffer buttons if `custom-raised-buttons' is nil."
2053 :group
'custom-faces
)
2056 (if custom-raised-buttons
'custom-button
'custom-button-unraised
))
2058 (setq custom-button-mouse
2059 (if custom-raised-buttons
'custom-button-mouse
'highlight
))
2061 (defface custom-button-pressed
2062 '((((type x w32 mac
) (class color
))
2063 (:box
(:line-width
2 :style pressed-button
)
2064 :background
"lightgrey" :foreground
"black"))
2066 (:inverse-video t
)))
2067 "Face for pressed custom buttons if `custom-raised-buttons' is non-nil."
2069 :group
'custom-faces
)
2070 ;; backward-compatibility alias
2071 (put 'custom-button-pressed-face
'face-alias
'custom-button-pressed
)
2073 (defface custom-button-pressed-unraised
2074 '((default :inherit custom-button-unraised
)
2075 (((class color
) (background light
)) :foreground
"magenta4")
2076 (((class color
) (background dark
)) :foreground
"violet"))
2077 "Face for pressed custom buttons if `custom-raised-buttons' is nil."
2079 :group
'custom-faces
)
2081 (setq custom-button-pressed
2082 (if custom-raised-buttons
2083 'custom-button-pressed
2084 'custom-button-pressed-unraised
))
2086 (defface custom-documentation
'((t nil
))
2087 "Face used for documentation strings in customization buffers."
2088 :group
'custom-faces
)
2089 ;; backward-compatibility alias
2090 (put 'custom-documentation-face
'face-alias
'custom-documentation
)
2092 (defface custom-state
'((((class color
)
2094 (:foreground
"lime green"))
2097 (:foreground
"dark green"))
2099 "Face used for State descriptions in the customize buffer."
2100 :group
'custom-faces
)
2101 ;; backward-compatibility alias
2102 (put 'custom-state-face
'face-alias
'custom-state
)
2104 (defface custom-link
2105 '((t :inherit link
))
2106 "Face for links in customization buffers."
2108 :group
'custom-faces
)
2110 (define-widget 'custom
'default
2111 "Customize a user option."
2113 :convert-widget
'custom-convert-widget
2114 :notify
'custom-notify
2117 :custom-state
'hidden
2118 :documentation-property
'widget-subclass-responsibility
2119 :value-create
'widget-subclass-responsibility
2120 :value-delete
'widget-children-value-delete
2121 :value-get
'widget-value-value-get
2122 :validate
'widget-children-validate
2123 :match
(lambda (widget value
) (symbolp value
)))
2125 (defun custom-convert-widget (widget)
2126 "Initialize :value and :tag from :args in WIDGET."
2127 (let ((args (widget-get widget
:args
)))
2129 (widget-put widget
:value
(widget-apply widget
2130 :value-to-internal
(car args
)))
2131 (widget-put widget
:tag
(custom-unlispify-tag-name (car args
)))
2132 (widget-put widget
:args nil
)))
2135 (defun custom-notify (widget &rest args
)
2136 "Keep track of changes."
2137 (let ((state (widget-get widget
:custom-state
)))
2138 (unless (eq state
'modified
)
2139 (unless (memq state
'(nil unknown hidden
))
2140 (widget-put widget
:custom-state
'modified
))
2141 (custom-magic-reset widget
)
2142 (apply 'widget-default-notify widget args
))))
2144 (defun custom-redraw (widget)
2145 "Redraw WIDGET with current settings."
2146 (let ((line (count-lines (point-min) (point)))
2147 (column (current-column))
2149 (from (marker-position (widget-get widget
:from
)))
2150 (to (marker-position (widget-get widget
:to
))))
2152 (widget-value-set widget
(widget-value widget
))
2153 (custom-redraw-magic widget
))
2154 (when (and (>= pos from
) (<= pos to
))
2159 (goto-line (1+ line
)))
2160 (move-to-column column
))
2163 (defun custom-redraw-magic (widget)
2164 "Redraw WIDGET state with current settings."
2166 (let ((magic (widget-get widget
:custom-magic
)))
2168 (widget-value-set magic
(widget-value magic
))
2169 (when (setq widget
(widget-get widget
:group
))
2170 (custom-group-state-update widget
)))
2172 (setq widget nil
)))))
2175 (defun custom-show (widget value
)
2176 "Non-nil if WIDGET should be shown with VALUE by default."
2177 (let ((show (widget-get widget
:custom-show
)))
2183 (funcall show widget value
)))))
2185 (defun custom-load-widget (widget)
2186 "Load all dependencies for WIDGET."
2187 (custom-load-symbol (widget-value widget
)))
2189 (defun custom-unloaded-symbol-p (symbol)
2190 "Return non-nil if the dependencies of SYMBOL have not yet been loaded."
2192 (loads (get symbol
'custom-loads
))
2195 (setq load
(car loads
)
2197 (cond ((symbolp load
)
2198 (unless (featurep load
)
2200 ((assoc load load-history
))
2201 ((assoc (locate-library load
) load-history
)
2207 (defun custom-unloaded-widget-p (widget)
2208 "Return non-nil if the dependencies of WIDGET have not yet been loaded."
2209 (custom-unloaded-symbol-p (widget-value widget
)))
2211 (defun custom-toggle-hide (widget)
2212 "Toggle visibility of WIDGET."
2213 (custom-load-widget widget
)
2214 (let ((state (widget-get widget
:custom-state
)))
2215 (cond ((memq state
'(invalid modified
))
2216 (error "There are unset changes"))
2218 (widget-put widget
:custom-state
'unknown
))
2220 (widget-put widget
:documentation-shown nil
)
2221 (widget-put widget
:custom-state
'hidden
)))
2222 (custom-redraw widget
)
2225 (defun custom-toggle-parent (widget &rest ignore
)
2226 "Toggle visibility of parent of WIDGET."
2227 (custom-toggle-hide (widget-get widget
:parent
)))
2229 (defun custom-add-see-also (widget &optional prefix
)
2230 "Add `See also ...' to WIDGET if there are any links.
2231 Insert PREFIX first if non-nil."
2232 (let* ((symbol (widget-get widget
:value
))
2233 (links (get symbol
'custom-links
))
2234 (many (> (length links
) 2))
2235 (buttons (widget-get widget
:buttons
))
2236 (indent (widget-get widget
:indent
)))
2239 (insert-char ?\ indent
))
2242 (insert "See also ")
2244 (push (widget-create-child-and-convert
2246 :button-face
'custom-link
2247 :mouse-face
'highlight
2248 :pressed-face
'highlight
)
2250 (setq links
(cdr links
))
2259 (widget-put widget
:buttons buttons
))))
2261 (defun custom-add-parent-links (widget &optional initial-string
)
2262 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
2263 The value is non-nil if any parents were found.
2264 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
2265 (let ((name (widget-value widget
))
2266 (type (widget-type widget
))
2267 (buttons (widget-get widget
:buttons
))
2270 (insert (or initial-string
"Parent groups:"))
2271 (mapatoms (lambda (symbol)
2272 (when (member (list name type
) (get symbol
'custom-group
))
2274 (push (widget-create-child-and-convert
2275 widget
'custom-group-link
2276 :tag
(custom-unlispify-tag-name symbol
)
2279 (setq parents
(cons symbol parents
)))))
2280 (and (null (get name
'custom-links
)) ;No links of its own.
2281 (= (length parents
) 1) ;A single parent.
2282 (let* ((links (delq nil
(mapcar (lambda (w)
2283 (unless (eq (widget-type w
)
2286 (get (car parents
) 'custom-links
))))
2287 (many (> (length links
) 2)))
2289 (insert "\nParent documentation: ")
2291 (push (widget-create-child-and-convert
2293 :button-face
'custom-link
2294 :mouse-face
'highlight
2295 :pressed-face
'highlight
)
2297 (setq links
(cdr links
))
2308 (delete-region start
(point)))
2309 (widget-put widget
:buttons buttons
)
2312 ;;; The `custom-comment' Widget.
2314 ;; like the editable field
2315 (defface custom-comment
'((((type tty
))
2316 :background
"yellow3"
2317 :foreground
"black")
2318 (((class grayscale color
)
2320 :background
"gray85")
2321 (((class grayscale color
)
2323 :background
"dim gray")
2326 "Face used for comments on variables or faces"
2328 :group
'custom-faces
)
2329 ;; backward-compatibility alias
2330 (put 'custom-comment-face
'face-alias
'custom-comment
)
2332 ;; like font-lock-comment-face
2333 (defface custom-comment-tag
2334 '((((class color
) (background dark
)) (:foreground
"gray80"))
2335 (((class color
) (background light
)) (:foreground
"blue4"))
2336 (((class grayscale
) (background light
))
2337 (:foreground
"DimGray" :weight bold
:slant italic
))
2338 (((class grayscale
) (background dark
))
2339 (:foreground
"LightGray" :weight bold
:slant italic
))
2341 "Face used for variables or faces comment tags"
2342 :group
'custom-faces
)
2343 ;; backward-compatibility alias
2344 (put 'custom-comment-tag-face
'face-alias
'custom-comment-tag
)
2346 (define-widget 'custom-comment
'string
2349 :help-echo
"Edit a comment here."
2350 :sample-face
'custom-comment-tag-face
2351 :value-face
'custom-comment-face
2353 :create
'custom-comment-create
)
2355 (defun custom-comment-create (widget)
2356 (let* ((null-comment (equal "" (widget-value widget
))))
2357 (if (or (widget-get (widget-get widget
:parent
) :comment-shown
)
2359 (widget-default-create widget
)
2360 ;; `widget-default-delete' expects markers in these slots --
2361 ;; maybe it shouldn't.
2362 (widget-put widget
:from
(point-marker))
2363 (widget-put widget
:to
(point-marker)))))
2365 (defun custom-comment-hide (widget)
2366 (widget-put (widget-get widget
:parent
) :comment-shown nil
))
2368 ;; Those functions are for the menu. WIDGET is NOT the comment widget. It's
2369 ;; the global custom one
2370 (defun custom-comment-show (widget)
2371 (widget-put widget
:comment-shown t
)
2372 (custom-redraw widget
)
2375 (defun custom-comment-invisible-p (widget)
2376 (let ((val (widget-value (widget-get widget
:comment-widget
))))
2378 (not (widget-get widget
:comment-shown
)))))
2380 ;;; The `custom-variable' Widget.
2382 ;; When this was underlined blue, users confused it with a
2383 ;; Mosaic-style hyperlink...
2384 (defface custom-variable-tag
2387 (:foreground
"light blue" :weight bold
))
2388 (((min-colors 88) (class color
)
2390 (:foreground
"blue1" :weight bold
))
2393 (:foreground
"blue" :weight bold
))
2395 "Face used for unpushable variable tags."
2396 :group
'custom-faces
)
2397 ;; backward-compatibility alias
2398 (put 'custom-variable-tag-face
'face-alias
'custom-variable-tag
)
2400 (defface custom-variable-button
'((t (:underline t
:weight bold
)))
2401 "Face used for pushable variable tags."
2402 :group
'custom-faces
)
2403 ;; backward-compatibility alias
2404 (put 'custom-variable-button-face
'face-alias
'custom-variable-button
)
2406 (defcustom custom-variable-default-form
'edit
2407 "Default form of displaying variable values."
2408 :type
'(choice (const edit
)
2410 :group
'custom-buffer
2413 (defun custom-variable-documentation (variable)
2414 "Return documentation of VARIABLE for use in Custom buffer.
2415 Normally just return the docstring. But if VARIABLE automatically
2416 becomes buffer local when set, append a message to that effect."
2417 (if (and (local-variable-if-set-p variable
)
2418 (or (not (local-variable-p variable
))
2420 (local-variable-if-set-p variable
))))
2421 (concat (documentation-property variable
'variable-documentation
)
2423 This variable automatically becomes buffer-local when set outside Custom.
2424 However, setting it through Custom sets the default value.")
2425 (documentation-property variable
'variable-documentation
)))
2427 (define-widget 'custom-variable
'custom
2428 "Customize variable."
2430 :help-echo
"Set or reset this variable."
2431 :documentation-property
#'custom-variable-documentation
2432 :custom-category
'option
2434 :custom-menu
'custom-variable-menu-create
2435 :custom-form nil
; defaults to value of `custom-variable-default-form'
2436 :value-create
'custom-variable-value-create
2437 :action
'custom-variable-action
2438 :custom-set
'custom-variable-set
2439 :custom-save
'custom-variable-save
2440 :custom-reset-current
'custom-redraw
2441 :custom-reset-saved
'custom-variable-reset-saved
2442 :custom-reset-standard
'custom-variable-reset-standard
2443 :custom-standard-value
'custom-variable-standard-value
)
2445 (defun custom-variable-type (symbol)
2446 "Return a widget suitable for editing the value of SYMBOL.
2447 If SYMBOL has a `custom-type' property, use that.
2448 Otherwise, try matching SYMBOL against `custom-guess-name-alist' and
2449 try matching its doc string against `custom-guess-doc-alist'."
2450 (let* ((type (or (get symbol
'custom-type
)
2451 (and (not (get symbol
'standard-value
))
2452 (custom-guess-type symbol
))
2454 (options (get symbol
'custom-options
))
2455 (tmp (if (listp type
)
2456 (copy-sequence type
)
2459 (widget-put tmp
:options options
))
2462 (defun custom-variable-value-create (widget)
2463 "Here is where you edit the variable's value."
2464 (custom-load-widget widget
)
2465 (unless (widget-get widget
:custom-form
)
2466 (widget-put widget
:custom-form custom-variable-default-form
))
2467 (let* ((buttons (widget-get widget
:buttons
))
2468 (children (widget-get widget
:children
))
2469 (form (widget-get widget
:custom-form
))
2470 (state (widget-get widget
:custom-state
))
2471 (symbol (widget-get widget
:value
))
2472 (tag (widget-get widget
:tag
))
2473 (type (custom-variable-type symbol
))
2474 (conv (widget-convert type
))
2475 (get (or (get symbol
'custom-get
) 'default-value
))
2476 (prefix (widget-get widget
:custom-prefix
))
2477 (last (widget-get widget
:custom-last
))
2478 (value (if (default-boundp symbol
)
2479 (funcall get symbol
)
2480 (widget-get conv
:value
))))
2481 ;; If the widget is new, the child determines whether it is hidden.
2483 ((custom-show type value
)
2484 (setq state
'unknown
))
2486 (setq state
'hidden
)))
2487 ;; If we don't know the state, see if we need to edit it in lisp form.
2488 (when (eq state
'unknown
)
2489 (unless (widget-apply conv
:match value
)
2490 ;; (widget-apply (widget-convert type) :match value)
2491 (setq form
'mismatch
)))
2492 ;; Now we can create the child widget.
2493 (cond ((eq custom-buffer-style
'tree
)
2494 (insert prefix
(if last
" `--- " " |--- "))
2495 (push (widget-create-child-and-convert
2496 widget
'custom-browse-variable-tag
)
2498 (insert " " tag
"\n")
2499 (widget-put widget
:buttons buttons
))
2501 ;; Indicate hidden value.
2502 (push (widget-create-child-and-convert
2505 :sample-face
'custom-variable-tag-face
2509 (push (widget-create-child-and-convert
2511 :help-echo
"Show the value of this option."
2513 :action
'custom-toggle-parent
2516 ((memq form
'(lisp mismatch
))
2517 ;; In lisp mode edit the saved value when possible.
2518 (let* ((value (cond ((get symbol
'saved-value
)
2519 (car (get symbol
'saved-value
)))
2520 ((get symbol
'standard-value
)
2521 (car (get symbol
'standard-value
)))
2522 ((default-boundp symbol
)
2523 (custom-quote (funcall get symbol
)))
2525 (custom-quote (widget-get conv
:value
))))))
2526 (insert (symbol-name symbol
) ": ")
2527 (push (widget-create-child-and-convert
2529 :help-echo
"Hide the value of this option."
2532 :action
'custom-toggle-parent
2536 (push (widget-create-child-and-convert
2538 :button-face
'custom-variable-button-face
2540 :tag
(symbol-name symbol
)
2546 (let* ((format (widget-get type
:format
))
2547 tag-format value-format
)
2548 (unless (string-match ":" format
)
2549 (error "Bad format"))
2550 (setq tag-format
(substring format
0 (match-end 0)))
2551 (setq value-format
(substring format
(match-end 0)))
2552 (push (widget-create-child-and-convert
2555 :action
'custom-tag-action
2556 :help-echo
"Change value of this option."
2557 :mouse-down-action
'custom-tag-mouse-down-action
2558 :button-face
'custom-variable-button-face
2559 :sample-face
'custom-variable-tag-face
2563 (push (widget-create-child-and-convert
2565 :help-echo
"Hide the value of this option."
2568 :action
'custom-toggle-parent
2571 (push (widget-create-child-and-convert
2573 :format value-format
2576 (unless (eq custom-buffer-style
'tree
)
2577 (unless (eq (preceding-char) ?
\n)
2578 (widget-insert "\n"))
2579 ;; Create the magic button.
2580 (let ((magic (widget-create-child-and-convert
2581 widget
'custom-magic nil
)))
2582 (widget-put widget
:custom-magic magic
)
2583 (push magic buttons
))
2584 (widget-put widget
:buttons buttons
)
2585 ;; Insert documentation.
2586 (widget-put widget
:documentation-indent
3)
2587 (widget-add-documentation-string-button
2588 widget
:visibility-widget
'custom-visibility
)
2590 ;; The comment field
2591 (unless (eq state
'hidden
)
2592 (let* ((comment (get symbol
'variable-comment
))
2594 (widget-create-child-and-convert
2595 widget
'custom-comment
2597 :value
(or comment
""))))
2598 (widget-put widget
:comment-widget comment-widget
)
2599 ;; Don't push it !!! Custom assumes that the first child is the
2601 (setq children
(append children
(list comment-widget
)))))
2602 ;; Update the rest of the properties properties.
2603 (widget-put widget
:custom-form form
)
2604 (widget-put widget
:children children
)
2605 ;; Now update the state.
2606 (if (eq state
'hidden
)
2607 (widget-put widget
:custom-state state
)
2608 (custom-variable-state-set widget
))
2610 (unless (eq state
'hidden
)
2611 (when (eq (widget-get widget
:custom-level
) 1)
2612 (custom-add-parent-links widget
))
2613 (custom-add-see-also widget
)))))
2615 (defun custom-tag-action (widget &rest args
)
2616 "Pass :action to first child of WIDGET's parent."
2617 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2620 (defun custom-tag-mouse-down-action (widget &rest args
)
2621 "Pass :mouse-down-action to first child of WIDGET's parent."
2622 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2623 :mouse-down-action args
))
2625 (defun custom-variable-state-set (widget)
2626 "Set the state of WIDGET."
2627 (let* ((symbol (widget-value widget
))
2628 (get (or (get symbol
'custom-get
) 'default-value
))
2629 (value (if (default-boundp symbol
)
2630 (funcall get symbol
)
2631 (widget-get widget
:value
)))
2632 (comment (get symbol
'variable-comment
))
2635 (state (cond ((progn (setq tmp
(get symbol
'customized-value
))
2637 (get symbol
'customized-variable-comment
))
2639 (if (condition-case nil
2640 (and (equal value
(eval (car tmp
)))
2641 (equal comment temp
))
2645 ((progn (setq tmp
(get symbol
'theme-value
))
2646 (setq temp
(get symbol
'saved-variable-comment
))
2648 (if (condition-case nil
2649 (and (equal comment temp
)
2652 (car (custom-variable-theme-value
2656 ((eq (caar tmp
) 'user
) 'saved
)
2657 ((eq (caar tmp
) 'changed
)
2658 (if (condition-case nil
2662 (car (get symbol
'standard-value
)))))
2664 ;; The value was originally set outside
2665 ;; custom, but it was set to the standard
2666 ;; value (probably an autoloaded defcustom).
2671 ((setq tmp
(get symbol
'standard-value
))
2672 (if (condition-case nil
2673 (and (equal value
(eval (car tmp
)))
2674 (equal comment nil
))
2679 (widget-put widget
:custom-state state
)))
2681 (defun custom-variable-standard-value (widget)
2682 (get (widget-value widget
) 'standard-value
))
2684 (defvar custom-variable-menu
2685 `(("Set for Current Session" custom-variable-set
2687 (eq (widget-get widget
:custom-state
) 'modified
)))
2688 ,@(when (or custom-file user-init-file
)
2689 '(("Save for Future Sessions" custom-variable-save
2691 (memq (widget-get widget
:custom-state
)
2692 '(modified set changed rogue
))))))
2693 ("Undo Edits" custom-redraw
2695 (and (default-boundp (widget-value widget
))
2696 (memq (widget-get widget
:custom-state
) '(modified changed
)))))
2697 ("Reset to Saved" custom-variable-reset-saved
2699 (and (or (get (widget-value widget
) 'saved-value
)
2700 (get (widget-value widget
) 'saved-variable-comment
))
2701 (memq (widget-get widget
:custom-state
)
2702 '(modified set changed rogue
)))))
2703 ,@(when (or custom-file user-init-file
)
2704 '(("Erase Customization" custom-variable-reset-standard
2706 (and (get (widget-value widget
) 'standard-value
)
2707 (memq (widget-get widget
:custom-state
)
2708 '(modified set changed saved rogue
)))))))
2709 ("Set to Backup Value" custom-variable-reset-backup
2711 (get (widget-value widget
) 'backup-value
)))
2712 ("---" ignore ignore
)
2713 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
2714 ("---" ignore ignore
)
2715 ("Show Current Value" custom-variable-edit
2717 (eq (widget-get widget
:custom-form
) 'lisp
)))
2718 ("Show Saved Lisp Expression" custom-variable-edit-lisp
2720 (eq (widget-get widget
:custom-form
) 'edit
))))
2721 "Alist of actions for the `custom-variable' widget.
2722 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2723 the menu entry, ACTION is the function to call on the widget when the
2724 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2725 widget as an argument, and returns non-nil if ACTION is valid on that
2726 widget. If FILTER is nil, ACTION is always valid.")
2728 (defun custom-variable-action (widget &optional event
)
2729 "Show the menu for `custom-variable' WIDGET.
2730 Optional EVENT is the location for the menu."
2731 (if (eq (widget-get widget
:custom-state
) 'hidden
)
2732 (custom-toggle-hide widget
)
2733 (unless (eq (widget-get widget
:custom-state
) 'modified
)
2734 (custom-variable-state-set widget
))
2735 (custom-redraw-magic widget
)
2736 (let* ((completion-ignore-case t
)
2737 (answer (widget-choose (concat "Operation on "
2738 (custom-unlispify-tag-name
2739 (widget-get widget
:value
)))
2740 (custom-menu-filter custom-variable-menu
2744 (funcall answer widget
)))))
2746 (defun custom-variable-edit (widget)
2747 "Edit value of WIDGET."
2748 (widget-put widget
:custom-state
'unknown
)
2749 (widget-put widget
:custom-form
'edit
)
2750 (custom-redraw widget
))
2752 (defun custom-variable-edit-lisp (widget)
2753 "Edit the Lisp representation of the value of WIDGET."
2754 (widget-put widget
:custom-state
'unknown
)
2755 (widget-put widget
:custom-form
'lisp
)
2756 (custom-redraw widget
))
2758 (defun custom-variable-set (widget)
2759 "Set the current value for the variable being edited by WIDGET."
2760 (let* ((form (widget-get widget
:custom-form
))
2761 (state (widget-get widget
:custom-state
))
2762 (child (car (widget-get widget
:children
)))
2763 (symbol (widget-value widget
))
2764 (set (or (get symbol
'custom-set
) 'set-default
))
2765 (comment-widget (widget-get widget
:comment-widget
))
2766 (comment (widget-value comment-widget
))
2768 (cond ((eq state
'hidden
)
2769 (error "Cannot set hidden variable"))
2770 ((setq val
(widget-apply child
:validate
))
2771 (goto-char (widget-get val
:from
))
2772 (error "%s" (widget-get val
:error
)))
2773 ((memq form
'(lisp mismatch
))
2774 (when (equal comment
"")
2776 ;; Make the comment invisible by hand if it's empty
2777 (custom-comment-hide comment-widget
))
2778 (custom-variable-backup-value widget
)
2779 (custom-push-theme 'theme-value symbol
'user
2780 'set
(custom-quote (widget-value child
)))
2781 (funcall set symbol
(eval (setq val
(widget-value child
))))
2782 (put symbol
'customized-value
(list val
))
2783 (put symbol
'variable-comment comment
)
2784 (put symbol
'customized-variable-comment comment
))
2786 (when (equal comment
"")
2788 ;; Make the comment invisible by hand if it's empty
2789 (custom-comment-hide comment-widget
))
2790 (custom-variable-backup-value widget
)
2791 (custom-push-theme 'theme-value symbol
'user
2792 'set
(custom-quote (widget-value child
)))
2793 (funcall set symbol
(setq val
(widget-value child
)))
2794 (put symbol
'customized-value
(list (custom-quote val
)))
2795 (put symbol
'variable-comment comment
)
2796 (put symbol
'customized-variable-comment comment
)))
2797 (custom-variable-state-set widget
)
2798 (custom-redraw-magic widget
)))
2800 (defun custom-variable-save (widget)
2801 "Set and save the value for the variable being edited by WIDGET."
2802 (let* ((form (widget-get widget
:custom-form
))
2803 (state (widget-get widget
:custom-state
))
2804 (child (car (widget-get widget
:children
)))
2805 (symbol (widget-value widget
))
2806 (set (or (get symbol
'custom-set
) 'set-default
))
2807 (comment-widget (widget-get widget
:comment-widget
))
2808 (comment (widget-value comment-widget
))
2810 (cond ((eq state
'hidden
)
2811 (error "Cannot set hidden variable"))
2812 ((setq val
(widget-apply child
:validate
))
2813 (goto-char (widget-get val
:from
))
2814 (error "Saving %s: %s" symbol
(widget-get val
:error
)))
2815 ((memq form
'(lisp mismatch
))
2816 (when (equal comment
"")
2818 ;; Make the comment invisible by hand if it's empty
2819 (custom-comment-hide comment-widget
))
2820 (put symbol
'saved-value
(list (widget-value child
)))
2821 (custom-push-theme 'theme-value symbol
'user
2822 'set
(custom-quote (widget-value child
)))
2823 (funcall set symbol
(eval (widget-value child
)))
2824 (put symbol
'variable-comment comment
)
2825 (put symbol
'saved-variable-comment comment
))
2827 (when (equal comment
"")
2829 ;; Make the comment invisible by hand if it's empty
2830 (custom-comment-hide comment-widget
))
2831 (put symbol
'saved-value
2832 (list (custom-quote (widget-value child
))))
2833 (custom-push-theme 'theme-value symbol
'user
2834 'set
(custom-quote (widget-value child
)))
2835 (funcall set symbol
(widget-value child
))
2836 (put symbol
'variable-comment comment
)
2837 (put symbol
'saved-variable-comment comment
)))
2838 (put symbol
'customized-value nil
)
2839 (put symbol
'customized-variable-comment nil
)
2841 (custom-variable-state-set widget
)
2842 (custom-redraw-magic widget
)))
2844 (defun custom-variable-reset-saved (widget)
2845 "Restore the saved value for the variable being edited by WIDGET.
2846 This also updates the buffer to show that value.
2847 The value that was current before this operation
2848 becomes the backup value, so you can get it again."
2849 (let* ((symbol (widget-value widget
))
2850 (set (or (get symbol
'custom-set
) 'set-default
))
2851 (value (get symbol
'saved-value
))
2852 (comment (get symbol
'saved-variable-comment
)))
2853 (cond ((or value comment
)
2854 (put symbol
'variable-comment comment
)
2855 (custom-variable-backup-value widget
)
2856 (custom-push-theme 'theme-value symbol
'user
'set
(car-safe value
))
2858 (funcall set symbol
(eval (car value
)))
2861 (error "No saved value for %s" symbol
)))
2862 (put symbol
'customized-value nil
)
2863 (put symbol
'customized-variable-comment nil
)
2864 (widget-put widget
:custom-state
'unknown
)
2865 ;; This call will possibly make the comment invisible
2866 (custom-redraw widget
)))
2868 (defun custom-variable-reset-standard (widget)
2869 "Restore the standard setting for the variable being edited by WIDGET.
2870 This operation eliminates any saved setting for the variable,
2871 restoring it to the state of a variable that has never been customized.
2872 The value that was current before this operation
2873 becomes the backup value, so you can get it again."
2874 (let* ((symbol (widget-value widget
)))
2875 (if (get symbol
'standard-value
)
2876 (custom-variable-backup-value widget
)
2877 (error "No standard setting known for %S" symbol
))
2878 (put symbol
'variable-comment nil
)
2879 (put symbol
'customized-value nil
)
2880 (put symbol
'customized-variable-comment nil
)
2881 (custom-push-theme 'theme-value symbol
'user
'reset
)
2882 (custom-theme-recalc-variable symbol
)
2883 (when (or (get symbol
'saved-value
) (get symbol
'saved-variable-comment
))
2884 (put symbol
'saved-value nil
)
2885 (put symbol
'saved-variable-comment nil
)
2887 (widget-put widget
:custom-state
'unknown
)
2888 ;; This call will possibly make the comment invisible
2889 (custom-redraw widget
)))
2891 (defun custom-variable-backup-value (widget)
2892 "Back up the current value for WIDGET's variable.
2893 The backup value is kept in the car of the `backup-value' property."
2894 (let* ((symbol (widget-value widget
))
2895 (get (or (get symbol
'custom-get
) 'default-value
))
2896 (type (custom-variable-type symbol
))
2897 (conv (widget-convert type
))
2898 (value (if (default-boundp symbol
)
2899 (funcall get symbol
)
2900 (widget-get conv
:value
))))
2901 (put symbol
'backup-value
(list value
))))
2903 (defun custom-variable-reset-backup (widget)
2904 "Restore the backup value for the variable being edited by WIDGET.
2905 The value that was current before this operation
2906 becomes the backup value, so you can use this operation repeatedly
2907 to switch between two values."
2908 (let* ((symbol (widget-value widget
))
2909 (set (or (get symbol
'custom-set
) 'set-default
))
2910 (value (get symbol
'backup-value
))
2911 (comment-widget (widget-get widget
:comment-widget
))
2912 (comment (widget-value comment-widget
)))
2915 (custom-variable-backup-value widget
)
2916 (custom-push-theme 'theme-value symbol
'user
'set value
)
2918 (funcall set symbol
(car value
))
2920 (error "No backup value for %s" symbol
))
2921 (put symbol
'customized-value
(list (car value
)))
2922 (put symbol
'variable-comment comment
)
2923 (put symbol
'customized-variable-comment comment
)
2924 (custom-variable-state-set widget
)
2925 ;; This call will possibly make the comment invisible
2926 (custom-redraw widget
)))
2928 ;;; The `custom-visibility' Widget
2930 (define-widget 'custom-visibility
'visibility
2931 "Show or hide a documentation string."
2932 :button-face
'custom-visibility
2933 :pressed-face
'custom-visibility
2934 :mouse-face
'highlight
2935 :pressed-face
'highlight
)
2937 (defface custom-visibility
2938 '((t :height
0.8 :inherit link
))
2939 "Face for the `custom-visibility' widget."
2941 :group
'custom-faces
)
2943 ;;; The `custom-face-edit' Widget.
2945 (define-widget 'custom-face-edit
'checklist
2946 "Edit face attributes."
2950 :button-args
'(:help-echo
"Control whether this attribute has any effect.")
2951 :value-to-internal
'custom-face-edit-fix-value
2952 :match
(lambda (widget value
)
2953 (widget-checklist-match widget
2954 (custom-face-edit-fix-value widget value
)))
2955 :convert-widget
'custom-face-edit-convert-widget
2956 :args
(mapcar (lambda (att)
2959 :sibling-args
(widget-get (nth 1 att
) :sibling-args
)
2960 (list 'const
:format
"" :value
(nth 0 att
))
2962 custom-face-attributes
))
2964 (defun custom-face-edit-fix-value (widget value
)
2965 "Ignoring WIDGET, convert :bold and :italic in VALUE to new form.
2966 Also change :reverse-video to :inverse-video."
2970 (let ((key (car value
))
2971 (val (car (cdr value
))))
2972 (cond ((eq key
:italic
)
2973 (push :slant result
)
2974 (push (if val
'italic
'normal
) result
))
2976 (push :weight result
)
2977 (push (if val
'bold
'normal
) result
))
2978 ((eq key
:reverse-video
)
2979 (push :inverse-video result
)
2983 (push val result
))))
2984 (setq value
(cdr (cdr value
))))
2985 (setq result
(nreverse result
))
2989 (defun custom-face-edit-convert-widget (widget)
2990 "Convert :args as widget types in WIDGET."
2993 :args
(mapcar (lambda (arg)
2995 :deactivate
'custom-face-edit-deactivate
2996 :activate
'custom-face-edit-activate
2997 :delete
'custom-face-edit-delete
))
2998 (widget-get widget
:args
)))
3001 (defun custom-face-edit-deactivate (widget)
3002 "Make face widget WIDGET inactive for user modifications."
3003 (unless (widget-get widget
:inactive
)
3004 (let ((tag (custom-face-edit-attribute-tag widget
))
3005 (from (copy-marker (widget-get widget
:from
)))
3006 (value (widget-value widget
))
3007 (inhibit-read-only t
)
3008 (inhibit-modification-hooks t
))
3011 (widget-default-delete widget
)
3012 (insert tag
": *\n")
3013 (widget-put widget
:inactive
3014 (cons value
(cons from
(- (point) from
))))))))
3016 (defun custom-face-edit-activate (widget)
3017 "Make face widget WIDGET inactive for user modifications."
3018 (let ((inactive (widget-get widget
:inactive
))
3019 (inhibit-read-only t
)
3020 (inhibit-modification-hooks t
))
3021 (when (consp inactive
)
3023 (goto-char (car (cdr inactive
)))
3024 (delete-region (point) (+ (point) (cdr (cdr inactive
))))
3025 (widget-put widget
:inactive nil
)
3026 (widget-apply widget
:create
)
3027 (widget-value-set widget
(car inactive
))
3030 (defun custom-face-edit-delete (widget)
3031 "Remove WIDGET from the buffer."
3032 (let ((inactive (widget-get widget
:inactive
))
3033 (inhibit-read-only t
)
3034 (inhibit-modification-hooks t
))
3036 ;; Widget is alive, we don't have to do anything special
3037 (widget-default-delete widget
)
3038 ;; WIDGET is already deleted because we did so to inactivate it;
3039 ;; now just get rid of the label we put in its place.
3040 (delete-region (car (cdr inactive
))
3041 (+ (car (cdr inactive
)) (cdr (cdr inactive
))))
3042 (widget-put widget
:inactive nil
))))
3045 (defun custom-face-edit-attribute-tag (widget)
3046 "Returns the first :tag property in WIDGET or one of its children."
3047 (let ((tag (widget-get widget
:tag
)))
3048 (or (and (not (equal tag
"")) tag
)
3049 (let ((children (widget-get widget
:children
)))
3050 (while (and (null tag
) children
)
3051 (setq tag
(custom-face-edit-attribute-tag (pop children
))))
3054 ;;; The `custom-display' Widget.
3056 (define-widget 'custom-display
'menu-choice
3057 "Select a display type."
3060 :help-echo
"Specify frames where the face attributes should be used."
3061 :args
'((const :tag
"all" t
)
3062 (const :tag
"defaults" default
)
3066 :args
((group :sibling-args
(:help-echo
"\
3067 Only match the specified window systems.")
3068 (const :format
"Type: "
3070 (checklist :inline t
3073 :sibling-args
(:help-echo
"\
3074 The X11 Window System.")
3076 (const :format
"PM "
3077 :sibling-args
(:help-echo
"\
3078 OS/2 Presentation Manager.")
3080 (const :format
"W32 "
3081 :sibling-args
(:help-echo
"\
3084 (const :format
"MAC "
3085 :sibling-args
(:help-echo
"\
3088 (const :format
"DOS "
3089 :sibling-args
(:help-echo
"\
3092 (const :format
"TTY%n"
3093 :sibling-args
(:help-echo
"\
3094 Plain text terminals.")
3096 (group :sibling-args
(:help-echo
"\
3097 Only match the frames with the specified color support.")
3098 (const :format
"Class: "
3100 (checklist :inline t
3102 (const :format
"Color "
3103 :sibling-args
(:help-echo
"\
3104 Match color frames.")
3106 (const :format
"Grayscale "
3107 :sibling-args
(:help-echo
"\
3108 Match grayscale frames.")
3110 (const :format
"Monochrome%n"
3111 :sibling-args
(:help-echo
"\
3112 Match frames with no color support.")
3114 (group :sibling-args
(:help-echo
"\
3115 The minimum number of colors the frame should support.")
3116 (const :format
"" min-colors
)
3117 (integer :tag
"Minimum number of colors" ))
3118 (group :sibling-args
(:help-echo
"\
3119 Only match frames with the specified intensity.")
3121 Background brightness: "
3123 (checklist :inline t
3125 (const :format
"Light "
3126 :sibling-args
(:help-echo
"\
3127 Match frames with light backgrounds.")
3129 (const :format
"Dark\n"
3130 :sibling-args
(:help-echo
"\
3131 Match frames with dark backgrounds.")
3133 (group :sibling-args
(:help-echo
"\
3134 Only match frames that support the specified face attributes.")
3135 (const :format
"Supports attributes:" supports
)
3136 (custom-face-edit :inline t
:format
"%n%v"))))))
3138 ;;; The `custom-face' Widget.
3140 (defface custom-face-tag
3141 `((t (:weight bold
:height
1.2 :inherit variable-pitch
)))
3142 "Face used for face tags."
3143 :group
'custom-faces
)
3144 ;; backward-compatibility alias
3145 (put 'custom-face-tag-face
'face-alias
'custom-face-tag
)
3147 (defcustom custom-face-default-form
'selected
3148 "Default form of displaying face definition."
3149 :type
'(choice (const all
)
3152 :group
'custom-buffer
3155 (define-widget 'custom-face
'custom
3157 :sample-face
'custom-face-tag-face
3158 :help-echo
"Set or reset this face."
3159 :documentation-property
#'face-doc-string
3160 :value-create
'custom-face-value-create
3161 :action
'custom-face-action
3162 :custom-category
'face
3163 :custom-form nil
; defaults to value of `custom-face-default-form'
3164 :custom-set
'custom-face-set
3165 :custom-save
'custom-face-save
3166 :custom-reset-current
'custom-redraw
3167 :custom-reset-saved
'custom-face-reset-saved
3168 :custom-reset-standard
'custom-face-reset-standard
3169 :custom-standard-value
'custom-face-standard-value
3170 :custom-menu
'custom-face-menu-create
)
3172 (define-widget 'custom-face-all
'editable-list
3173 "An editable list of display specifications and attributes."
3174 :entry-format
"%i %d %v"
3175 :insert-button-args
'(:help-echo
"Insert new display specification here.")
3176 :append-button-args
'(:help-echo
"Append new display specification here.")
3177 :delete-button-args
'(:help-echo
"Delete this display specification.")
3178 :args
'((group :format
"%v" custom-display custom-face-edit
)))
3180 (defconst custom-face-all
(widget-convert 'custom-face-all
)
3181 "Converted version of the `custom-face-all' widget.")
3183 (define-widget 'custom-display-unselected
'item
3184 "A display specification that doesn't match the selected display."
3185 :match
'custom-display-unselected-match
)
3187 (defun custom-display-unselected-match (widget value
)
3188 "Non-nil if VALUE is an unselected display specification."
3189 (not (face-spec-set-match-display value
(selected-frame))))
3191 (define-widget 'custom-face-selected
'group
3192 "Edit the attributes of the selected display in a face specification."
3193 :args
'((choice :inline t
3194 (group :tag
"With Defaults" :inline t
3195 (group (const :tag
"" default
)
3196 (custom-face-edit :tag
" Default\n Attributes"))
3199 (group custom-display-unselected sexp
))
3200 (group (sexp :format
"")
3201 (custom-face-edit :tag
" Overriding\n Attributes"))
3205 (group :tag
"No Defaults" :inline t
3208 (group custom-display-unselected sexp
))
3209 (group (sexp :format
"")
3210 (custom-face-edit :tag
"\n Attributes"))
3217 (defconst custom-face-selected
(widget-convert 'custom-face-selected
)
3218 "Converted version of the `custom-face-selected' widget.")
3220 (defun custom-filter-face-spec (spec filter-index
&optional default-filter
)
3221 "Return a canonicalized version of SPEC using.
3222 FILTER-INDEX is the index in the entry for each attribute in
3223 `custom-face-attributes' at which the appropriate filter function can be
3224 found, and DEFAULT-FILTER is the filter to apply for attributes that
3226 (mapcar (lambda (entry)
3227 ;; Filter a single face-spec entry
3228 (let ((tests (car entry
))
3230 ;; Handle both old- and new-style attribute syntax
3231 (if (listp (car (cdr entry
)))
3234 (filtered-attrs nil
))
3235 ;; Filter each face attribute
3236 (while unfiltered-attrs
3237 (let* ((attr (pop unfiltered-attrs
))
3238 (pre-filtered-value (pop unfiltered-attrs
))
3240 (or (nth filter-index
(assq attr custom-face-attributes
))
3244 (funcall filter pre-filtered-value
)
3245 pre-filtered-value
)))
3246 (push filtered-value filtered-attrs
)
3247 (push attr filtered-attrs
)))
3249 (list tests filtered-attrs
)))
3252 (defun custom-pre-filter-face-spec (spec)
3253 "Return SPEC changed as necessary for editing by the face customization widget.
3254 SPEC must be a full face spec."
3255 (custom-filter-face-spec spec
2))
3257 (defun custom-post-filter-face-spec (spec)
3258 "Return the customized SPEC in a form suitable for setting the face."
3259 (custom-filter-face-spec spec
3))
3261 (defun custom-face-value-create (widget)
3262 "Create a list of the display specifications for WIDGET."
3263 (let ((buttons (widget-get widget
:buttons
))
3265 (symbol (widget-get widget
:value
))
3266 (tag (widget-get widget
:tag
))
3267 (state (widget-get widget
:custom-state
))
3269 (is-last (widget-get widget
:custom-last
))
3270 (prefix (widget-get widget
:custom-prefix
)))
3272 (setq tag
(prin1-to-string symbol
)))
3273 (cond ((eq custom-buffer-style
'tree
)
3274 (insert prefix
(if is-last
" `--- " " |--- "))
3275 (push (widget-create-child-and-convert
3276 widget
'custom-browse-face-tag
)
3278 (insert " " tag
"\n")
3279 (widget-put widget
:buttons buttons
))
3283 (widget-specify-sample widget begin
(point))
3284 (if (eq custom-buffer-style
'face
)
3286 (if (string-match "face\\'" tag
)
3288 (insert " face: ")))
3290 (push (widget-create-child-and-convert widget
'item
3297 (push (widget-create-child-and-convert
3299 :help-echo
"Hide or show this face."
3302 :action
'custom-toggle-parent
3303 (not (eq state
'hidden
)))
3307 (let ((magic (widget-create-child-and-convert
3308 widget
'custom-magic nil
)))
3309 (widget-put widget
:custom-magic magic
)
3310 (push magic buttons
))
3312 (widget-put widget
:buttons buttons
)
3313 ;; Insert documentation.
3314 (widget-add-documentation-string-button
3315 widget
:visibility-widget
'custom-visibility
)
3317 ;; The comment field
3318 (unless (eq state
'hidden
)
3319 (let* ((comment (get symbol
'face-comment
))
3321 (widget-create-child-and-convert
3322 widget
'custom-comment
3324 :value
(or comment
""))))
3325 (widget-put widget
:comment-widget comment-widget
)
3326 (push comment-widget children
)))
3328 (unless (eq state
'hidden
)
3329 (when (eq (widget-get widget
:custom-level
) 1)
3330 (custom-add-parent-links widget
))
3331 (custom-add-see-also widget
))
3333 (unless (eq (preceding-char) ?
\n)
3335 (unless (eq state
'hidden
)
3336 (message "Creating face editor...")
3337 (custom-load-widget widget
)
3338 (unless (widget-get widget
:custom-form
)
3339 (widget-put widget
:custom-form custom-face-default-form
))
3340 (let* ((symbol (widget-value widget
))
3341 (spec (or (get symbol
'customized-face
)
3342 (get symbol
'saved-face
)
3343 (get symbol
'face-defface-spec
)
3344 ;; Attempt to construct it.
3345 (list (list t
(custom-face-attributes-get
3346 symbol
(selected-frame))))))
3347 (form (widget-get widget
:custom-form
))
3348 (indent (widget-get widget
:indent
))
3350 ;; If the user has changed this face in some other way,
3351 ;; edit it as the user has specified it.
3352 (if (not (face-spec-match-p symbol spec
(selected-frame)))
3353 (setq spec
(list (list t
(face-attr-construct symbol
(selected-frame))))))
3354 (setq spec
(custom-pre-filter-face-spec spec
))
3355 (setq edit
(widget-create-child-and-convert
3357 (cond ((and (eq form
'selected
)
3358 (widget-apply custom-face-selected
3360 (when indent
(insert-char ?\ indent
))
3361 'custom-face-selected
)
3362 ((and (not (eq form
'lisp
))
3363 (widget-apply custom-face-all
3367 (when indent
(insert-char ?\ indent
))
3370 (custom-face-state-set widget
)
3371 (push edit children
)
3372 (widget-put widget
:children children
))
3373 (message "Creating face editor...done"))))))
3375 (defvar custom-face-menu
3376 `(("Set for Current Session" custom-face-set
)
3377 ,@(when (or custom-file user-init-file
)
3378 '(("Save for Future Sessions" custom-face-save
)))
3379 ("Undo Edits" custom-redraw
3381 (memq (widget-get widget
:custom-state
) '(modified changed
))))
3382 ("Reset to Saved" custom-face-reset-saved
3384 (or (get (widget-value widget
) 'saved-face
)
3385 (get (widget-value widget
) 'saved-face-comment
))))
3386 ,@(when (or custom-file user-init-file
)
3387 '(("Erase Customization" custom-face-reset-standard
3389 (get (widget-value widget
) 'face-defface-spec
)))))
3390 ("---" ignore ignore
)
3391 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
3392 ("---" ignore ignore
)
3393 ("For Current Display" custom-face-edit-selected
3395 (not (eq (widget-get widget
:custom-form
) 'selected
))))
3396 ("For All Kinds of Displays" custom-face-edit-all
3398 (not (eq (widget-get widget
:custom-form
) 'all
))))
3399 ("Show Lisp Expression" custom-face-edit-lisp
3401 (not (eq (widget-get widget
:custom-form
) 'lisp
)))))
3402 "Alist of actions for the `custom-face' widget.
3403 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3404 the menu entry, ACTION is the function to call on the widget when the
3405 menu is selected, and FILTER is a predicate which takes a `custom-face'
3406 widget as an argument, and returns non-nil if ACTION is valid on that
3407 widget. If FILTER is nil, ACTION is always valid.")
3409 (defun custom-face-edit-selected (widget)
3410 "Edit selected attributes of the value of WIDGET."
3411 (widget-put widget
:custom-state
'unknown
)
3412 (widget-put widget
:custom-form
'selected
)
3413 (custom-redraw widget
))
3415 (defun custom-face-edit-all (widget)
3416 "Edit all attributes of the value of WIDGET."
3417 (widget-put widget
:custom-state
'unknown
)
3418 (widget-put widget
:custom-form
'all
)
3419 (custom-redraw widget
))
3421 (defun custom-face-edit-lisp (widget)
3422 "Edit the Lisp representation of the value of WIDGET."
3423 (widget-put widget
:custom-state
'unknown
)
3424 (widget-put widget
:custom-form
'lisp
)
3425 (custom-redraw widget
))
3427 (defun custom-face-state-set (widget)
3428 "Set the state of WIDGET."
3429 (let* ((symbol (widget-value widget
))
3430 (comment (get symbol
'face-comment
))
3434 (setq tmp
(get symbol
'customized-face
))
3435 (setq temp
(get symbol
'customized-face-comment
))
3437 (if (equal temp comment
)
3441 (setq tmp
(get symbol
'saved-face
))
3442 (setq temp
(get symbol
'saved-face-comment
))
3444 (if (equal temp comment
)
3446 ((eq 'user
(caar (get symbol
'theme-face
)))
3448 ((eq 'changed
(caar (get symbol
'theme-face
)))
3452 ((get symbol
'face-defface-spec
)
3453 (if (equal comment nil
)
3458 ;; If the user called set-face-attribute to change the default
3459 ;; for new frames, this face is "set outside of Customize".
3460 (if (and (not (eq state
'rogue
))
3461 (get symbol
'face-modified
))
3462 (setq state
'changed
))
3463 (widget-put widget
:custom-state state
)))
3465 (defun custom-face-action (widget &optional event
)
3466 "Show the menu for `custom-face' WIDGET.
3467 Optional EVENT is the location for the menu."
3468 (if (eq (widget-get widget
:custom-state
) 'hidden
)
3469 (custom-toggle-hide widget
)
3470 (let* ((completion-ignore-case t
)
3471 (symbol (widget-get widget
:value
))
3472 (answer (widget-choose (concat "Operation on "
3473 (custom-unlispify-tag-name symbol
))
3474 (custom-menu-filter custom-face-menu
3478 (funcall answer widget
)))))
3480 (defun custom-face-set (widget)
3481 "Make the face attributes in WIDGET take effect."
3482 (let* ((symbol (widget-value widget
))
3483 (child (car (widget-get widget
:children
)))
3484 (value (custom-post-filter-face-spec (widget-value child
)))
3485 (comment-widget (widget-get widget
:comment-widget
))
3486 (comment (widget-value comment-widget
)))
3487 (when (equal comment
"")
3489 ;; Make the comment invisible by hand if it's empty
3490 (custom-comment-hide comment-widget
))
3491 (put symbol
'customized-face value
)
3492 (custom-push-theme 'theme-face symbol
'user
'set value
)
3493 (if (face-spec-choose value
)
3494 (face-spec-set symbol value
)
3495 ;; face-set-spec ignores empty attribute lists, so just give it
3496 ;; something harmless instead.
3497 (face-spec-set symbol
'((t :foreground unspecified
))))
3498 (put symbol
'customized-face-comment comment
)
3499 (put symbol
'face-comment comment
)
3500 (custom-face-state-set widget
)
3501 (custom-redraw-magic widget
)))
3503 (defun custom-face-save (widget)
3504 "Save in `.emacs' the face attributes in WIDGET."
3505 (let* ((symbol (widget-value widget
))
3506 (child (car (widget-get widget
:children
)))
3507 (value (custom-post-filter-face-spec (widget-value child
)))
3508 (comment-widget (widget-get widget
:comment-widget
))
3509 (comment (widget-value comment-widget
)))
3510 (when (equal comment
"")
3512 ;; Make the comment invisible by hand if it's empty
3513 (custom-comment-hide comment-widget
))
3514 (custom-push-theme 'theme-face symbol
'user
'set value
)
3515 (if (face-spec-choose value
)
3516 (face-spec-set symbol value
)
3517 ;; face-set-spec ignores empty attribute lists, so just give it
3518 ;; something harmless instead.
3519 (face-spec-set symbol
'((t :foreground unspecified
))))
3520 (unless (eq (widget-get widget
:custom-state
) 'standard
)
3521 (put symbol
'saved-face value
))
3522 (put symbol
'customized-face nil
)
3523 (put symbol
'face-comment comment
)
3524 (put symbol
'customized-face-comment nil
)
3525 (put symbol
'saved-face-comment comment
)
3527 (custom-face-state-set widget
)
3528 (custom-redraw-magic widget
)))
3530 ;; For backward compatibility.
3531 (define-obsolete-function-alias 'custom-face-save-command
'custom-face-save
3534 (defun custom-face-reset-saved (widget)
3535 "Restore WIDGET to the face's default attributes."
3536 (let* ((symbol (widget-value widget
))
3537 (child (car (widget-get widget
:children
)))
3538 (value (get symbol
'saved-face
))
3539 (comment (get symbol
'saved-face-comment
))
3540 (comment-widget (widget-get widget
:comment-widget
)))
3541 (unless (or value comment
)
3542 (error "No saved value for this face"))
3543 (put symbol
'customized-face nil
)
3544 (put symbol
'customized-face-comment nil
)
3545 (custom-push-theme 'theme-face symbol
'user
'set value
)
3546 (face-spec-set symbol value
)
3547 (put symbol
'face-comment comment
)
3548 (widget-value-set child value
)
3549 ;; This call manages the comment visibility
3550 (widget-value-set comment-widget
(or comment
""))
3551 (custom-face-state-set widget
)
3552 (custom-redraw-magic widget
)))
3554 (defun custom-face-standard-value (widget)
3555 (get (widget-value widget
) 'face-defface-spec
))
3557 (defun custom-face-reset-standard (widget)
3558 "Restore WIDGET to the face's standard attribute values.
3559 This operation eliminates any saved attributes for the face,
3560 restoring it to the state of a face that has never been customized."
3561 (let* ((symbol (widget-value widget
))
3562 (child (car (widget-get widget
:children
)))
3563 (value (get symbol
'face-defface-spec
))
3564 (comment-widget (widget-get widget
:comment-widget
)))
3566 (error "No standard setting for this face"))
3567 (put symbol
'customized-face nil
)
3568 (put symbol
'customized-face-comment nil
)
3569 (custom-push-theme 'theme-face symbol
'user
'reset
)
3570 (face-spec-set symbol value
)
3571 (custom-theme-recalc-face symbol
)
3572 (when (or (get symbol
'saved-face
) (get symbol
'saved-face-comment
))
3573 (put symbol
'saved-face nil
)
3574 (put symbol
'saved-face-comment nil
)
3576 (put symbol
'face-comment nil
)
3577 (widget-value-set child
3578 (custom-pre-filter-face-spec
3579 (list (list t
(custom-face-attributes-get
3581 ;; This call manages the comment visibility
3582 (widget-value-set comment-widget
"")
3583 (custom-face-state-set widget
)
3584 (custom-redraw-magic widget
)))
3586 ;;; The `face' Widget.
3588 (defvar widget-face-prompt-value-history nil
3589 "History of input to `widget-face-prompt-value'.")
3591 (define-widget 'face
'symbol
3592 "A Lisp face name (with sample)."
3593 :format
"%{%t%}: (%{sample%}) %v"
3596 :sample-face-get
'widget-face-sample-face-get
3597 :notify
'widget-face-notify
3598 :match
(lambda (widget value
) (facep value
))
3599 :complete-function
(lambda ()
3601 (lisp-complete-symbol 'facep
))
3602 :prompt-match
'facep
3603 :prompt-history
'widget-face-prompt-value-history
3604 :validate
(lambda (widget)
3605 (unless (facep (widget-value widget
))
3607 :error
(format "Invalid face: %S"
3608 (widget-value widget
)))
3611 (defun widget-face-sample-face-get (widget)
3612 (let ((value (widget-value widget
)))
3617 (defun widget-face-notify (widget child
&optional event
)
3618 "Update the sample, and notify the parent."
3619 (overlay-put (widget-get widget
:sample-overlay
)
3620 'face
(widget-apply widget
:sample-face-get
))
3621 (widget-default-notify widget child event
))
3624 ;;; The `hook' Widget.
3626 (define-widget 'hook
'list
3627 "An Emacs Lisp hook."
3628 :value-to-internal
(lambda (widget value
)
3629 (if (and value
(symbolp value
))
3632 :match
(lambda (widget value
)
3634 (widget-group-match widget value
)))
3635 ;; Avoid adding undefined functions to the hook, especially for
3636 ;; things like `find-file-hook' or even more basic ones, to avoid
3638 :set
(lambda (symbol value
)
3641 (add-hook symbol elt
))))
3642 :convert-widget
'custom-hook-convert-widget
3645 (defun custom-hook-convert-widget (widget)
3646 ;; Handle `:options'.
3647 (let* ((options (widget-get widget
:options
))
3648 (other `(editable-list :inline t
3649 :entry-format
"%i %d%v"
3650 (function :format
" %v")))
3652 (list `(checklist :inline t
3653 ,@(mapcar (lambda (entry)
3654 `(function-item ,entry
))
3658 (widget-put widget
:args args
)
3661 ;;; The `custom-group-link' Widget.
3663 (define-widget 'custom-group-link
'link
3664 "Show parent in other window when activated."
3665 :button-face
'custom-link
3666 :mouse-face
'highlight
3667 :pressed-face
'highlight
3668 :help-echo
"Create customization buffer for this group."
3669 :keymap custom-mode-link-map
3670 :follow-link
'mouse-face
3671 :action
'custom-group-link-action
)
3673 (defun custom-group-link-action (widget &rest ignore
)
3674 (customize-group (widget-value widget
)))
3676 ;;; The `custom-group' Widget.
3678 (defcustom custom-group-tag-faces nil
3679 ;; In XEmacs, this ought to play games with font size.
3680 ;; Fixme: make it do so in Emacs.
3681 "Face used for group tags.
3682 The first member is used for level 1 groups, the second for level 2,
3683 and so forth. The remaining group tags are shown with `custom-group-tag'."
3684 :type
'(repeat face
)
3685 :group
'custom-faces
)
3687 (defface custom-group-tag-1
3690 (:foreground
"pink" :weight bold
:height
1.2 :inherit variable-pitch
))
3691 (((min-colors 88) (class color
)
3693 (:foreground
"red1" :weight bold
:height
1.2 :inherit variable-pitch
))
3696 (:foreground
"red" :weight bold
:height
1.2 :inherit variable-pitch
))
3698 "Face used for group tags."
3699 :group
'custom-faces
)
3700 ;; backward-compatibility alias
3701 (put 'custom-group-tag-face-1
'face-alias
'custom-group-tag-1
)
3703 (defface custom-group-tag
3706 (:foreground
"light blue" :weight bold
:height
1.2 :inherit variable-pitch
))
3707 (((min-colors 88) (class color
)
3709 (:foreground
"blue1" :weight bold
:height
1.2 :inherit variable-pitch
))
3712 (:foreground
"blue" :weight bold
:height
1.2 :inherit variable-pitch
))
3714 "Face used for low level group tags."
3715 :group
'custom-faces
)
3716 ;; backward-compatibility alias
3717 (put 'custom-group-tag-face
'face-alias
'custom-group-tag
)
3719 (define-widget 'custom-group
'custom
3722 :sample-face-get
'custom-group-sample-face-get
3723 :documentation-property
'group-documentation
3724 :help-echo
"Set or reset all members of this group."
3725 :value-create
'custom-group-value-create
3726 :action
'custom-group-action
3727 :custom-category
'group
3728 :custom-set
'custom-group-set
3729 :custom-save
'custom-group-save
3730 :custom-reset-current
'custom-group-reset-current
3731 :custom-reset-saved
'custom-group-reset-saved
3732 :custom-reset-standard
'custom-group-reset-standard
3733 :custom-menu
'custom-group-menu-create
)
3735 (defun custom-group-sample-face-get (widget)
3736 ;; Use :sample-face.
3737 (or (nth (1- (widget-get widget
:custom-level
)) custom-group-tag-faces
)
3740 (define-widget 'custom-group-visibility
'visibility
3741 "An indicator and manipulator for hidden group contents."
3742 :create
'custom-group-visibility-create
)
3744 (defun custom-group-visibility-create (widget)
3745 (let ((visible (widget-value widget
)))
3747 (insert "--------")))
3748 (widget-default-create widget
))
3750 (defun custom-group-members (symbol groups-only
)
3751 "Return SYMBOL's custom group members.
3752 If GROUPS-ONLY non-nil, return only those members that are groups."
3753 (if (not groups-only
)
3754 (get symbol
'custom-group
)
3756 (dolist (entry (get symbol
'custom-group
))
3757 (when (eq (nth 1 entry
) 'custom-group
)
3758 (push entry members
)))
3759 (nreverse members
))))
3761 (defun custom-group-value-create (widget)
3762 "Insert a customize group for WIDGET in the current buffer."
3763 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
3764 (custom-load-widget widget
))
3765 (let* ((state (widget-get widget
:custom-state
))
3766 (level (widget-get widget
:custom-level
))
3767 ;; (indent (widget-get widget :indent))
3768 (prefix (widget-get widget
:custom-prefix
))
3769 (buttons (widget-get widget
:buttons
))
3770 (tag (widget-get widget
:tag
))
3771 (symbol (widget-value widget
))
3772 (members (custom-group-members symbol
3773 (and (eq custom-buffer-style
'tree
)
3774 custom-browse-only-groups
))))
3775 (cond ((and (eq custom-buffer-style
'tree
)
3777 (or members
(custom-unloaded-widget-p widget
)))
3778 (custom-browse-insert-prefix prefix
)
3779 (push (widget-create-child-and-convert
3780 widget
'custom-browse-visibility
3781 ;; :tag-glyph "plus"
3785 ;; (widget-glyph-insert nil "-- " "horizontal")
3786 (push (widget-create-child-and-convert
3787 widget
'custom-browse-group-tag
)
3789 (insert " " tag
"\n")
3790 (widget-put widget
:buttons buttons
))
3791 ((and (eq custom-buffer-style
'tree
)
3792 (zerop (length members
)))
3793 (custom-browse-insert-prefix prefix
)
3795 ;; (widget-glyph-insert nil "[ ]" "empty")
3796 ;; (widget-glyph-insert nil "-- " "horizontal")
3797 (push (widget-create-child-and-convert
3798 widget
'custom-browse-group-tag
)
3800 (insert " " tag
"\n")
3801 (widget-put widget
:buttons buttons
))
3802 ((eq custom-buffer-style
'tree
)
3803 (custom-browse-insert-prefix prefix
)
3804 (if (zerop (length members
))
3806 (custom-browse-insert-prefix prefix
)
3808 ;; (widget-glyph-insert nil "[ ]" "empty")
3809 ;; (widget-glyph-insert nil "-- " "horizontal")
3810 (push (widget-create-child-and-convert
3811 widget
'custom-browse-group-tag
)
3813 (insert " " tag
"\n")
3814 (widget-put widget
:buttons buttons
))
3815 (push (widget-create-child-and-convert
3816 widget
'custom-browse-visibility
3817 ;; :tag-glyph "minus"
3821 ;; (widget-glyph-insert nil "-\\ " "top")
3822 (push (widget-create-child-and-convert
3823 widget
'custom-browse-group-tag
)
3825 (insert " " tag
"\n")
3826 (widget-put widget
:buttons buttons
)
3827 (message "Creating group...")
3828 (let* ((members (custom-sort-items members
3829 custom-browse-sort-alphabetically
3830 custom-browse-order-groups
))
3831 (prefixes (widget-get widget
:custom-prefixes
))
3832 (custom-prefix-list (custom-prefix-add symbol prefixes
))
3833 (extra-prefix (if (widget-get widget
:custom-last
)
3836 (prefix (concat prefix extra-prefix
))
3839 (setq entry
(car members
)
3840 members
(cdr members
))
3841 (push (widget-create-child-and-convert
3842 widget
(nth 1 entry
)
3844 :tag
(custom-unlispify-tag-name (nth 0 entry
))
3845 :custom-prefixes custom-prefix-list
3846 :custom-level
(1+ level
)
3847 :custom-last
(null members
)
3848 :value
(nth 0 entry
)
3849 :custom-prefix prefix
)
3851 (widget-put widget
:children
(reverse children
)))
3852 (message "Creating group...done")))
3855 ;; Create level indicator.
3857 (if (eq custom-buffer-style
'links
)
3858 (push (widget-create-child-and-convert
3859 widget
'custom-group-link
3863 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3865 (push (widget-create-child-and-convert
3866 widget
'custom-group-visibility
3867 :help-echo
"Show members of this group."
3868 :action
'custom-toggle-parent
3869 (not (eq state
'hidden
)))
3872 ;; Create magic button.
3873 (let ((magic (widget-create-child-and-convert
3874 widget
'custom-magic nil
)))
3875 (widget-put widget
:custom-magic magic
)
3876 (push magic buttons
))
3878 (widget-put widget
:buttons buttons
)
3879 ;; Insert documentation.
3880 (if (and (eq custom-buffer-style
'links
) (> level
1))
3881 (widget-put widget
:documentation-indent
0))
3882 (widget-add-documentation-string-button
3883 widget
:visibility-widget
'custom-visibility
))
3887 ;; Add parent groups references above the group.
3888 (if t
;;; This should test that the buffer
3889 ;;; was made to display a group.
3891 (if (custom-add-parent-links widget
3894 ;; Create level indicator.
3895 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3898 (let ((start (point)))
3899 (insert tag
" group: ")
3900 (widget-specify-sample widget start
(point)))
3901 (insert (widget-docstring widget
))
3902 ;; Create visibility indicator.
3903 (unless (eq custom-buffer-style
'links
)
3905 (push (widget-create-child-and-convert
3907 :help-echo
"Hide members of this group."
3908 :action
'custom-toggle-parent
3909 (not (eq state
'hidden
)))
3912 ;; Create more dashes.
3913 ;; Use 76 instead of 75 to compensate for the temporary "<"
3914 ;; added by `widget-insert'.
3915 (insert-char ?-
(- 76 (current-column)
3916 (* custom-buffer-indent level
)))
3918 ;; Create magic button.
3919 (let ((magic (widget-create-child-and-convert
3920 widget
'custom-magic
3923 (widget-put widget
:custom-magic magic
)
3924 (push magic buttons
))
3926 (widget-put widget
:buttons buttons
)
3927 ;; Insert documentation.
3928 (widget-add-documentation-string-button
3929 widget
:visibility-widget
'custom-visibility
)
3932 (if nil
;;; This should test that the buffer
3933 ;;; was not made to display a group.
3935 (insert-char ?\ custom-buffer-indent
)
3936 (custom-add-parent-links widget
)))
3937 (custom-add-see-also widget
3938 (make-string (* custom-buffer-indent level
)
3941 (message "Creating group...")
3942 (let* ((members (custom-sort-items members
3943 custom-buffer-sort-alphabetically
3944 custom-buffer-order-groups
))
3945 (prefixes (widget-get widget
:custom-prefixes
))
3946 (custom-prefix-list (custom-prefix-add symbol prefixes
))
3947 (length (length members
))
3949 (children (mapcar (lambda (entry)
3950 (widget-insert "\n")
3952 Creating group members... %2d%%"
3953 (/ (* 100.0 count
) length
))
3954 (setq count
(1+ count
))
3956 (widget-create-child-and-convert
3957 widget
(nth 1 entry
)
3959 :tag
(custom-unlispify-tag-name
3961 :custom-prefixes custom-prefix-list
3962 :custom-level
(1+ level
)
3963 :value
(nth 0 entry
))
3964 (unless (eq (preceding-char) ?
\n)
3965 (widget-insert "\n"))))
3967 (message "Creating group magic...")
3968 (mapc 'custom-magic-reset children
)
3969 (message "Creating group state...")
3970 (widget-put widget
:children children
)
3971 (custom-group-state-update widget
)
3972 (message "Creating group... done"))
3975 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3976 (insert "\\- " (widget-get widget
:tag
) " group end ")
3977 (insert-char ?-
(- 75 (current-column) (* custom-buffer-indent level
)))
3980 (defvar custom-group-menu
3981 `(("Set for Current Session" custom-group-set
3983 (eq (widget-get widget
:custom-state
) 'modified
)))
3984 ,@(when (or custom-file user-init-file
)
3985 '(("Save for Future Sessions" custom-group-save
3987 (memq (widget-get widget
:custom-state
) '(modified set
))))))
3988 ("Undo Edits" custom-group-reset-current
3990 (memq (widget-get widget
:custom-state
) '(modified))))
3991 ("Reset to Saved" custom-group-reset-saved
3993 (memq (widget-get widget
:custom-state
) '(modified set
))))
3994 ,@(when (or custom-file user-init-file
)
3995 '(("Erase Customization" custom-group-reset-standard
3997 (memq (widget-get widget
:custom-state
) '(modified set saved
)))))))
3998 "Alist of actions for the `custom-group' widget.
3999 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
4000 the menu entry, ACTION is the function to call on the widget when the
4001 menu is selected, and FILTER is a predicate which takes a `custom-group'
4002 widget as an argument, and returns non-nil if ACTION is valid on that
4003 widget. If FILTER is nil, ACTION is always valid.")
4005 (defun custom-group-action (widget &optional event
)
4006 "Show the menu for `custom-group' WIDGET.
4007 Optional EVENT is the location for the menu."
4008 (if (eq (widget-get widget
:custom-state
) 'hidden
)
4009 (custom-toggle-hide widget
)
4010 (let* ((completion-ignore-case t
)
4011 (answer (widget-choose (concat "Operation on "
4012 (custom-unlispify-tag-name
4013 (widget-get widget
:value
)))
4014 (custom-menu-filter custom-group-menu
4018 (funcall answer widget
)))))
4020 (defun custom-group-set (widget)
4021 "Set changes in all modified group members."
4022 (dolist (child (widget-get widget
:children
))
4023 (when (eq (widget-get child
:custom-state
) 'modified
)
4024 (widget-apply child
:custom-set
))))
4026 (defun custom-group-save (widget)
4027 "Save all modified group members."
4028 (dolist (child (children (widget-get widget
:children
)))
4029 (when (memq (widget-get child
:custom-state
) '(modified set
))
4030 (widget-apply child
:custom-save
))))
4032 (defun custom-group-reset-current (widget)
4033 "Reset all modified group members."
4034 (dolist (child (widget-get widget
:children
))
4035 (when (eq (widget-get child
:custom-state
) 'modified
)
4036 (widget-apply child
:custom-reset-current
))))
4038 (defun custom-group-reset-saved (widget)
4039 "Reset all modified or set group members."
4040 (dolist (child (widget-get widget
:children
))
4041 (when (memq (widget-get child
:custom-state
) '(modified set
))
4042 (widget-apply child
:custom-reset-saved
))))
4044 (defun custom-group-reset-standard (widget)
4045 "Reset all modified, set, or saved group members."
4046 (dolist (child (widget-get widget
:children
))
4047 (when (memq (widget-get child
:custom-state
)
4048 '(modified set saved
))
4049 (widget-apply child
:custom-reset-standard
))))
4051 (defun custom-group-state-update (widget)
4053 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
4054 (let* ((children (widget-get widget
:children
))
4055 (states (mapcar (lambda (child)
4056 (widget-get child
:custom-state
))
4058 (magics custom-magic-alist
)
4061 (let ((magic (car (car magics
))))
4062 (if (and (not (eq magic
'hidden
))
4063 (memq magic states
))
4066 (setq magics
(cdr magics
)))))
4067 (widget-put widget
:custom-state found
)))
4068 (custom-magic-reset widget
))
4070 ;;; Reading and writing the custom file.
4073 (defcustom custom-file nil
4074 "File used for storing customization information.
4075 The default is nil, which means to use your init file
4076 as specified by `user-init-file'. If the value is not nil,
4077 it should be an absolute file name.
4079 You can set this option through Custom, if you carefully read the
4080 last paragraph below. However, usually it is simpler to write
4081 something like the following in your init file:
4083 \(setq custom-file \"~/.emacs-custom.el\")
4086 Note that both lines are necessary: the first line tells Custom to
4087 save all customizations in this file, but does not load it.
4089 When you change this variable outside Custom, look in the
4090 previous custom file \(usually your init file) for the
4091 forms `(custom-set-variables ...)' and `(custom-set-faces ...)',
4092 and copy them (whichever ones you find) to the new custom file.
4093 This will preserve your existing customizations.
4095 If you save this option using Custom, Custom will write all
4096 currently saved customizations, including the new one for this
4097 option itself, into the file you specify, overwriting any
4098 `custom-set-variables' and `custom-set-faces' forms already
4099 present in that file. It will not delete any customizations from
4100 the old custom file. You should do that manually if that is what you
4101 want. You also have to put something like `\(load \"CUSTOM-FILE\")
4102 in your init file, where CUSTOM-FILE is the actual name of the
4103 file. Otherwise, Emacs will not load the file when it starts up,
4104 and hence will not set `custom-file' to that file either."
4105 :type
'(choice (const :tag
"Your Emacs init file" nil
)
4106 (file :format
"%t:%v%d"
4108 "Please read entire docstring below before setting \
4109 this through Custom.
4110 Click om \"More\" \(or position point there and press RETURN)
4111 if only the first line of the docstring is shown."))
4114 (defun custom-file ()
4115 "Return the file name for saving customizations."
4118 (let ((user-init-file user-init-file
)
4120 (if (eq system-type
'ms-dos
) "~/_emacs" "~/.emacs")))
4121 (when (null user-init-file
)
4122 (if (or (file-exists-p default-init-file
)
4123 (and (eq system-type
'windows-nt
)
4124 (file-exists-p "~/_emacs")))
4125 ;; Started with -q, i.e. the file containing
4126 ;; Custom settings hasn't been read. Saving
4127 ;; settings there would overwrite other settings.
4128 (error "Saving settings from \"emacs -q\" would overwrite existing customizations"))
4129 (setq user-init-file default-init-file
))
4133 (defun custom-save-all ()
4134 "Save all customizations in `custom-file'."
4135 (when (and (null custom-file
) init-file-had-error
)
4136 (error "Cannot save customizations; init file was not fully loaded"))
4137 (let* ((filename (custom-file))
4142 (recentf-expand-file-name (custom-file)))
4145 (old-buffer (find-buffer-visiting filename
)))
4146 (with-current-buffer (let ((find-file-visit-truename t
))
4147 (or old-buffer
(find-file-noselect filename
)))
4148 (unless (eq major-mode
'emacs-lisp-mode
)
4150 (let ((inhibit-read-only t
))
4151 (custom-save-variables)
4152 (custom-save-faces))
4153 (let ((file-precious-flag t
))
4156 (kill-buffer (current-buffer))))))
4159 (defun customize-save-customized ()
4160 "Save all user options which have been set in this session."
4162 (mapatoms (lambda (symbol)
4163 (let ((face (get symbol
'customized-face
))
4164 (value (get symbol
'customized-value
))
4165 (face-comment (get symbol
'customized-face-comment
))
4167 (get symbol
'customized-variable-comment
)))
4169 (put symbol
'saved-face face
)
4170 (custom-push-theme 'theme-face symbol
'user
'set value
)
4171 (put symbol
'customized-face nil
))
4173 (put symbol
'saved-value value
)
4174 (custom-push-theme 'theme-value symbol
'user
'set value
)
4175 (put symbol
'customized-value nil
))
4176 (when variable-comment
4177 (put symbol
'saved-variable-comment variable-comment
)
4178 (put symbol
'customized-variable-comment nil
))
4180 (put symbol
'saved-face-comment face-comment
)
4181 (put symbol
'customized-face-comment nil
)))))
4182 ;; We really should update all custom buffers here.
4185 ;; Editing the custom file contents in a buffer.
4187 (defun custom-save-delete (symbol)
4188 "Delete all calls to SYMBOL from the contents of the current buffer.
4189 Leave point at the old location of the first such call,
4190 or (if there were none) at the end of the buffer.
4192 This function does not save the buffer."
4193 (goto-char (point-min))
4194 ;; Skip all whitespace and comments.
4195 (while (forward-comment 1))
4197 (save-excursion (forward-sexp (buffer-size)))) ; Test for scan errors.
4200 (while t
;; We exit this loop only via throw.
4201 ;; Skip all whitespace and comments.
4202 (while (forward-comment 1))
4203 (let ((start (point))
4204 (sexp (condition-case nil
4205 (read (current-buffer))
4206 (end-of-file (throw 'found nil
)))))
4207 (when (and (listp sexp
)
4208 (eq (car sexp
) symbol
))
4209 (delete-region start
(point))
4211 (setq first
(point)))))))
4214 ;; Move in front of local variables, otherwise long Custom
4215 ;; entries would make them ineffective.
4216 (let ((pos (point-max))
4217 (case-fold-search t
))
4219 (goto-char (point-max))
4220 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
4222 (when (search-forward "Local Variables:" nil t
)
4223 (setq pos
(line-beginning-position))))
4226 (defun custom-save-variables ()
4227 "Save all customized variables in `custom-file'."
4229 (custom-save-delete 'custom-set-variables
)
4230 (let ((standard-output (current-buffer))
4231 (saved-list (make-list 1 0))
4233 ;; First create a sorted list of saved variables.
4236 (if (and (get symbol
'saved-value
)
4237 ;; ignore theme values
4238 (or (null (get symbol
'theme-value
))
4239 (eq 'user
(caar (get symbol
'theme-value
)))))
4240 (nconc saved-list
(list symbol
)))))
4241 (setq saved-list
(sort (cdr saved-list
) 'string
<))
4244 (princ "(custom-set-variables
4245 ;; custom-set-variables was added by Custom.
4246 ;; If you edit it by hand, you could mess it up, so be careful.
4247 ;; Your init file should contain only one such instance.
4248 ;; If there is more than one, they won't work right.\n")
4249 (dolist (symbol saved-list
)
4250 (let ((spec (car-safe (get symbol
'theme-value
)))
4251 (value (get symbol
'saved-value
))
4252 (requests (get symbol
'custom-requests
))
4253 (now (and (not (custom-variable-p symbol
))
4255 (eq (get symbol
'force-value
)
4257 (comment (get symbol
'saved-variable-comment
)))
4258 ;; Check REQUESTS for validity.
4259 (dolist (request requests
)
4260 (when (and (symbolp request
) (not (featurep request
)))
4261 (message "Unknown requested feature: %s" request
)
4262 (setq requests
(delq request requests
))))
4263 ;; Is there anything customized about this variable?
4264 (when (or (and spec
(eq (car spec
) 'user
))
4266 (and (null spec
) (get symbol
'saved-value
)))
4267 ;; Output an element for this variable.
4268 ;; It has the form (SYMBOL VALUE-FORM NOW REQUESTS COMMENT).
4269 ;; SYMBOL is the variable name.
4270 ;; VALUE-FORM is an expression to return the customized value.
4271 ;; NOW if non-nil means always set the variable immediately
4272 ;; when the customizations are reloaded. This is used
4273 ;; for rogue variables
4274 ;; REQUESTS is a list of packages to load before setting the
4275 ;; variable. Each element of it will be passed to `require'.
4276 ;; COMMENT is whatever comment the user has specified
4277 ;; with the customize facility.
4284 (when (or now requests comment
)
4287 (when (or requests comment
)
4297 (unless (looking-at "\n")
4300 (defun custom-save-faces ()
4301 "Save all customized faces in `custom-file'."
4303 (custom-save-delete 'custom-reset-faces
)
4304 (custom-save-delete 'custom-set-faces
)
4305 (let ((standard-output (current-buffer))
4306 (saved-list (make-list 1 0))
4308 ;; First create a sorted list of saved faces.
4311 (if (and (get symbol
'saved-face
)
4312 (eq 'user
(car (car-safe (get symbol
'theme-face
)))))
4313 (nconc saved-list
(list symbol
)))))
4314 (setq saved-list
(sort (cdr saved-list
) 'string
<))
4315 ;; The default face must be first, since it affects the others.
4316 (if (memq 'default saved-list
)
4317 (setq saved-list
(cons 'default
(delq 'default saved-list
))))
4320 (princ "(custom-set-faces
4321 ;; custom-set-faces was added by Custom.
4322 ;; If you edit it by hand, you could mess it up, so be careful.
4323 ;; Your init file should contain only one such instance.
4324 ;; If there is more than one, they won't work right.\n")
4325 (dolist (symbol saved-list
)
4326 (let ((spec (car-safe (get symbol
'theme-face
)))
4327 (value (get symbol
'saved-face
))
4328 (now (not (or (get symbol
'face-defface-spec
)
4329 (and (not (custom-facep symbol
))
4330 (not (get symbol
'force-face
))))))
4331 (comment (get symbol
'saved-face-comment
)))
4332 (when (or (and spec
(eq (nth 0 spec
) 'user
))
4334 (and (null spec
) (get symbol
'saved-face
)))
4335 ;; Don't print default face here.
4342 (when (or now comment
)
4352 (unless (looking-at "\n")
4355 ;;; The Customize Menu.
4359 (defcustom custom-menu-nesting
2
4360 "Maximum nesting in custom menus."
4362 :group
'custom-menu
)
4364 (defun custom-face-menu-create (widget symbol
)
4365 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
4366 (vector (custom-unlispify-menu-entry symbol
)
4367 `(customize-face ',symbol
)
4370 (defun custom-variable-menu-create (widget symbol
)
4371 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
4372 (let ((type (get symbol
'custom-type
)))
4373 (unless (listp type
)
4374 (setq type
(list type
)))
4375 (if (and type
(widget-get type
:custom-menu
))
4376 (widget-apply type
:custom-menu symbol
)
4377 (vector (custom-unlispify-menu-entry symbol
)
4378 `(customize-variable ',symbol
)
4381 ;; Add checkboxes to boolean variable entries.
4382 (widget-put (get 'boolean
'widget-type
)
4383 :custom-menu
(lambda (widget symbol
)
4384 (vector (custom-unlispify-menu-entry symbol
)
4385 `(customize-variable ',symbol
)
4387 ':selected symbol
)))
4389 (defun custom-group-menu-create (widget symbol
)
4390 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
4391 `( ,(custom-unlispify-menu-entry symbol t
)
4392 :filter
(lambda (&rest junk
)
4393 (let* ((menu (custom-menu-create ',symbol
)))
4394 (if (consp menu
) (cdr menu
) menu
)))))
4397 (defun custom-menu-create (symbol)
4398 "Create menu for customization group SYMBOL.
4399 The menu is in a format applicable to `easy-menu-define'."
4400 (let* ((deactivate-mark nil
)
4401 (item (vector (custom-unlispify-menu-entry symbol
)
4402 `(customize-group ',symbol
)
4404 (if (and (or (not (boundp 'custom-menu-nesting
))
4405 (>= custom-menu-nesting
0))
4407 (custom-load-symbol symbol
)
4408 (< (length (get symbol
'custom-group
)) widget-menu-max-size
)))
4409 (let ((custom-prefix-list (custom-prefix-add symbol
4410 custom-prefix-list
))
4411 (members (custom-sort-items (get symbol
'custom-group
)
4412 custom-menu-sort-alphabetically
4413 custom-menu-order-groups
)))
4414 `(,(custom-unlispify-menu-entry symbol t
)
4417 ,@(mapcar (lambda (entry)
4418 (widget-apply (if (listp (nth 1 entry
))
4420 (list (nth 1 entry
)))
4421 :custom-menu
(nth 0 entry
)))
4426 (defun customize-menu-create (symbol &optional name
)
4427 "Return a customize menu for customization group SYMBOL.
4428 If optional NAME is given, use that as the name of the menu.
4429 Otherwise the menu will be named `Customize'.
4430 The format is suitable for use with `easy-menu-define'."
4432 (setq name
"Customize"))
4434 :filter
(lambda (&rest junk
)
4435 (let ((menu (custom-menu-create ',symbol
)))
4436 (if (consp menu
) (cdr menu
) menu
)))))
4438 ;;; Toolbar and menubar support
4441 Custom-mode-menu custom-mode-map
4442 "Menu used in customization buffers."
4443 (nconc (list "Custom"
4444 (customize-menu-create 'customize
))
4445 (mapcar (lambda (arg)
4446 (let ((tag (nth 0 arg
))
4447 (command (nth 1 arg
))
4448 (active (nth 2 arg
))
4450 (vector tag command
:active
(eval active
) :help help
)))
4453 (defvar tool-bar-map
)
4454 (defvar custom-tool-bar-map
4455 (if (display-graphic-p)
4456 (let ((map (make-sparse-keymap)))
4459 (tool-bar-local-item-from-menu
4460 (nth 1 arg
) (nth 4 arg
) map custom-mode-map
))
4464 ;;; The Custom Mode.
4466 (defun Custom-no-edit (pos &optional event
)
4467 "Invoke button at POS, or refuse to allow editing of Custom buffer."
4469 (error "You can't edit this part of the Custom buffer"))
4471 (defun Custom-newline (pos &optional event
)
4472 "Invoke button at POS, or refuse to allow editing of Custom buffer."
4474 (let ((button (get-char-property pos
'button
)))
4476 (widget-apply-action button event
)
4477 (error "You can't edit this part of the Custom buffer"))))
4479 (defvar custom-field-keymap
4480 (let ((map (copy-keymap widget-field-keymap
)))
4481 (define-key map
"\C-c\C-c" 'Custom-set
)
4482 (define-key map
"\C-x\C-s" 'Custom-save
)
4484 "Keymap used inside editable fields in customization buffers.")
4486 (widget-put (get 'editable-field
'widget-type
) :keymap custom-field-keymap
)
4488 (defun Custom-goto-parent ()
4489 "Go to the parent group listed at the top of this buffer.
4490 If several parents are listed, go to the first of them."
4493 (goto-char (point-min))
4494 (if (search-forward "\nGo to parent group: " nil t
)
4495 (let* ((button (get-char-property (point) 'button
))
4496 (parent (downcase (widget-get button
:tag
))))
4497 (customize-group parent
)))))
4499 (defcustom custom-mode-hook nil
4500 "Hook called when entering Custom mode."
4502 :group
'custom-buffer
)
4504 (defun custom-state-buffer-message (widget)
4505 (if (eq (widget-get (widget-get widget
:parent
) :custom-state
) 'modified
)
4506 (message "To install your edits, invoke [State] and choose the Set operation")))
4508 (defun custom-mode ()
4509 "Major mode for editing customization buffers.
4511 The following commands are available:
4514 Move to next button, link or editable field. \\[widget-forward]
4515 Move to previous button, link or editable field. \\[advertised-widget-backward]
4516 \\<custom-field-keymap>\
4517 Complete content of editable text field. \\[widget-complete]
4518 \\<custom-mode-map>\
4519 Invoke button under the mouse pointer. \\[widget-button-click]
4520 Invoke button under point. \\[widget-button-press]
4521 Set all options from current text. \\[Custom-set]
4522 Make values in current text permanent. \\[Custom-save]
4523 Make text match actual option values. \\[Custom-reset-current]
4524 Reset options to permanent settings. \\[Custom-reset-saved]
4525 Erase customizations; set options
4526 and buffer text to the standard values. \\[Custom-reset-standard]
4528 Entry to this mode calls the value of `custom-mode-hook'
4529 if that value is non-nil."
4530 (kill-all-local-variables)
4531 (setq major-mode
'custom-mode
4533 (use-local-map custom-mode-map
)
4534 (easy-menu-add Custom-mode-menu
)
4535 (set (make-local-variable 'tool-bar-map
) custom-tool-bar-map
)
4536 (make-local-variable 'custom-options
)
4537 (make-local-variable 'custom-local-buffer
)
4538 (make-local-variable 'widget-documentation-face
)
4539 (setq widget-documentation-face
'custom-documentation
)
4540 (make-local-variable 'widget-button-face
)
4541 (setq widget-button-face custom-button
)
4543 ;; We need this because of the "More" button on docstrings.
4544 ;; Otherwise clicking on "More" can push point offscreen, which
4545 ;; causes the window to recenter on point, which pushes the
4546 ;; newly-revealed docstring offscreen; which is annoying. -- cyd.
4547 (set (make-local-variable 'widget-button-click-moves-point
) t
)
4549 (set (make-local-variable 'widget-button-pressed-face
) custom-button-pressed
)
4550 (set (make-local-variable 'widget-mouse-face
) custom-button-mouse
)
4552 ;; When possible, use relief for buttons, not bracketing. This test
4553 ;; may not be optimal.
4554 (when custom-raised-buttons
4555 (set (make-local-variable 'widget-push-button-prefix
) "")
4556 (set (make-local-variable 'widget-push-button-suffix
) "")
4557 (set (make-local-variable 'widget-link-prefix
) "")
4558 (set (make-local-variable 'widget-link-suffix
) ""))
4559 (add-hook 'widget-edit-functions
'custom-state-buffer-message nil t
)
4560 (run-mode-hooks 'custom-mode-hook
))
4562 (put 'custom-mode
'mode-class
'special
)
4565 '("^No user option defaults have been changed since Emacs "
4567 "^No \\(?:customized\\|rogue\\|saved\\) user options"
4568 "^No customizable items matching "
4569 "^There are unset changes"
4570 "^Cannot set hidden variable"
4571 "^No \\(?:saved\\|backup\\) value for "
4572 "^No standard setting known for "
4573 "^No standard setting for this face"
4574 "^Saving settings from \"emacs -q\" would overwrite existing customizations"))
4575 (add-to-list 'debug-ignored-errors regexp
))
4581 ;; arch-tag: 64533aa4-1b1a-48c3-8812-f9dc718e8a6f
4582 ;;; cus-edit.el ends here