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 with from the result with:
505 (mapconcat 'identity result \"\\|\")
507 IF REGEXP is not a string, return it unchanged."
511 (while (string-match "\\\\|" regexp start
)
512 (setq all
(cons (substring regexp start
(match-beginning 0)) all
)
513 start
(match-end 0)))
514 (nreverse (cons (substring regexp start
) all
)))
517 (defun custom-variable-prompt ()
518 "Prompt for a custom variable, defaulting to the variable at point.
519 Return a list suitable for use in `interactive'."
520 (let* ((v (variable-at-point))
521 (default (and (symbolp v
) (custom-variable-p v
) (symbol-name v
)))
522 (enable-recursive-minibuffers t
)
524 (setq val
(completing-read
525 (if default
(format "Customize variable (default %s): " default
)
526 "Customize variable: ")
527 obarray
'custom-variable-p t nil nil default
))
528 (list (if (equal val
"")
529 (if (symbolp v
) v nil
)
532 (defun custom-menu-filter (menu widget
)
533 "Convert MENU to the form used by `widget-choose'.
534 MENU should be in the same format as `custom-variable-menu'.
535 WIDGET is the widget to apply the filter entries of MENU on."
537 current name action filter
)
539 (setq current
(car menu
)
541 action
(nth 1 current
)
542 filter
(nth 2 current
)
544 (if (or (null filter
) (funcall filter widget
))
545 (push (cons name action
) result
)
551 (defvar custom-prefix-list nil
552 "List of prefixes that should be ignored by `custom-unlispify'.")
554 (defcustom custom-unlispify-menu-entries t
555 "Display menu entries as words instead of symbols if non-nil."
559 (defcustom custom-unlispify-remove-prefixes nil
560 "Non-nil means remove group prefixes from option names in buffer."
562 :group
'custom-buffer
565 (defun custom-unlispify-menu-entry (symbol &optional no-suffix
)
566 "Convert SYMBOL into a menu entry."
567 (cond ((not custom-unlispify-menu-entries
)
568 (symbol-name symbol
))
569 ((get symbol
'custom-tag
)
571 (get symbol
'custom-tag
)
572 (concat (get symbol
'custom-tag
) "...")))
574 (with-current-buffer (get-buffer-create " *Custom-Work*")
576 (princ symbol
(current-buffer))
577 (goto-char (point-min))
578 ;; FIXME: Boolean variables are not predicates, so they shouldn't
579 ;; end with `-p'. -stef
580 ;; (when (and (eq (get symbol 'custom-type) 'boolean)
581 ;; (re-search-forward "-p\\'" nil t))
582 ;; (replace-match "" t t)
583 ;; (goto-char (point-min)))
584 (if custom-unlispify-remove-prefixes
585 (let ((prefixes custom-prefix-list
)
588 (setq prefix
(car prefixes
))
589 (if (search-forward prefix
(+ (point) (length prefix
)) t
)
592 (delete-region (point-min) (point)))
593 (setq prefixes
(cdr prefixes
))))))
594 (subst-char-in-region (point-min) (point-max) ?- ?\ t
)
595 (capitalize-region (point-min) (point-max))
597 (goto-char (point-max))
601 (defcustom custom-unlispify-tag-names t
602 "Display tag names as words instead of symbols if non-nil."
603 :group
'custom-buffer
606 (defun custom-unlispify-tag-name (symbol)
607 "Convert SYMBOL into a menu entry."
608 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names
))
609 (custom-unlispify-menu-entry symbol t
)))
611 (defun custom-prefix-add (symbol prefixes
)
612 "Add SYMBOL to list of ignored PREFIXES."
613 (cons (or (get symbol
'custom-prefix
)
614 (concat (symbol-name symbol
) "-"))
619 (defcustom custom-guess-name-alist
625 ("-function\\'" function
)
626 ("-functions\\'" (repeat function
))
627 ("-list\\'" (repeat sexp
))
628 ("-alist\\'" (repeat (cons sexp sexp
))))
629 "Alist of (MATCH TYPE).
631 MATCH should be a regexp matching the name of a symbol, and TYPE should
632 be a widget suitable for editing the value of that symbol. The TYPE
633 of the first entry where MATCH matches the name of the symbol will be
636 This is used for guessing the type of variables not declared with
638 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
639 :group
'custom-buffer
)
641 (defcustom custom-guess-doc-alist
642 '(("\\`\\*?Non-nil " boolean
))
643 "Alist of (MATCH TYPE).
645 MATCH should be a regexp matching a documentation string, and TYPE
646 should be a widget suitable for editing the value of a variable with
647 that documentation string. The TYPE of the first entry where MATCH
648 matches the name of the symbol will be used.
650 This is used for guessing the type of variables not declared with
652 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
653 :group
'custom-buffer
)
655 (defun custom-guess-type (symbol)
656 "Guess a widget suitable for editing the value of SYMBOL.
657 This is done by matching SYMBOL with `custom-guess-name-alist' and
658 if that fails, the doc string with `custom-guess-doc-alist'."
659 (let ((name (symbol-name symbol
))
660 (names custom-guess-name-alist
)
663 (setq current
(car names
)
665 (when (string-match (nth 0 current
) name
)
666 (setq found
(nth 1 current
)
669 (let ((doc (documentation-property symbol
'variable-documentation
))
670 (docs custom-guess-doc-alist
))
673 (setq current
(car docs
)
675 (when (string-match (nth 0 current
) doc
)
676 (setq found
(nth 1 current
)
683 (defcustom custom-browse-sort-alphabetically nil
684 "If non-nil, sort customization group alphabetically in `custom-browse'."
686 :group
'custom-browse
)
688 (defcustom custom-browse-order-groups nil
689 "If non-nil, order group members within each customization group.
690 If `first', order groups before non-groups.
691 If `last', order groups after non-groups."
692 :type
'(choice (const first
)
694 (const :tag
"none" nil
))
695 :group
'custom-browse
)
697 (defcustom custom-browse-only-groups nil
698 "If non-nil, show group members only within each customization group."
700 :group
'custom-browse
)
703 (defcustom custom-buffer-sort-alphabetically nil
704 "If non-nil, sort each customization group alphabetically in Custom buffer."
706 :group
'custom-buffer
)
708 (defcustom custom-buffer-order-groups
'last
709 "If non-nil, order group members within each customization group.
710 If `first', order groups before non-groups.
711 If `last', order groups after non-groups."
712 :type
'(choice (const first
)
714 (const :tag
"none" nil
))
715 :group
'custom-buffer
)
718 (defcustom custom-menu-sort-alphabetically nil
719 "If non-nil, sort each customization group alphabetically in menus."
723 (defcustom custom-menu-order-groups
'first
724 "If non-nil, order group members within each customization group.
725 If `first', order groups before non-groups.
726 If `last', order groups after non-groups."
727 :type
'(choice (const first
)
729 (const :tag
"none" nil
))
732 ;;;###autoload (add-hook 'same-window-regexps "\\`\\*Customiz.*\\*\\'")
734 (defun custom-sort-items (items sort-alphabetically order-groups
)
735 "Return a sorted copy of ITEMS.
736 ITEMS should be a `custom-group' property.
737 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
738 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
739 groups after non-groups, if nil do not order groups at all."
740 (sort (copy-sequence items
)
742 (let ((typea (nth 1 a
)) (typeb (nth 1 b
))
743 (namea (nth 0 a
)) (nameb (nth 0 b
)))
744 (cond ((not order-groups
)
745 ;; Since we don't care about A and B order, maybe sort.
746 (when sort-alphabetically
747 (string-lessp namea nameb
)))
748 ((eq typea
'custom-group
)
749 ;; If B is also a group, maybe sort. Otherwise, order A and B.
750 (if (eq typeb
'custom-group
)
751 (when sort-alphabetically
752 (string-lessp namea nameb
))
753 (eq order-groups
'first
)))
754 ((eq typeb
'custom-group
)
755 ;; Since A cannot be a group, order A and B.
756 (eq order-groups
'last
))
758 ;; Since A and B cannot be groups, sort.
759 (string-lessp namea nameb
)))))))
761 ;;; Custom Mode Commands.
763 (defvar custom-options nil
764 "Customization widgets in the current buffer.")
767 "Set the current value of all edited settings in the buffer."
769 (let ((children custom-options
))
770 (if (or (and (= 1 (length children
))
771 (memq (widget-type (car children
))
772 '(custom-variable custom-face
)))
773 (y-or-n-p "Set all values according to this buffer? "))
774 (mapc (lambda (child)
775 (when (eq (widget-get child
:custom-state
) 'modified
)
776 (widget-apply child
:custom-set
)))
778 (message "Aborted"))))
780 (defun Custom-save ()
781 "Set all edited settings, then save all settings that have been set.
782 If a setting was edited and set before, this saves it.
783 If a setting was merely edited before, this sets it then saves it."
785 (let ((children custom-options
))
786 (if (or (and (= 1 (length children
))
787 (memq (widget-type (car children
))
788 '(custom-variable custom-face
)))
789 (yes-or-no-p "Save all settings in this buffer? "))
791 (mapc (lambda (child)
792 (when (memq (widget-get child
:custom-state
)
793 '(modified set changed rogue
))
794 (widget-apply child
:custom-save
)))
797 (message "Aborted"))))
799 (defvar custom-reset-menu
800 '(("Undo Edits" . Custom-reset-current
)
801 ("Reset to Saved" . Custom-reset-saved
)
802 ("Erase Customization (use standard values)" . Custom-reset-standard
))
803 "Alist of actions for the `Reset' button.
804 The key is a string containing the name of the action, the value is a
805 Lisp function taking the widget as an element which will be called
806 when the action is chosen.")
808 (defun custom-reset (event)
809 "Select item from reset menu."
810 (let* ((completion-ignore-case t
)
811 (answer (widget-choose "Reset settings"
817 (defun Custom-reset-current (&rest ignore
)
818 "Reset all edited settings in the buffer to show their current values."
820 (let ((children custom-options
))
821 (if (or (and (= 1 (length children
))
822 (memq (widget-type (car children
))
823 '(custom-variable custom-face
)))
824 (y-or-n-p "Reset all settings' buffer text to show current values? "))
825 (mapc (lambda (widget)
826 (if (memq (widget-get widget
:custom-state
)
828 (widget-apply widget
:custom-reset-current
)))
830 (message "Aborted"))))
832 (defun Custom-reset-saved (&rest ignore
)
833 "Reset all edited or set settings in the buffer to their saved value.
834 This also shows the saved values in the buffer."
836 (let ((children custom-options
))
837 (if (or (and (= 1 (length children
))
838 (memq (widget-type (car children
))
839 '(custom-variable custom-face
)))
840 (y-or-n-p "Reset all settings (current values and buffer text) to saved values? "))
841 (mapc (lambda (widget)
842 (if (memq (widget-get widget
:custom-state
)
843 '(modified set changed rogue
))
844 (widget-apply widget
:custom-reset-saved
)))
846 (message "Aborted"))))
848 (defun Custom-reset-standard (&rest ignore
)
849 "Erase all customization (either current or saved) for the group members.
850 The immediate result is to restore them to their standard values.
851 This operation eliminates any saved values for the group members,
852 making them as if they had never been customized at all."
854 (let ((children custom-options
))
855 (if (or (and (= 1 (length children
))
856 (memq (widget-type (car children
))
857 '(custom-variable custom-face
)))
858 (yes-or-no-p "Erase all customizations for settings in this buffer? "))
859 (mapc (lambda (widget)
860 (and (if (widget-get widget
:custom-standard-value
)
861 (widget-apply widget
:custom-standard-value
)
863 (memq (widget-get widget
:custom-state
)
864 '(modified set changed saved rogue
))
865 (widget-apply widget
:custom-reset-standard
)))
867 (message "Aborted"))))
869 ;;; The Customize Commands
871 (defun custom-prompt-variable (prompt-var prompt-val
&optional comment
)
872 "Prompt for a variable and a value and return them as a list.
873 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
874 prompt for the value. The %s escape in PROMPT-VAL is replaced with
875 the name of the variable.
877 If the variable has a `variable-interactive' property, that is used as if
878 it were the arg to `interactive' (which see) to interactively read the value.
880 If the variable has a `custom-type' property, it must be a widget and the
881 `:prompt-value' property of that widget will be used for reading the value.
883 If optional COMMENT argument is non-nil, also prompt for a comment and return
884 it as the third element in the list."
885 (let* ((var (read-variable prompt-var
))
886 (minibuffer-help-form '(describe-variable var
))
888 (let ((prop (get var
'variable-interactive
))
889 (type (get var
'custom-type
))
890 (prompt (format prompt-val var
)))
892 (setq type
(list type
)))
894 ;; Use VAR's `variable-interactive' property
895 ;; as an interactive spec for prompting.
896 (call-interactively (list 'lambda
'(arg)
897 (list 'interactive prop
)
900 (widget-prompt-value type
906 (eval-minibuffer prompt
))))))
909 (read-string "Comment: " (get var
'variable-comment
)))
913 (defun customize-set-value (variable value
&optional comment
)
914 "Set VARIABLE to VALUE, and return VALUE. VALUE is a Lisp object.
916 If VARIABLE has a `variable-interactive' property, that is used as if
917 it were the arg to `interactive' (which see) to interactively read the value.
919 If VARIABLE has a `custom-type' property, it must be a widget and the
920 `:prompt-value' property of that widget will be used for reading the value.
922 If given a prefix (or a COMMENT argument), also prompt for a comment."
923 (interactive (custom-prompt-variable "Set variable: "
927 (cond ((string= comment
"")
928 (put variable
'variable-comment nil
))
930 (put variable
'variable-comment comment
)))
931 (set variable value
))
934 (defun customize-set-variable (variable value
&optional comment
)
935 "Set the default for VARIABLE to VALUE, and return VALUE.
936 VALUE is a Lisp object.
938 If VARIABLE has a `custom-set' property, that is used for setting
939 VARIABLE, otherwise `set-default' is used.
941 If VARIABLE has a `variable-interactive' property, that is used as if
942 it were the arg to `interactive' (which see) to interactively read the value.
944 If VARIABLE has a `custom-type' property, it must be a widget and the
945 `:prompt-value' property of that widget will be used for reading the value.
947 If given a prefix (or a COMMENT argument), also prompt for a comment."
948 (interactive (custom-prompt-variable "Set variable: "
949 "Set customized value for %s to: "
951 (custom-load-symbol variable
)
952 (custom-push-theme 'theme-value variable
'user
'set
(custom-quote value
))
953 (funcall (or (get variable
'custom-set
) 'set-default
) variable value
)
954 (put variable
'customized-value
(list (custom-quote value
)))
955 (cond ((string= comment
"")
956 (put variable
'variable-comment nil
)
957 (put variable
'customized-variable-comment nil
))
959 (put variable
'variable-comment comment
)
960 (put variable
'customized-variable-comment comment
)))
964 (defun customize-save-variable (variable value
&optional comment
)
965 "Set the default for VARIABLE to VALUE, and save it for future sessions.
968 If VARIABLE has a `custom-set' property, that is used for setting
969 VARIABLE, otherwise `set-default' is used.
971 If VARIABLE has a `variable-interactive' property, that is used as if
972 it were the arg to `interactive' (which see) to interactively read the value.
974 If VARIABLE has a `custom-type' property, it must be a widget and the
975 `:prompt-value' property of that widget will be used for reading the value.
977 If given a prefix (or a COMMENT argument), also prompt for a comment."
978 (interactive (custom-prompt-variable "Set and save variable: "
979 "Set and save value for %s as: "
981 (funcall (or (get variable
'custom-set
) 'set-default
) variable value
)
982 (put variable
'saved-value
(list (custom-quote value
)))
983 (custom-push-theme 'theme-value variable
'user
'set
(custom-quote value
))
984 (cond ((string= comment
"")
985 (put variable
'variable-comment nil
)
986 (put variable
'saved-variable-comment nil
))
988 (put variable
'variable-comment comment
)
989 (put variable
'saved-variable-comment comment
)))
990 (put variable
'customized-value nil
)
991 (put variable
'customized-variable-comment nil
)
997 "Select a customization buffer which you can use to set user options.
998 User options are structured into \"groups\".
999 Initially the top-level group `Emacs' and its immediate subgroups
1000 are shown; the contents of those subgroups are initially hidden."
1002 (customize-group 'emacs
))
1005 (defun customize-mode (mode)
1006 "Customize options related to the current major mode.
1007 If a prefix \\[universal-argument] was given (or if the current major mode has no known group),
1008 then prompt for the MODE to customize."
1011 (let ((completion-regexp-list '("-mode\\'"))
1012 (group (custom-group-of-mode major-mode
)))
1013 (if (and group
(not current-prefix-arg
))
1016 (completing-read (if group
1017 (format "Major mode (default %s): " major-mode
)
1020 'custom-group-of-mode
1021 t nil nil
(if group
(symbol-name major-mode
))))))))
1022 (customize-group (custom-group-of-mode mode
)))
1026 (defun customize-group (group)
1027 "Customize GROUP, which must be a customization group."
1029 (list (let ((completion-ignore-case t
))
1030 (completing-read "Customize group (default emacs): "
1033 (or (and (get symbol
'custom-loads
)
1034 (not (get symbol
'custom-autoload
)))
1035 (get symbol
'custom-group
)))
1037 (when (stringp group
)
1038 (if (string-equal "" group
)
1040 (setq group
(intern group
))))
1041 (let ((name (format "*Customize Group: %s*"
1042 (custom-unlispify-tag-name group
))))
1043 (if (get-buffer name
)
1044 (pop-to-buffer name
)
1045 (custom-buffer-create (list (list group
'custom-group
))
1047 (concat " for group "
1048 (custom-unlispify-tag-name group
))))))
1051 (defun customize-group-other-window (group)
1052 "Customize GROUP, which must be a customization group."
1054 (list (let ((completion-ignore-case t
))
1055 (completing-read "Customize group (default emacs): "
1058 (or (and (get symbol
'custom-loads
)
1059 (not (get symbol
'custom-autoload
)))
1060 (get symbol
'custom-group
)))
1062 (when (stringp group
)
1063 (if (string-equal "" group
)
1065 (setq group
(intern group
))))
1066 (let ((name (format "*Customize Group: %s*"
1067 (custom-unlispify-tag-name group
))))
1068 (if (get-buffer name
)
1070 ;; Copied from `custom-buffer-create-other-window'.
1072 (same-window-buffer-names nil
)
1073 (same-window-regexps nil
))
1074 (pop-to-buffer name
))
1075 (custom-buffer-create-other-window
1076 (list (list group
'custom-group
))
1078 (concat " for group "
1079 (custom-unlispify-tag-name group
))))))
1082 (defalias 'customize-variable
'customize-option
)
1085 (defun customize-option (symbol)
1086 "Customize SYMBOL, which must be a user option variable."
1087 (interactive (custom-variable-prompt))
1089 (error "No variable specified"))
1090 (let ((basevar (indirect-variable symbol
)))
1091 (custom-buffer-create (list (list basevar
'custom-variable
))
1092 (format "*Customize Option: %s*"
1093 (custom-unlispify-tag-name basevar
)))
1094 (unless (eq symbol basevar
)
1095 (message "`%s' is an alias for `%s'" symbol basevar
))))
1098 (defalias 'customize-variable-other-window
'customize-option-other-window
)
1101 (defun customize-option-other-window (symbol)
1102 "Customize SYMBOL, which must be a user option variable.
1103 Show the buffer in another window, but don't select it."
1104 (interactive (custom-variable-prompt))
1106 (error "No variable specified"))
1107 (let ((basevar (indirect-variable symbol
)))
1108 (custom-buffer-create-other-window
1109 (list (list basevar
'custom-variable
))
1110 (format "*Customize Option: %s*" (custom-unlispify-tag-name basevar
)))
1111 (unless (eq symbol basevar
)
1112 (message "`%s' is an alias for `%s'" symbol basevar
))))
1114 (defvar customize-changed-options-previous-release
"21.1"
1115 "Version for `customize-changed-options' to refer back to by default.")
1117 ;; Packages will update this variable, so make it available.
1119 (defvar customize-package-emacs-version-alist nil
1120 "Alist mapping versions of a package to Emacs versions.
1121 We use this for packages that have their own names, but are released
1122 as part of Emacs itself.
1124 Each elements looks like this:
1126 (PACKAGE (PVERSION . EVERSION)...)
1128 Here PACKAGE is the name of a package, as a symbol. After
1129 PACKAGE come one or more elements, each associating a
1130 package version PVERSION with the first Emacs version
1131 EVERSION in which it (or a subsequent version of PACKAGE)
1132 was first released. Both PVERSION and EVERSION are strings.
1133 PVERSION should be a string that this package used in
1134 the :package-version keyword for `defcustom', `defgroup',
1137 For example, the MH-E package updates this alist as follows:
1139 (add-to-list 'customize-package-emacs-version-alist
1140 '(MH-E (\"6.0\" . \"22.1\") (\"6.1\" . \"22.1\")
1141 (\"7.0\" . \"22.1\") (\"7.1\" . \"22.1\")
1142 (\"7.2\" . \"22.1\") (\"7.3\" . \"22.1\")
1143 (\"7.4\" . \"22.1\") (\"8.0\" . \"22.1\")))
1145 The value of PACKAGE needs to be unique and it needs to match the
1146 PACKAGE value appearing in the :package-version keyword. Since
1147 the user might see the value in a error message, a good choice is
1148 the official name of the package, such as MH-E or Gnus.")
1151 (defalias 'customize-changed
'customize-changed-options
)
1154 (defun customize-changed-options (since-version)
1155 "Customize all settings whose meanings have changed in Emacs itself.
1156 This includes new user option variables and faces, and new
1157 customization groups, as well as older options and faces whose meanings
1158 or default values have changed since the previous major Emacs release.
1160 With argument SINCE-VERSION (a string), customize all settings
1161 that were added or redefined since that version."
1165 (read-from-minibuffer
1166 (format "Customize options changed, since version (default %s): "
1167 customize-changed-options-previous-release
))))
1168 (if (equal since-version
"")
1169 (setq since-version nil
)
1170 (unless (condition-case nil
1171 (numberp (read since-version
))
1173 (signal 'wrong-type-argument
(list 'numberp since-version
))))
1174 (unless since-version
1175 (setq since-version customize-changed-options-previous-release
))
1177 ;; Load the information for versions since since-version. We use
1178 ;; custom-load-symbol for this.
1179 (put 'custom-versions-load-alist
'custom-loads nil
)
1180 (dolist (elt custom-versions-load-alist
)
1181 (if (customize-version-lessp since-version
(car elt
))
1182 (dolist (load (cdr elt
))
1183 (custom-add-load 'custom-versions-load-alist load
))))
1184 (custom-load-symbol 'custom-versions-load-alist
)
1185 (put 'custom-versions-load-alist
'custom-loads nil
)
1190 (let* ((package-version (get symbol
'custom-package-version
))
1192 (or (and package-version
1193 (customize-package-emacs-version symbol
1195 (get symbol
'custom-version
))))
1197 (when (customize-version-lessp since-version version
)
1198 (if (or (get symbol
'custom-group
)
1199 (get symbol
'group-documentation
))
1200 (push (list symbol
'custom-group
) found
))
1201 (if (custom-variable-p symbol
)
1202 (push (list symbol
'custom-variable
) found
))
1203 (if (custom-facep symbol
)
1204 (push (list symbol
'custom-face
) found
)))))))
1206 (custom-buffer-create (custom-sort-items found t
'first
)
1207 "*Customize Changed Options*")
1208 (error "No user option defaults have been changed since Emacs %s"
1211 (defun customize-package-emacs-version (symbol package-version
)
1212 "Return the Emacs version in which SYMBOL's meaning last changed.
1213 PACKAGE-VERSION has the form (PACKAGE . VERSION). We use
1214 `customize-package-emacs-version-alist' to find the version of
1215 Emacs that is associated with version VERSION of PACKAGE."
1216 (let (package-versions emacs-version
)
1217 ;; Use message instead of error since we want user to be able to
1218 ;; see the rest of the symbols even if a package author has
1219 ;; botched things up.
1220 (cond ((not (listp package-version
))
1221 (message "Invalid package-version value for %s" symbol
))
1222 ((setq package-versions
(assq (car package-version
)
1223 customize-package-emacs-version-alist
))
1225 (cdr (assoc (cdr package-version
) package-versions
)))
1226 (unless emacs-version
1227 (message "%s version %s not found in %s" symbol
1228 (cdr package-version
)
1229 "customize-package-emacs-version-alist")))
1231 (message "Package %s version %s lists no corresponding Emacs version"
1232 (car package-version
)
1233 (cdr package-version
))))
1236 (defun customize-version-lessp (version1 version2
)
1237 ;; Why are the versions strings, and given that they are, why aren't
1238 ;; they converted to numbers and compared as such here? -- fx
1240 ;; In case someone made a mistake and left out the quotes
1241 ;; in the :version value.
1242 (if (numberp version2
)
1243 (setq version2
(prin1-to-string version2
)))
1244 (let (major1 major2 minor1 minor2
)
1245 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version1
)
1246 (setq major1
(read (or (match-string 1 version1
)
1248 (setq minor1
(read (or (match-string 3 version1
)
1250 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version2
)
1251 (setq major2
(read (or (match-string 1 version2
)
1253 (setq minor2
(read (or (match-string 3 version2
)
1255 (or (< major1 major2
)
1256 (and (= major1 major2
)
1257 (< minor1 minor2
)))))
1260 (defun customize-face (&optional face
)
1261 "Customize FACE, which should be a face name or nil.
1262 If FACE is nil, customize all faces. If FACE is actually a
1263 face-alias, customize the face it is aliased to.
1265 Interactively, when point is on text which has a face specified,
1266 suggest to customize that face, if it's customizable."
1268 (list (read-face-name "Customize face" "all faces" t
)))
1269 (if (member face
'(nil ""))
1270 (setq face
(face-list)))
1271 (if (and (listp face
) (null (cdr face
)))
1272 (setq face
(car face
)))
1274 (custom-buffer-create (custom-sort-items
1276 (list s
'custom-face
))
1279 "*Customize Faces*")
1280 ;; If FACE is actually an alias, customize the face it is aliased to.
1281 (if (get face
'face-alias
)
1282 (setq face
(get face
'face-alias
)))
1283 (unless (facep face
)
1284 (error "Invalid face %S" face
))
1285 (custom-buffer-create (list (list face
'custom-face
))
1286 (format "*Customize Face: %s*"
1287 (custom-unlispify-tag-name face
)))))
1290 (defun customize-face-other-window (&optional face
)
1291 "Show customization buffer for face FACE in other window.
1292 If FACE is actually a face-alias, customize the face it is aliased to.
1294 Interactively, when point is on text which has a face specified,
1295 suggest to customize that face, if it's customizable."
1297 (list (read-face-name "Customize face" "all faces" t
)))
1298 (if (member face
'(nil ""))
1299 (setq face
(face-list)))
1300 (if (and (listp face
) (null (cdr face
)))
1301 (setq face
(car face
)))
1303 (custom-buffer-create-other-window
1306 (list s
'custom-face
))
1309 "*Customize Faces*")
1310 (if (get face
'face-alias
)
1311 (setq face
(get face
'face-alias
)))
1312 (unless (facep face
)
1313 (error "Invalid face %S" face
))
1314 (custom-buffer-create-other-window
1315 (list (list face
'custom-face
))
1316 (format "*Customize Face: %s*"
1317 (custom-unlispify-tag-name face
)))))
1319 (defalias 'customize-customized
'customize-unsaved
)
1322 (defun customize-unsaved ()
1323 "Customize all user options set in this session but not saved."
1326 (mapatoms (lambda (symbol)
1327 (and (or (get symbol
'customized-face
)
1328 (get symbol
'customized-face-comment
))
1329 (custom-facep symbol
)
1330 (push (list symbol
'custom-face
) found
))
1331 (and (or (get symbol
'customized-value
)
1332 (get symbol
'customized-variable-comment
))
1334 (push (list symbol
'custom-variable
) found
))))
1336 (error "No user options are set but unsaved")
1337 (custom-buffer-create (custom-sort-items found t nil
)
1338 "*Customize Unsaved*"))))
1341 (defun customize-rogue ()
1342 "Customize all user variables modified outside customize."
1345 (mapatoms (lambda (symbol)
1346 (let ((cval (or (get symbol
'customized-value
)
1347 (get symbol
'saved-value
)
1348 (get symbol
'standard-value
))))
1349 (when (and cval
;Declared with defcustom.
1350 (default-boundp symbol
) ;Has a value.
1351 (not (equal (eval (car cval
))
1352 ;; Which does not match customize.
1353 (default-value symbol
))))
1354 (push (list symbol
'custom-variable
) found
)))))
1356 (error "No rogue user options")
1357 (custom-buffer-create (custom-sort-items found t nil
)
1358 "*Customize Rogue*"))))
1360 (defun customize-saved ()
1361 "Customize all already saved user options."
1364 (mapatoms (lambda (symbol)
1365 (and (or (get symbol
'saved-face
)
1366 (get symbol
'saved-face-comment
))
1367 (custom-facep symbol
)
1368 (push (list symbol
'custom-face
) found
))
1369 (and (or (get symbol
'saved-value
)
1370 (get symbol
'saved-variable-comment
))
1372 (push (list symbol
'custom-variable
) found
))))
1374 (error "No saved user options")
1375 (custom-buffer-create (custom-sort-items found t nil
)
1376 "*Customize Saved*"))))
1379 (defun customize-apropos (regexp &optional all
)
1380 "Customize all loaded options, faces and groups matching REGEXP.
1381 If ALL is `options', include only options.
1382 If ALL is `faces', include only faces.
1383 If ALL is `groups', include only groups.
1384 If ALL is t (interactively, with prefix arg), include variables
1385 that are not customizable options, as well as faces and groups
1386 \(but we recommend using `apropos-variable' instead)."
1387 (interactive "sCustomize regexp: \nP")
1389 (mapatoms (lambda (symbol)
1390 (when (string-match regexp
(symbol-name symbol
))
1391 (when (and (not (memq all
'(faces options
)))
1392 (get symbol
'custom-group
))
1393 (push (list symbol
'custom-group
) found
))
1394 (when (and (not (memq all
'(options groups
)))
1395 (custom-facep symbol
))
1396 (push (list symbol
'custom-face
) found
))
1397 (when (and (not (memq all
'(groups faces
)))
1399 (eq (indirect-variable symbol
) symbol
)
1400 (or (get symbol
'saved-value
)
1401 (custom-variable-p symbol
)
1402 (and (not (memq all
'(nil options
)))
1403 (get symbol
'variable-documentation
))))
1404 (push (list symbol
'custom-variable
) found
)))))
1406 (error "No customizable items matching %s" regexp
)
1407 (custom-buffer-create
1408 (custom-sort-items found t custom-buffer-order-groups
)
1409 "*Customize Apropos*"))))
1412 (defun customize-apropos-options (regexp &optional arg
)
1413 "Customize all loaded customizable options matching REGEXP.
1414 With prefix arg, include variables that are not customizable options
1415 \(but we recommend using `apropos-variable' instead)."
1416 (interactive "sCustomize regexp: \nP")
1417 (customize-apropos regexp
(or arg
'options
)))
1420 (defun customize-apropos-faces (regexp)
1421 "Customize all loaded faces matching REGEXP."
1422 (interactive "sCustomize regexp: \n")
1423 (customize-apropos regexp
'faces
))
1426 (defun customize-apropos-groups (regexp)
1427 "Customize all loaded groups matching REGEXP."
1428 (interactive "sCustomize regexp: \n")
1429 (customize-apropos regexp
'groups
))
1433 (defcustom custom-buffer-style
'links
1434 "Control the presentation style for customization buffers.
1435 The value should be a symbol, one of:
1437 brackets: groups nest within each other with big horizontal brackets.
1438 links: groups have links to subgroups."
1439 :type
'(radio (const brackets
)
1441 :group
'custom-buffer
)
1443 (defcustom custom-buffer-done-kill nil
1444 "*Non-nil means exiting a Custom buffer should kill it."
1447 :group
'custom-buffer
)
1449 (defcustom custom-buffer-indent
3
1450 "Number of spaces to indent nested groups."
1452 :group
'custom-buffer
)
1454 (defun custom-get-fresh-buffer (name)
1455 "Get a fresh new buffer with name NAME.
1456 If the buffer already exist, clean it up to be like new.
1457 Beware: it's not quite like new. Good enough for custom, but maybe
1459 ;; To be more complete, we should also kill all permanent-local variables,
1460 ;; but it's not needed for custom.
1461 (let ((buf (get-buffer name
)))
1462 (when (and buf
(buffer-local-value 'buffer-file-name buf
))
1463 ;; This will check if the file is not saved.
1467 (get-buffer-create name
)
1468 (with-current-buffer buf
1469 (kill-all-local-variables)
1470 (run-hooks 'kill-buffer-hook
)
1471 ;; Delete overlays before erasing the buffer so the overlay hooks
1472 ;; don't get run spuriously when we erase the buffer.
1473 (let ((ols (overlay-lists)))
1474 (dolist (ol (nconc (car ols
) (cdr ols
)))
1475 (delete-overlay ol
)))
1480 (defun custom-buffer-create (options &optional name description
)
1481 "Create a buffer containing OPTIONS.
1482 Optional NAME is the name of the buffer.
1483 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1484 SYMBOL is a customization option, and WIDGET is a widget for editing
1486 (pop-to-buffer (custom-get-fresh-buffer (or name
"*Customization*")))
1487 (custom-buffer-create-internal options description
))
1490 (defun custom-buffer-create-other-window (options &optional name description
)
1491 "Create a buffer containing OPTIONS, and display it in another window.
1492 The result includes selecting that window.
1493 Optional NAME is the name of the buffer.
1494 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1495 SYMBOL is a customization option, and WIDGET is a widget for editing
1497 (unless name
(setq name
"*Customization*"))
1498 (let ((pop-up-windows t
)
1499 (same-window-buffer-names nil
)
1500 (same-window-regexps nil
))
1501 (pop-to-buffer (custom-get-fresh-buffer name
))
1502 (custom-buffer-create-internal options description
)))
1504 (defcustom custom-reset-button-menu nil
1505 "If non-nil, only show a single reset button in customize buffers.
1506 This button will have a menu with all three reset operations."
1508 :group
'custom-buffer
)
1510 (defcustom custom-buffer-verbose-help t
1511 "If non-nil, include explanatory text in the customization buffer."
1513 :group
'custom-buffer
)
1515 (defun Custom-buffer-done (&rest ignore
)
1516 "Exit current Custom buffer according to `custom-buffer-done-kill'."
1518 (quit-window custom-buffer-done-kill
))
1520 (defvar custom-button nil
1521 "Face used for buttons in customization buffers.")
1523 (defvar custom-button-mouse nil
1524 "Mouse face used for buttons in customization buffers.")
1526 (defvar custom-button-pressed nil
1527 "Face used for pressed buttons in customization buffers.")
1529 (defcustom custom-raised-buttons
(not (equal (face-valid-attribute-values :box
)
1530 '(("unspecified" . unspecified
))))
1531 "If non-nil, indicate active buttons in a `raised-button' style.
1532 Otherwise use brackets."
1535 :group
'custom-buffer
1536 :set
(lambda (variable value
)
1537 (custom-set-default variable value
)
1539 (if value
'custom-button
'custom-button-unraised
))
1540 (setq custom-button-mouse
1541 (if value
'custom-button-mouse
'highlight
))
1542 (setq custom-button-pressed
1544 'custom-button-pressed
1545 'custom-button-pressed-unraised
))))
1547 (defun custom-buffer-create-internal (options &optional description
)
1549 (if custom-buffer-verbose-help
1551 (widget-insert "This is a customization buffer")
1553 (widget-insert description
))
1554 (widget-insert (format ".
1555 %s buttons; type RET or click mouse-1 to actuate one.
1556 Editing a setting changes only the text in the buffer."
1557 (if custom-raised-buttons
1558 "`Raised' text indicates"
1559 "Square brackets indicate")))
1562 Use the setting's State button to set it or save changes in it.
1563 Saving a change normally works by editing your Emacs init file.")
1565 \nSince you started Emacs with `-q', which inhibits use of the
1566 Emacs init file, you cannot save settings into the Emacs init file."))
1567 (widget-insert "\nSee ")
1568 (widget-create 'custom-manual
1570 "(emacs)Saving Customizations")
1572 " for information on how to save in a different file.\n
1574 (widget-create 'custom-manual
1576 :help-echo
"Read the online help."
1577 "(emacs)Easy Customization")
1578 (widget-insert " for more information.\n\n")
1579 (widget-insert "Operate on all settings in this buffer that \
1580 are not marked HIDDEN:\n "))
1581 (widget-insert " "))
1582 (widget-create 'push-button
1583 :tag
"Set for Current Session"
1585 Make your editing in this buffer take effect for this session."
1586 :action
(lambda (widget &optional event
)
1588 (if (not custom-buffer-verbose-help
)
1591 (widget-create 'custom-manual
1593 :help-echo
"Read the online help."
1594 "(emacs)Easy Customization")))
1595 (when (or custom-file user-init-file
)
1597 (widget-create 'push-button
1598 :tag
"Save for Future Sessions"
1600 Make your editing in this buffer take effect for future Emacs sessions.
1601 This updates your Emacs initialization file or creates a new one."
1602 :action
(lambda (widget &optional event
)
1604 (if custom-reset-button-menu
1607 (widget-create 'push-button
1609 :help-echo
"Show a menu with reset operations."
1610 :mouse-down-action
(lambda (&rest junk
) t
)
1611 :action
(lambda (widget &optional event
)
1612 (custom-reset event
))))
1613 (widget-insert "\n ")
1614 (widget-create 'push-button
1617 Reset all edited text in this buffer to reflect current values."
1618 :action
'Custom-reset-current
)
1620 (widget-create 'push-button
1621 :tag
"Reset to Saved"
1623 Reset all settings in this buffer to their saved values."
1624 :action
'Custom-reset-saved
)
1626 (when (or custom-file user-init-file
)
1627 (widget-create 'push-button
1628 :tag
"Erase Customization"
1630 Un-customize all settings in this buffer and save them with standard values."
1631 :action
'Custom-reset-standard
)))
1633 (widget-create 'push-button
1636 (lambda (&rest ignore
)
1637 (if custom-buffer-done-kill
1639 "Bury this buffer"))
1640 :action
#'Custom-buffer-done
)
1641 (widget-insert "\n\n")
1642 (message "Creating customization items...")
1643 (buffer-disable-undo)
1644 (setq custom-options
1645 (if (= (length options
) 1)
1646 (mapcar (lambda (entry)
1647 (widget-create (nth 1 entry
)
1648 :documentation-shown t
1649 :custom-state
'unknown
1650 :tag
(custom-unlispify-tag-name
1652 :value
(nth 0 entry
)))
1655 (length (length options
)))
1656 (mapcar (lambda (entry)
1658 (message "Creating customization items ...%2d%%"
1659 (/ (* 100.0 count
) length
))
1660 (widget-create (nth 1 entry
)
1661 :tag
(custom-unlispify-tag-name
1663 :value
(nth 0 entry
))
1664 (setq count
(1+ count
))
1665 (unless (eq (preceding-char) ?
\n)
1666 (widget-insert "\n"))
1667 (widget-insert "\n")))
1669 (unless (eq (preceding-char) ?
\n)
1670 (widget-insert "\n"))
1671 (message "Creating customization items ...done")
1672 (message "Resetting customization items...")
1673 (unless (eq custom-buffer-style
'tree
)
1674 (mapc 'custom-magic-reset custom-options
))
1675 (message "Resetting customization items...done")
1676 (message "Creating customization setup...")
1678 (buffer-enable-undo)
1679 (goto-char (point-min))
1680 (message "Creating customization setup...done"))
1682 ;;; The Tree Browser.
1685 (defun customize-browse (&optional group
)
1686 "Create a tree browser for the customize hierarchy."
1689 (setq group
'emacs
))
1690 (let ((name "*Customize Browser*"))
1691 (pop-to-buffer (custom-get-fresh-buffer name
)))
1693 (widget-insert (format "\
1694 %s buttons; type RET or click mouse-1
1695 on a button to invoke its action.
1696 Invoke [+] to expand a group, and [-] to collapse an expanded group.\n"
1697 (if custom-raised-buttons
1698 "`Raised' text indicates"
1699 "Square brackets indicate")))
1702 (if custom-browse-only-groups
1704 Invoke the [Group] button below to edit that item in another window.\n\n")
1705 (widget-insert "Invoke the ")
1706 (widget-create 'item
1709 :tag-glyph
"folder")
1710 (widget-insert ", ")
1711 (widget-create 'item
1715 (widget-insert ", and ")
1716 (widget-create 'item
1719 :tag-glyph
"option")
1720 (widget-insert " buttons below to edit that
1721 item in another window.\n\n"))
1722 (let ((custom-buffer-style 'tree
))
1723 (widget-create 'custom-group
1725 :custom-state
'unknown
1726 :tag
(custom-unlispify-tag-name group
)
1729 (goto-char (point-min)))
1731 (define-widget 'custom-browse-visibility
'item
1732 "Control visibility of items in the customize tree browser."
1734 :action
'custom-browse-visibility-action
)
1736 (defun custom-browse-visibility-action (widget &rest ignore
)
1737 (let ((custom-buffer-style 'tree
))
1738 (custom-toggle-parent widget
)))
1740 (define-widget 'custom-browse-group-tag
'custom-group-link
1741 "Show parent in other window when activated."
1744 :action
'custom-browse-group-tag-action
)
1746 (defun custom-browse-group-tag-action (widget &rest ignore
)
1747 (let ((parent (widget-get widget
:parent
)))
1748 (customize-group-other-window (widget-value parent
))))
1750 (define-widget 'custom-browse-variable-tag
'custom-group-link
1751 "Show parent in other window when activated."
1754 :action
'custom-browse-variable-tag-action
)
1756 (defun custom-browse-variable-tag-action (widget &rest ignore
)
1757 (let ((parent (widget-get widget
:parent
)))
1758 (customize-variable-other-window (widget-value parent
))))
1760 (define-widget 'custom-browse-face-tag
'custom-group-link
1761 "Show parent in other window when activated."
1764 :action
'custom-browse-face-tag-action
)
1766 (defun custom-browse-face-tag-action (widget &rest ignore
)
1767 (let ((parent (widget-get widget
:parent
)))
1768 (customize-face-other-window (widget-value parent
))))
1770 (defconst custom-browse-alist
'((" " "space")
1776 (defun custom-browse-insert-prefix (prefix)
1777 "Insert PREFIX. On XEmacs convert it to line graphics."
1778 ;; Fixme: do graphics.
1779 (if nil
; (string-match "XEmacs" emacs-version)
1782 (while (not (string-equal prefix
""))
1783 (let ((entry (substring prefix
0 3)))
1784 (setq prefix
(substring prefix
3))
1785 (let ((overlay (make-overlay (1- (point)) (point) nil t nil
))
1786 (name (nth 1 (assoc entry custom-browse-alist
))))
1787 (overlay-put overlay
'end-glyph
(widget-glyph-find name entry
))
1788 (overlay-put overlay
'start-open t
)
1789 (overlay-put overlay
'end-open t
)))))
1792 ;;; Modification of Basic Widgets.
1794 ;; We add extra properties to the basic widgets needed here. This is
1795 ;; fine, as long as we are careful to stay within out own namespace.
1797 ;; We want simple widgets to be displayed by default, but complex
1798 ;; widgets to be hidden.
1800 (widget-put (get 'item
'widget-type
) :custom-show t
)
1801 (widget-put (get 'editable-field
'widget-type
)
1802 :custom-show
(lambda (widget value
)
1803 (let ((pp (pp-to-string value
)))
1804 (cond ((string-match "\n" pp
)
1809 (widget-put (get 'menu-choice
'widget-type
) :custom-show t
)
1811 ;;; The `custom-manual' Widget.
1813 (define-widget 'custom-manual
'info-link
1814 "Link to the manual entry for this customization option."
1815 :help-echo
"Read the manual entry for this option."
1816 :keymap custom-mode-link-map
1817 :follow-link
'mouse-face
1818 :button-face
'custom-link
1819 :mouse-face
'highlight
1820 :pressed-face
'highlight
1823 ;;; The `custom-magic' Widget.
1825 (defgroup custom-magic-faces nil
1826 "Faces used by the magic button."
1827 :group
'custom-faces
1828 :group
'custom-buffer
)
1830 (defface custom-invalid
'((((class color
))
1831 (:foreground
"yellow1" :background
"red1"))
1833 (:weight bold
:slant italic
:underline t
)))
1834 "Face used when the customize item is invalid."
1835 :group
'custom-magic-faces
)
1836 ;; backward-compatibility alias
1837 (put 'custom-invalid-face
'face-alias
'custom-invalid
)
1839 (defface custom-rogue
'((((class color
))
1840 (:foreground
"pink" :background
"black"))
1843 "Face used when the customize item is not defined for customization."
1844 :group
'custom-magic-faces
)
1845 ;; backward-compatibility alias
1846 (put 'custom-rogue-face
'face-alias
'custom-rogue
)
1848 (defface custom-modified
'((((min-colors 88) (class color
))
1849 (:foreground
"white" :background
"blue1"))
1851 (:foreground
"white" :background
"blue"))
1853 (:slant italic
:bold
)))
1854 "Face used when the customize item has been modified."
1855 :group
'custom-magic-faces
)
1856 ;; backward-compatibility alias
1857 (put 'custom-modified-face
'face-alias
'custom-modified
)
1859 (defface custom-set
'((((min-colors 88) (class color
))
1860 (:foreground
"blue1" :background
"white"))
1862 (:foreground
"blue" :background
"white"))
1865 "Face used when the customize item has been set."
1866 :group
'custom-magic-faces
)
1867 ;; backward-compatibility alias
1868 (put 'custom-set-face
'face-alias
'custom-set
)
1870 (defface custom-changed
'((((min-colors 88) (class color
))
1871 (:foreground
"white" :background
"blue1"))
1873 (:foreground
"white" :background
"blue"))
1876 "Face used when the customize item has been changed."
1877 :group
'custom-magic-faces
)
1878 ;; backward-compatibility alias
1879 (put 'custom-changed-face
'face-alias
'custom-changed
)
1881 (defface custom-themed
'((((min-colors 88) (class color
))
1882 (:foreground
"white" :background
"blue1"))
1884 (:foreground
"white" :background
"blue"))
1887 "Face used when the customize item has been set by a theme."
1888 :group
'custom-magic-faces
)
1890 (defface custom-saved
'((t (:underline t
)))
1891 "Face used when the customize item has been saved."
1892 :group
'custom-magic-faces
)
1893 ;; backward-compatibility alias
1894 (put 'custom-saved-face
'face-alias
'custom-saved
)
1896 (defconst custom-magic-alist
1897 '((nil "#" underline
"\
1898 UNINITIALIZED, you should not see this.")
1899 (unknown "?" italic
"\
1900 UNKNOWN, you should not see this.")
1901 (hidden "-" default
"\
1902 HIDDEN, invoke \"Show\" in the previous line to show." "\
1903 group now hidden, invoke \"Show\", above, to show contents.")
1904 (invalid "x" custom-invalid
"\
1905 INVALID, the displayed value cannot be set.")
1906 (modified "*" custom-modified
"\
1907 EDITED, shown value does not take effect until you set or save it." "\
1908 something in this group has been edited but not set.")
1909 (set "+" custom-set
"\
1910 SET for current session only." "\
1911 something in this group has been set but not saved.")
1912 (changed ":" custom-changed
"\
1913 CHANGED outside Customize; operating on it here may be unreliable." "\
1914 something in this group has been changed outside customize.")
1915 (saved "!" custom-saved
"\
1917 something in this group has been set and saved.")
1918 (themed "o" custom-themed
"\
1920 visible group members are all at standard values.")
1921 (rogue "@" custom-rogue
"\
1922 NO CUSTOMIZATION DATA; not intended to be customized." "\
1923 something in this group is not prepared for customization.")
1924 (standard " " nil
"\
1926 visible group members are all at standard values."))
1927 "Alist of customize option states.
1928 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1930 STATE is one of the following symbols:
1933 For internal use, should never occur.
1935 For internal use, should never occur.
1937 This item is not being displayed.
1939 This item is modified, but has an invalid form.
1941 This item is modified, and has a valid form.
1943 This item has been set but not saved.
1945 The current value of this item has been changed outside Customize.
1947 This item is marked for saving.
1949 This item has no customization information.
1951 This item is unchanged from the standard setting.
1953 MAGIC is a string used to present that state.
1955 FACE is a face used to present the state.
1957 ITEM-DESC is a string describing the state for options.
1959 GROUP-DESC is a string describing the state for groups. If this is
1960 left out, ITEM-DESC will be used.
1962 The string %c in either description will be replaced with the
1963 category of the item. These are `group'. `option', and `face'.
1965 The list should be sorted most significant first.")
1967 (defcustom custom-magic-show
'long
1968 "If non-nil, show textual description of the state.
1969 If `long', show a full-line description, not just one word."
1970 :type
'(choice (const :tag
"no" nil
)
1972 (other :tag
"short" short
))
1973 :group
'custom-buffer
)
1975 (defcustom custom-magic-show-hidden
'(option face
)
1976 "Control whether the State button is shown for hidden items.
1977 The value should be a list with the custom categories where the State
1978 button should be visible. Possible categories are `group', `option',
1980 :type
'(set (const group
) (const option
) (const face
))
1981 :group
'custom-buffer
)
1983 (defcustom custom-magic-show-button nil
1984 "Show a \"magic\" button indicating the state of each customization option."
1986 :group
'custom-buffer
)
1988 (define-widget 'custom-magic
'default
1989 "Show and manipulate state for a customization option."
1991 :action
'widget-parent-action
1994 :value-create
'custom-magic-value-create
1995 :value-delete
'widget-children-value-delete
)
1997 (defun widget-magic-mouse-down-action (widget &optional event
)
1998 ;; Non-nil unless hidden.
1999 (not (eq (widget-get (widget-get (widget-get widget
:parent
) :parent
)
2003 (defun custom-magic-value-create (widget)
2004 "Create compact status report for WIDGET."
2005 (let* ((parent (widget-get widget
:parent
))
2006 (state (widget-get parent
:custom-state
))
2007 (hidden (eq state
'hidden
))
2008 (entry (assq state custom-magic-alist
))
2009 (magic (nth 1 entry
))
2010 (face (nth 2 entry
))
2011 (category (widget-get parent
:custom-category
))
2012 (text (or (and (eq category
'group
)
2015 (form (widget-get parent
:custom-form
))
2017 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text
)
2018 (setq text
(concat (match-string 1 text
)
2019 (symbol-name category
)
2020 (match-string 2 text
))))
2021 (when (and custom-magic-show
2023 (memq category custom-magic-show-hidden
)))
2025 (when (and (eq category
'group
)
2026 (not (and (eq custom-buffer-style
'links
)
2027 (> (widget-get parent
:custom-level
) 1))))
2028 (insert-char ?\
(* custom-buffer-indent
2029 (widget-get parent
:custom-level
))))
2030 (push (widget-create-child-and-convert
2032 :help-echo
"Change the state of this item."
2033 :format
(if hidden
"%t" "%[%t%]")
2034 :button-prefix
'widget-push-button-prefix
2035 :button-suffix
'widget-push-button-suffix
2036 :mouse-down-action
'widget-magic-mouse-down-action
2040 (let ((start (point)))
2041 (if (eq custom-magic-show
'long
)
2043 (insert (symbol-name state
)))
2044 (cond ((eq form
'lisp
)
2046 ((eq form
'mismatch
)
2047 (insert " (mismatch)")))
2048 (put-text-property start
(point) 'face
'custom-state
))
2050 (when (and (eq category
'group
)
2051 (not (and (eq custom-buffer-style
'links
)
2052 (> (widget-get parent
:custom-level
) 1))))
2053 (insert-char ?\
(* custom-buffer-indent
2054 (widget-get parent
:custom-level
))))
2055 (when custom-magic-show-button
2056 (when custom-magic-show
2057 (let ((indent (widget-get parent
:indent
)))
2059 (insert-char ? indent
))))
2060 (push (widget-create-child-and-convert
2062 :mouse-down-action
'widget-magic-mouse-down-action
2066 :help-echo
"Change the state."
2067 :format
(if hidden
"%t" "%[%t%]")
2068 :tag
(if (memq form
'(lisp mismatch
))
2069 (concat "(" magic
")")
2070 (concat "[" magic
"]")))
2073 (widget-put widget
:children children
)))
2075 (defun custom-magic-reset (widget)
2076 "Redraw the :custom-magic property of WIDGET."
2077 (let ((magic (widget-get widget
:custom-magic
)))
2078 (widget-value-set magic
(widget-value magic
))))
2080 ;;; The `custom' Widget.
2082 (defface custom-button
2083 '((((type x w32 mac
) (class color
)) ; Like default modeline
2084 (:box
(:line-width
2 :style released-button
)
2085 :background
"lightgrey" :foreground
"black"))
2088 "Face for custom buffer buttons if `custom-raised-buttons' is non-nil."
2090 :group
'custom-faces
)
2091 ;; backward-compatibility alias
2092 (put 'custom-button-face
'face-alias
'custom-button
)
2094 (defface custom-button-mouse
2095 '((((type x w32 mac
) (class color
))
2096 (:box
(:line-width
2 :style released-button
)
2097 :background
"grey90" :foreground
"black"))
2100 "Mouse face for custom buffer buttons if `custom-raised-buttons' is non-nil."
2102 :group
'custom-faces
)
2104 (defface custom-button-unraised
2105 '((t :inherit underline
))
2106 "Face for custom buffer buttons if `custom-raised-buttons' is nil."
2108 :group
'custom-faces
)
2111 (if custom-raised-buttons
'custom-button
'custom-button-unraised
))
2113 (setq custom-button-mouse
2114 (if custom-raised-buttons
'custom-button-mouse
'highlight
))
2116 (defface custom-button-pressed
2117 '((((type x w32 mac
) (class color
))
2118 (:box
(:line-width
2 :style pressed-button
)
2119 :background
"lightgrey" :foreground
"black"))
2121 (:inverse-video t
)))
2122 "Face for pressed custom buttons if `custom-raised-buttons' is non-nil."
2124 :group
'custom-faces
)
2125 ;; backward-compatibility alias
2126 (put 'custom-button-pressed-face
'face-alias
'custom-button-pressed
)
2128 (defface custom-button-pressed-unraised
2129 '((default :inherit custom-button-unraised
)
2130 (((class color
) (background light
)) :foreground
"magenta4")
2131 (((class color
) (background dark
)) :foreground
"violet"))
2132 "Face for pressed custom buttons if `custom-raised-buttons' is nil."
2134 :group
'custom-faces
)
2136 (setq custom-button-pressed
2137 (if custom-raised-buttons
2138 'custom-button-pressed
2139 'custom-button-pressed-unraised
))
2141 (defface custom-documentation
'((t nil
))
2142 "Face used for documentation strings in customization buffers."
2143 :group
'custom-faces
)
2144 ;; backward-compatibility alias
2145 (put 'custom-documentation-face
'face-alias
'custom-documentation
)
2147 (defface custom-state
'((((class color
)
2149 (:foreground
"lime green"))
2152 (:foreground
"dark green"))
2154 "Face used for State descriptions in the customize buffer."
2155 :group
'custom-faces
)
2156 ;; backward-compatibility alias
2157 (put 'custom-state-face
'face-alias
'custom-state
)
2159 (defface custom-link
2160 '((t :inherit link
))
2161 "Face for links in customization buffers."
2163 :group
'custom-faces
)
2165 (define-widget 'custom
'default
2166 "Customize a user option."
2168 :convert-widget
'custom-convert-widget
2169 :notify
'custom-notify
2172 :custom-state
'hidden
2173 :documentation-property
'widget-subclass-responsibility
2174 :value-create
'widget-subclass-responsibility
2175 :value-delete
'widget-children-value-delete
2176 :value-get
'widget-value-value-get
2177 :validate
'widget-children-validate
2178 :match
(lambda (widget value
) (symbolp value
)))
2180 (defun custom-convert-widget (widget)
2181 "Initialize :value and :tag from :args in WIDGET."
2182 (let ((args (widget-get widget
:args
)))
2184 (widget-put widget
:value
(widget-apply widget
2185 :value-to-internal
(car args
)))
2186 (widget-put widget
:tag
(custom-unlispify-tag-name (car args
)))
2187 (widget-put widget
:args nil
)))
2190 (defun custom-notify (widget &rest args
)
2191 "Keep track of changes."
2192 (let ((state (widget-get widget
:custom-state
)))
2193 (unless (eq state
'modified
)
2194 (unless (memq state
'(nil unknown hidden
))
2195 (widget-put widget
:custom-state
'modified
))
2196 (custom-magic-reset widget
)
2197 (apply 'widget-default-notify widget args
))))
2199 (defun custom-redraw (widget)
2200 "Redraw WIDGET with current settings."
2201 (let ((line (count-lines (point-min) (point)))
2202 (column (current-column))
2204 (from (marker-position (widget-get widget
:from
)))
2205 (to (marker-position (widget-get widget
:to
))))
2207 (widget-value-set widget
(widget-value widget
))
2208 (custom-redraw-magic widget
))
2209 (when (and (>= pos from
) (<= pos to
))
2214 (goto-line (1+ line
)))
2215 (move-to-column column
))
2218 (defun custom-redraw-magic (widget)
2219 "Redraw WIDGET state with current settings."
2221 (let ((magic (widget-get widget
:custom-magic
)))
2223 (widget-value-set magic
(widget-value magic
))
2224 (when (setq widget
(widget-get widget
:group
))
2225 (custom-group-state-update widget
)))
2227 (setq widget nil
)))))
2230 (defun custom-show (widget value
)
2231 "Non-nil if WIDGET should be shown with VALUE by default."
2232 (let ((show (widget-get widget
:custom-show
)))
2238 (funcall show widget value
)))))
2240 (defun custom-load-widget (widget)
2241 "Load all dependencies for WIDGET."
2242 (custom-load-symbol (widget-value widget
)))
2244 (defun custom-unloaded-symbol-p (symbol)
2245 "Return non-nil if the dependencies of SYMBOL have not yet been loaded."
2247 (loads (get symbol
'custom-loads
))
2250 (setq load
(car loads
)
2252 (cond ((symbolp load
)
2253 (unless (featurep load
)
2255 ((assoc load load-history
))
2256 ((assoc (locate-library load
) load-history
)
2262 (defun custom-unloaded-widget-p (widget)
2263 "Return non-nil if the dependencies of WIDGET have not yet been loaded."
2264 (custom-unloaded-symbol-p (widget-value widget
)))
2266 (defun custom-toggle-hide (widget)
2267 "Toggle visibility of WIDGET."
2268 (custom-load-widget widget
)
2269 (let ((state (widget-get widget
:custom-state
)))
2270 (cond ((memq state
'(invalid modified
))
2271 (error "There are unset changes"))
2273 (widget-put widget
:custom-state
'unknown
))
2275 (widget-put widget
:documentation-shown nil
)
2276 (widget-put widget
:custom-state
'hidden
)))
2277 (custom-redraw widget
)
2280 (defun custom-toggle-parent (widget &rest ignore
)
2281 "Toggle visibility of parent of WIDGET."
2282 (custom-toggle-hide (widget-get widget
:parent
)))
2284 (defun custom-add-see-also (widget &optional prefix
)
2285 "Add `See also ...' to WIDGET if there are any links.
2286 Insert PREFIX first if non-nil."
2287 (let* ((symbol (widget-get widget
:value
))
2288 (links (get symbol
'custom-links
))
2289 (many (> (length links
) 2))
2290 (buttons (widget-get widget
:buttons
))
2291 (indent (widget-get widget
:indent
)))
2294 (insert-char ?\ indent
))
2297 (insert "See also ")
2299 (push (widget-create-child-and-convert
2301 :button-face
'custom-link
2302 :mouse-face
'highlight
2303 :pressed-face
'highlight
)
2305 (setq links
(cdr links
))
2314 (widget-put widget
:buttons buttons
))))
2316 (defun custom-add-parent-links (widget &optional initial-string
)
2317 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
2318 The value is non-nil if any parents were found.
2319 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
2320 (let ((name (widget-value widget
))
2321 (type (widget-type widget
))
2322 (buttons (widget-get widget
:buttons
))
2325 (insert (or initial-string
"Parent groups:"))
2326 (mapatoms (lambda (symbol)
2327 (when (member (list name type
) (get symbol
'custom-group
))
2329 (push (widget-create-child-and-convert
2330 widget
'custom-group-link
2331 :tag
(custom-unlispify-tag-name symbol
)
2334 (setq parents
(cons symbol parents
)))))
2335 (and (null (get name
'custom-links
)) ;No links of its own.
2336 (= (length parents
) 1) ;A single parent.
2337 (let* ((links (delq nil
(mapcar (lambda (w)
2338 (unless (eq (widget-type w
)
2341 (get (car parents
) 'custom-links
))))
2342 (many (> (length links
) 2)))
2344 (insert "\nParent documentation: ")
2346 (push (widget-create-child-and-convert
2348 :button-face
'custom-link
2349 :mouse-face
'highlight
2350 :pressed-face
'highlight
)
2352 (setq links
(cdr links
))
2363 (delete-region start
(point)))
2364 (widget-put widget
:buttons buttons
)
2367 ;;; The `custom-comment' Widget.
2369 ;; like the editable field
2370 (defface custom-comment
'((((type tty
))
2371 :background
"yellow3"
2372 :foreground
"black")
2373 (((class grayscale color
)
2375 :background
"gray85")
2376 (((class grayscale color
)
2378 :background
"dim gray")
2381 "Face used for comments on variables or faces"
2383 :group
'custom-faces
)
2384 ;; backward-compatibility alias
2385 (put 'custom-comment-face
'face-alias
'custom-comment
)
2387 ;; like font-lock-comment-face
2388 (defface custom-comment-tag
2389 '((((class color
) (background dark
)) (:foreground
"gray80"))
2390 (((class color
) (background light
)) (:foreground
"blue4"))
2391 (((class grayscale
) (background light
))
2392 (:foreground
"DimGray" :weight bold
:slant italic
))
2393 (((class grayscale
) (background dark
))
2394 (:foreground
"LightGray" :weight bold
:slant italic
))
2396 "Face used for variables or faces comment tags"
2397 :group
'custom-faces
)
2398 ;; backward-compatibility alias
2399 (put 'custom-comment-tag-face
'face-alias
'custom-comment-tag
)
2401 (define-widget 'custom-comment
'string
2404 :help-echo
"Edit a comment here."
2405 :sample-face
'custom-comment-tag-face
2406 :value-face
'custom-comment-face
2408 :create
'custom-comment-create
)
2410 (defun custom-comment-create (widget)
2411 (let* ((null-comment (equal "" (widget-value widget
))))
2412 (if (or (widget-get (widget-get widget
:parent
) :comment-shown
)
2414 (widget-default-create widget
)
2415 ;; `widget-default-delete' expects markers in these slots --
2416 ;; maybe it shouldn't.
2417 (widget-put widget
:from
(point-marker))
2418 (widget-put widget
:to
(point-marker)))))
2420 (defun custom-comment-hide (widget)
2421 (widget-put (widget-get widget
:parent
) :comment-shown nil
))
2423 ;; Those functions are for the menu. WIDGET is NOT the comment widget. It's
2424 ;; the global custom one
2425 (defun custom-comment-show (widget)
2426 (widget-put widget
:comment-shown t
)
2427 (custom-redraw widget
)
2430 (defun custom-comment-invisible-p (widget)
2431 (let ((val (widget-value (widget-get widget
:comment-widget
))))
2433 (not (widget-get widget
:comment-shown
)))))
2435 ;;; The `custom-variable' Widget.
2437 ;; When this was underlined blue, users confused it with a
2438 ;; Mosaic-style hyperlink...
2439 (defface custom-variable-tag
2442 (:foreground
"light blue" :weight bold
:height
1.2 :inherit variable-pitch
))
2443 (((min-colors 88) (class color
)
2445 (:foreground
"blue1" :weight bold
:height
1.2 :inherit variable-pitch
))
2448 (:foreground
"blue" :weight bold
:height
1.2 :inherit variable-pitch
))
2450 "Face used for unpushable variable tags."
2451 :group
'custom-faces
)
2452 ;; backward-compatibility alias
2453 (put 'custom-variable-tag-face
'face-alias
'custom-variable-tag
)
2455 (defface custom-variable-button
'((t (:underline t
:weight bold
)))
2456 "Face used for pushable variable tags."
2457 :group
'custom-faces
)
2458 ;; backward-compatibility alias
2459 (put 'custom-variable-button-face
'face-alias
'custom-variable-button
)
2461 (defcustom custom-variable-default-form
'edit
2462 "Default form of displaying variable values."
2463 :type
'(choice (const edit
)
2465 :group
'custom-buffer
2468 (defun custom-variable-documentation (variable)
2469 "Return documentation of VARIABLE for use in Custom buffer.
2470 Normally just return the docstring. But if VARIABLE automatically
2471 becomes buffer local when set, append a message to that effect."
2472 (if (and (local-variable-if-set-p variable
)
2473 (or (not (local-variable-p variable
))
2475 (local-variable-if-set-p variable
))))
2476 (concat (documentation-property variable
'variable-documentation
)
2478 This variable automatically becomes buffer-local when set outside Custom.
2479 However, setting it through Custom sets the default value.")
2480 (documentation-property variable
'variable-documentation
)))
2482 (define-widget 'custom-variable
'custom
2483 "Customize variable."
2485 :help-echo
"Set or reset this variable."
2486 :documentation-property
#'custom-variable-documentation
2487 :custom-category
'option
2489 :custom-menu
'custom-variable-menu-create
2490 :custom-form nil
; defaults to value of `custom-variable-default-form'
2491 :value-create
'custom-variable-value-create
2492 :action
'custom-variable-action
2493 :custom-set
'custom-variable-set
2494 :custom-save
'custom-variable-save
2495 :custom-reset-current
'custom-redraw
2496 :custom-reset-saved
'custom-variable-reset-saved
2497 :custom-reset-standard
'custom-variable-reset-standard
2498 :custom-standard-value
'custom-variable-standard-value
)
2500 (defun custom-variable-type (symbol)
2501 "Return a widget suitable for editing the value of SYMBOL.
2502 If SYMBOL has a `custom-type' property, use that.
2503 Otherwise, try matching SYMBOL against `custom-guess-name-alist' and
2504 try matching its doc string against `custom-guess-doc-alist'."
2505 (let* ((type (or (get symbol
'custom-type
)
2506 (and (not (get symbol
'standard-value
))
2507 (custom-guess-type symbol
))
2509 (options (get symbol
'custom-options
))
2510 (tmp (if (listp type
)
2511 (copy-sequence type
)
2514 (widget-put tmp
:options options
))
2517 (defun custom-variable-value-create (widget)
2518 "Here is where you edit the variable's value."
2519 (custom-load-widget widget
)
2520 (unless (widget-get widget
:custom-form
)
2521 (widget-put widget
:custom-form custom-variable-default-form
))
2522 (let* ((buttons (widget-get widget
:buttons
))
2523 (children (widget-get widget
:children
))
2524 (form (widget-get widget
:custom-form
))
2525 (state (widget-get widget
:custom-state
))
2526 (symbol (widget-get widget
:value
))
2527 (tag (widget-get widget
:tag
))
2528 (type (custom-variable-type symbol
))
2529 (conv (widget-convert type
))
2530 (get (or (get symbol
'custom-get
) 'default-value
))
2531 (prefix (widget-get widget
:custom-prefix
))
2532 (last (widget-get widget
:custom-last
))
2533 (value (if (default-boundp symbol
)
2534 (funcall get symbol
)
2535 (widget-get conv
:value
))))
2536 ;; If the widget is new, the child determines whether it is hidden.
2538 ((custom-show type value
)
2539 (setq state
'unknown
))
2541 (setq state
'hidden
)))
2542 ;; If we don't know the state, see if we need to edit it in lisp form.
2543 (when (eq state
'unknown
)
2544 (unless (widget-apply conv
:match value
)
2545 ;; (widget-apply (widget-convert type) :match value)
2546 (setq form
'mismatch
)))
2547 ;; Now we can create the child widget.
2548 (cond ((eq custom-buffer-style
'tree
)
2549 (insert prefix
(if last
" `--- " " |--- "))
2550 (push (widget-create-child-and-convert
2551 widget
'custom-browse-variable-tag
)
2553 (insert " " tag
"\n")
2554 (widget-put widget
:buttons buttons
))
2556 ;; Indicate hidden value.
2557 (push (widget-create-child-and-convert
2560 :sample-face
'custom-variable-tag-face
2564 (push (widget-create-child-and-convert
2566 :help-echo
"Show the value of this option."
2568 :action
'custom-toggle-parent
2571 ((memq form
'(lisp mismatch
))
2572 ;; In lisp mode edit the saved value when possible.
2573 (let* ((value (cond ((get symbol
'saved-value
)
2574 (car (get symbol
'saved-value
)))
2575 ((get symbol
'standard-value
)
2576 (car (get symbol
'standard-value
)))
2577 ((default-boundp symbol
)
2578 (custom-quote (funcall get symbol
)))
2580 (custom-quote (widget-get conv
:value
))))))
2581 (insert (symbol-name symbol
) ": ")
2582 (push (widget-create-child-and-convert
2584 :help-echo
"Hide the value of this option."
2587 :action
'custom-toggle-parent
2591 (push (widget-create-child-and-convert
2593 :button-face
'custom-variable-button-face
2595 :tag
(symbol-name symbol
)
2601 (let* ((format (widget-get type
:format
))
2602 tag-format value-format
)
2603 (unless (string-match ":" format
)
2604 (error "Bad format"))
2605 (setq tag-format
(substring format
0 (match-end 0)))
2606 (setq value-format
(substring format
(match-end 0)))
2607 (push (widget-create-child-and-convert
2610 :action
'custom-tag-action
2611 :help-echo
"Change value of this option."
2612 :mouse-down-action
'custom-tag-mouse-down-action
2613 :button-face
'custom-variable-button-face
2614 :sample-face
'custom-variable-tag-face
2618 (push (widget-create-child-and-convert
2620 :help-echo
"Hide the value of this option."
2623 :action
'custom-toggle-parent
2626 (push (widget-create-child-and-convert
2628 :format value-format
2631 (unless (eq custom-buffer-style
'tree
)
2632 (unless (eq (preceding-char) ?
\n)
2633 (widget-insert "\n"))
2634 ;; Create the magic button.
2635 (let ((magic (widget-create-child-and-convert
2636 widget
'custom-magic nil
)))
2637 (widget-put widget
:custom-magic magic
)
2638 (push magic buttons
))
2639 ;; ### NOTE: this is ugly!!!! I need to update the :buttons property
2640 ;; before the call to `widget-default-format-handler'. Otherwise, I
2641 ;; loose my current `buttons'. This function shouldn't be called like
2642 ;; this anyway. The doc string widget should be added like the others.
2644 (widget-put widget
:buttons buttons
)
2646 ;; Insert documentation.
2647 (widget-default-format-handler widget ?h
)
2649 ;; The comment field
2650 (unless (eq state
'hidden
)
2651 (let* ((comment (get symbol
'variable-comment
))
2653 (widget-create-child-and-convert
2654 widget
'custom-comment
2656 :value
(or comment
""))))
2657 (widget-put widget
:comment-widget comment-widget
)
2658 ;; Don't push it !!! Custom assumes that the first child is the
2660 (setq children
(append children
(list comment-widget
)))))
2661 ;; Update the rest of the properties properties.
2662 (widget-put widget
:custom-form form
)
2663 (widget-put widget
:children children
)
2664 ;; Now update the state.
2665 (if (eq state
'hidden
)
2666 (widget-put widget
:custom-state state
)
2667 (custom-variable-state-set widget
))
2669 (unless (eq state
'hidden
)
2670 (when (eq (widget-get widget
:custom-level
) 1)
2671 (custom-add-parent-links widget
))
2672 (custom-add-see-also widget
)))))
2674 (defun custom-tag-action (widget &rest args
)
2675 "Pass :action to first child of WIDGET's parent."
2676 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2679 (defun custom-tag-mouse-down-action (widget &rest args
)
2680 "Pass :mouse-down-action to first child of WIDGET's parent."
2681 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2682 :mouse-down-action args
))
2684 (defun custom-variable-state-set (widget)
2685 "Set the state of WIDGET."
2686 (let* ((symbol (widget-value widget
))
2687 (get (or (get symbol
'custom-get
) 'default-value
))
2688 (value (if (default-boundp symbol
)
2689 (funcall get symbol
)
2690 (widget-get widget
:value
)))
2691 (comment (get symbol
'variable-comment
))
2694 (state (cond ((progn (setq tmp
(get symbol
'customized-value
))
2696 (get symbol
'customized-variable-comment
))
2698 (if (condition-case nil
2699 (and (equal value
(eval (car tmp
)))
2700 (equal comment temp
))
2704 ((progn (setq tmp
(get symbol
'theme-value
))
2705 (setq temp
(get symbol
'saved-variable-comment
))
2707 (if (condition-case nil
2708 (and (equal comment temp
)
2711 (car (custom-variable-theme-value
2715 ((eq (caar tmp
) 'user
) 'saved
)
2716 ((eq (caar tmp
) 'changed
)
2717 (if (condition-case nil
2721 (car (get symbol
'standard-value
)))))
2723 ;; The value was originally set outside
2724 ;; custom, but it was set to the standard
2725 ;; value (probably an autoloaded defcustom).
2730 ((setq tmp
(get symbol
'standard-value
))
2731 (if (condition-case nil
2732 (and (equal value
(eval (car tmp
)))
2733 (equal comment nil
))
2738 (widget-put widget
:custom-state state
)))
2740 (defun custom-variable-standard-value (widget)
2741 (get (widget-value widget
) 'standard-value
))
2743 (defvar custom-variable-menu
2744 `(("Set for Current Session" custom-variable-set
2746 (eq (widget-get widget
:custom-state
) 'modified
)))
2747 ,@(when (or custom-file user-init-file
)
2748 '(("Save for Future Sessions" custom-variable-save
2750 (memq (widget-get widget
:custom-state
)
2751 '(modified set changed rogue
))))))
2752 ("Undo Edits" custom-redraw
2754 (and (default-boundp (widget-value widget
))
2755 (memq (widget-get widget
:custom-state
) '(modified changed
)))))
2756 ("Reset to Saved" custom-variable-reset-saved
2758 (and (or (get (widget-value widget
) 'saved-value
)
2759 (get (widget-value widget
) 'saved-variable-comment
))
2760 (memq (widget-get widget
:custom-state
)
2761 '(modified set changed rogue
)))))
2762 ,@(when (or custom-file user-init-file
)
2763 '(("Erase Customization" custom-variable-reset-standard
2765 (and (get (widget-value widget
) 'standard-value
)
2766 (memq (widget-get widget
:custom-state
)
2767 '(modified set changed saved rogue
)))))))
2768 ("Set to Backup Value" custom-variable-reset-backup
2770 (get (widget-value widget
) 'backup-value
)))
2771 ("---" ignore ignore
)
2772 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
2773 ("---" ignore ignore
)
2774 ("Show Current Value" custom-variable-edit
2776 (eq (widget-get widget
:custom-form
) 'lisp
)))
2777 ("Show Saved Lisp Expression" custom-variable-edit-lisp
2779 (eq (widget-get widget
:custom-form
) 'edit
))))
2780 "Alist of actions for the `custom-variable' widget.
2781 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2782 the menu entry, ACTION is the function to call on the widget when the
2783 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2784 widget as an argument, and returns non-nil if ACTION is valid on that
2785 widget. If FILTER is nil, ACTION is always valid.")
2787 (defun custom-variable-action (widget &optional event
)
2788 "Show the menu for `custom-variable' WIDGET.
2789 Optional EVENT is the location for the menu."
2790 (if (eq (widget-get widget
:custom-state
) 'hidden
)
2791 (custom-toggle-hide widget
)
2792 (unless (eq (widget-get widget
:custom-state
) 'modified
)
2793 (custom-variable-state-set widget
))
2794 (custom-redraw-magic widget
)
2795 (let* ((completion-ignore-case t
)
2796 (answer (widget-choose (concat "Operation on "
2797 (custom-unlispify-tag-name
2798 (widget-get widget
:value
)))
2799 (custom-menu-filter custom-variable-menu
2803 (funcall answer widget
)))))
2805 (defun custom-variable-edit (widget)
2806 "Edit value of WIDGET."
2807 (widget-put widget
:custom-state
'unknown
)
2808 (widget-put widget
:custom-form
'edit
)
2809 (custom-redraw widget
))
2811 (defun custom-variable-edit-lisp (widget)
2812 "Edit the Lisp representation of the value of WIDGET."
2813 (widget-put widget
:custom-state
'unknown
)
2814 (widget-put widget
:custom-form
'lisp
)
2815 (custom-redraw widget
))
2817 (defun custom-variable-set (widget)
2818 "Set the current value for the variable being edited by WIDGET."
2819 (let* ((form (widget-get widget
:custom-form
))
2820 (state (widget-get widget
:custom-state
))
2821 (child (car (widget-get widget
:children
)))
2822 (symbol (widget-value widget
))
2823 (set (or (get symbol
'custom-set
) 'set-default
))
2824 (comment-widget (widget-get widget
:comment-widget
))
2825 (comment (widget-value comment-widget
))
2827 (cond ((eq state
'hidden
)
2828 (error "Cannot set hidden variable"))
2829 ((setq val
(widget-apply child
:validate
))
2830 (goto-char (widget-get val
:from
))
2831 (error "%s" (widget-get val
:error
)))
2832 ((memq form
'(lisp mismatch
))
2833 (when (equal comment
"")
2835 ;; Make the comment invisible by hand if it's empty
2836 (custom-comment-hide comment-widget
))
2837 (custom-variable-backup-value widget
)
2838 (custom-push-theme 'theme-value symbol
'user
2839 'set
(custom-quote (widget-value child
)))
2840 (funcall set symbol
(eval (setq val
(widget-value child
))))
2841 (put symbol
'customized-value
(list val
))
2842 (put symbol
'variable-comment comment
)
2843 (put symbol
'customized-variable-comment comment
))
2845 (when (equal comment
"")
2847 ;; Make the comment invisible by hand if it's empty
2848 (custom-comment-hide comment-widget
))
2849 (custom-variable-backup-value widget
)
2850 (custom-push-theme 'theme-value symbol
'user
2851 'set
(custom-quote (widget-value child
)))
2852 (funcall set symbol
(setq val
(widget-value child
)))
2853 (put symbol
'customized-value
(list (custom-quote val
)))
2854 (put symbol
'variable-comment comment
)
2855 (put symbol
'customized-variable-comment comment
)))
2856 (custom-variable-state-set widget
)
2857 (custom-redraw-magic widget
)))
2859 (defun custom-variable-save (widget)
2860 "Set and save the value for the variable being edited by WIDGET."
2861 (let* ((form (widget-get widget
:custom-form
))
2862 (state (widget-get widget
:custom-state
))
2863 (child (car (widget-get widget
:children
)))
2864 (symbol (widget-value widget
))
2865 (set (or (get symbol
'custom-set
) 'set-default
))
2866 (comment-widget (widget-get widget
:comment-widget
))
2867 (comment (widget-value comment-widget
))
2869 (cond ((eq state
'hidden
)
2870 (error "Cannot set hidden variable"))
2871 ((setq val
(widget-apply child
:validate
))
2872 (goto-char (widget-get val
:from
))
2873 (error "Saving %s: %s" symbol
(widget-get val
:error
)))
2874 ((memq form
'(lisp mismatch
))
2875 (when (equal comment
"")
2877 ;; Make the comment invisible by hand if it's empty
2878 (custom-comment-hide comment-widget
))
2879 (put symbol
'saved-value
(list (widget-value child
)))
2880 (custom-push-theme 'theme-value symbol
'user
2881 'set
(custom-quote (widget-value child
)))
2882 (funcall set symbol
(eval (widget-value child
)))
2883 (put symbol
'variable-comment comment
)
2884 (put symbol
'saved-variable-comment comment
))
2886 (when (equal comment
"")
2888 ;; Make the comment invisible by hand if it's empty
2889 (custom-comment-hide comment-widget
))
2890 (put symbol
'saved-value
2891 (list (custom-quote (widget-value child
))))
2892 (custom-push-theme 'theme-value symbol
'user
2893 'set
(custom-quote (widget-value child
)))
2894 (funcall set symbol
(widget-value child
))
2895 (put symbol
'variable-comment comment
)
2896 (put symbol
'saved-variable-comment comment
)))
2897 (put symbol
'customized-value nil
)
2898 (put symbol
'customized-variable-comment nil
)
2900 (custom-variable-state-set widget
)
2901 (custom-redraw-magic widget
)))
2903 (defun custom-variable-reset-saved (widget)
2904 "Restore the saved value for the variable being edited by WIDGET.
2905 This also updates the buffer to show that value.
2906 The value that was current before this operation
2907 becomes the backup value, so you can get it again."
2908 (let* ((symbol (widget-value widget
))
2909 (set (or (get symbol
'custom-set
) 'set-default
))
2910 (value (get symbol
'saved-value
))
2911 (comment (get symbol
'saved-variable-comment
)))
2912 (cond ((or value comment
)
2913 (put symbol
'variable-comment comment
)
2914 (custom-variable-backup-value widget
)
2915 (custom-push-theme 'theme-value symbol
'user
'set
(car-safe value
))
2917 (funcall set symbol
(eval (car value
)))
2920 (error "No saved value for %s" symbol
)))
2921 (put symbol
'customized-value nil
)
2922 (put symbol
'customized-variable-comment nil
)
2923 (widget-put widget
:custom-state
'unknown
)
2924 ;; This call will possibly make the comment invisible
2925 (custom-redraw widget
)))
2927 (defun custom-variable-reset-standard (widget)
2928 "Restore the standard setting for the variable being edited by WIDGET.
2929 This operation eliminates any saved setting for the variable,
2930 restoring it to the state of a variable that has never been customized.
2931 The value that was current before this operation
2932 becomes the backup value, so you can get it again."
2933 (let* ((symbol (widget-value widget
)))
2934 (if (get symbol
'standard-value
)
2935 (custom-variable-backup-value widget
)
2936 (error "No standard setting known for %S" symbol
))
2937 (put symbol
'variable-comment nil
)
2938 (put symbol
'customized-value nil
)
2939 (put symbol
'customized-variable-comment nil
)
2940 (custom-push-theme 'theme-value symbol
'user
'reset
)
2941 (custom-theme-recalc-variable symbol
)
2942 (when (or (get symbol
'saved-value
) (get symbol
'saved-variable-comment
))
2943 (put symbol
'saved-value nil
)
2944 (put symbol
'saved-variable-comment nil
)
2946 (widget-put widget
:custom-state
'unknown
)
2947 ;; This call will possibly make the comment invisible
2948 (custom-redraw widget
)))
2950 (defun custom-variable-backup-value (widget)
2951 "Back up the current value for WIDGET's variable.
2952 The backup value is kept in the car of the `backup-value' property."
2953 (let* ((symbol (widget-value widget
))
2954 (get (or (get symbol
'custom-get
) 'default-value
))
2955 (type (custom-variable-type symbol
))
2956 (conv (widget-convert type
))
2957 (value (if (default-boundp symbol
)
2958 (funcall get symbol
)
2959 (widget-get conv
:value
))))
2960 (put symbol
'backup-value
(list value
))))
2962 (defun custom-variable-reset-backup (widget)
2963 "Restore the backup value for the variable being edited by WIDGET.
2964 The value that was current before this operation
2965 becomes the backup value, so you can use this operation repeatedly
2966 to switch between two values."
2967 (let* ((symbol (widget-value widget
))
2968 (set (or (get symbol
'custom-set
) 'set-default
))
2969 (value (get symbol
'backup-value
))
2970 (comment-widget (widget-get widget
:comment-widget
))
2971 (comment (widget-value comment-widget
)))
2974 (custom-variable-backup-value widget
)
2975 (custom-push-theme 'theme-value symbol
'user
'set value
)
2977 (funcall set symbol
(car value
))
2979 (error "No backup value for %s" symbol
))
2980 (put symbol
'customized-value
(list (car value
)))
2981 (put symbol
'variable-comment comment
)
2982 (put symbol
'customized-variable-comment comment
)
2983 (custom-variable-state-set widget
)
2984 ;; This call will possibly make the comment invisible
2985 (custom-redraw widget
)))
2987 ;;; The `custom-face-edit' Widget.
2989 (define-widget 'custom-face-edit
'checklist
2990 "Edit face attributes."
2994 :button-args
'(:help-echo
"Control whether this attribute has any effect.")
2995 :value-to-internal
'custom-face-edit-fix-value
2996 :match
(lambda (widget value
)
2997 (widget-checklist-match widget
2998 (custom-face-edit-fix-value widget value
)))
2999 :convert-widget
'custom-face-edit-convert-widget
3000 :args
(mapcar (lambda (att)
3003 :sibling-args
(widget-get (nth 1 att
) :sibling-args
)
3004 (list 'const
:format
"" :value
(nth 0 att
))
3006 custom-face-attributes
))
3008 (defun custom-face-edit-fix-value (widget value
)
3009 "Ignoring WIDGET, convert :bold and :italic in VALUE to new form.
3010 Also change :reverse-video to :inverse-video."
3014 (let ((key (car value
))
3015 (val (car (cdr value
))))
3016 (cond ((eq key
:italic
)
3017 (push :slant result
)
3018 (push (if val
'italic
'normal
) result
))
3020 (push :weight result
)
3021 (push (if val
'bold
'normal
) result
))
3022 ((eq key
:reverse-video
)
3023 (push :inverse-video result
)
3027 (push val result
))))
3028 (setq value
(cdr (cdr value
))))
3029 (setq result
(nreverse result
))
3033 (defun custom-face-edit-convert-widget (widget)
3034 "Convert :args as widget types in WIDGET."
3037 :args
(mapcar (lambda (arg)
3039 :deactivate
'custom-face-edit-deactivate
3040 :activate
'custom-face-edit-activate
3041 :delete
'custom-face-edit-delete
))
3042 (widget-get widget
:args
)))
3045 (defun custom-face-edit-deactivate (widget)
3046 "Make face widget WIDGET inactive for user modifications."
3047 (unless (widget-get widget
:inactive
)
3048 (let ((tag (custom-face-edit-attribute-tag widget
))
3049 (from (copy-marker (widget-get widget
:from
)))
3050 (value (widget-value widget
))
3051 (inhibit-read-only t
)
3052 (inhibit-modification-hooks t
))
3055 (widget-default-delete widget
)
3056 (insert tag
": *\n")
3057 (widget-put widget
:inactive
3058 (cons value
(cons from
(- (point) from
))))))))
3060 (defun custom-face-edit-activate (widget)
3061 "Make face widget WIDGET inactive for user modifications."
3062 (let ((inactive (widget-get widget
:inactive
))
3063 (inhibit-read-only t
)
3064 (inhibit-modification-hooks t
))
3065 (when (consp inactive
)
3067 (goto-char (car (cdr inactive
)))
3068 (delete-region (point) (+ (point) (cdr (cdr inactive
))))
3069 (widget-put widget
:inactive nil
)
3070 (widget-apply widget
:create
)
3071 (widget-value-set widget
(car inactive
))
3074 (defun custom-face-edit-delete (widget)
3075 "Remove WIDGET from the buffer."
3076 (let ((inactive (widget-get widget
:inactive
))
3077 (inhibit-read-only t
)
3078 (inhibit-modification-hooks t
))
3080 ;; Widget is alive, we don't have to do anything special
3081 (widget-default-delete widget
)
3082 ;; WIDGET is already deleted because we did so to inactivate it;
3083 ;; now just get rid of the label we put in its place.
3084 (delete-region (car (cdr inactive
))
3085 (+ (car (cdr inactive
)) (cdr (cdr inactive
))))
3086 (widget-put widget
:inactive nil
))))
3089 (defun custom-face-edit-attribute-tag (widget)
3090 "Returns the first :tag property in WIDGET or one of its children."
3091 (let ((tag (widget-get widget
:tag
)))
3092 (or (and (not (equal tag
"")) tag
)
3093 (let ((children (widget-get widget
:children
)))
3094 (while (and (null tag
) children
)
3095 (setq tag
(custom-face-edit-attribute-tag (pop children
))))
3098 ;;; The `custom-display' Widget.
3100 (define-widget 'custom-display
'menu-choice
3101 "Select a display type."
3104 :help-echo
"Specify frames where the face attributes should be used."
3105 :args
'((const :tag
"all" t
)
3106 (const :tag
"defaults" default
)
3110 :args
((group :sibling-args
(:help-echo
"\
3111 Only match the specified window systems.")
3112 (const :format
"Type: "
3114 (checklist :inline t
3117 :sibling-args
(:help-echo
"\
3118 The X11 Window System.")
3120 (const :format
"PM "
3121 :sibling-args
(:help-echo
"\
3122 OS/2 Presentation Manager.")
3124 (const :format
"W32 "
3125 :sibling-args
(:help-echo
"\
3128 (const :format
"MAC "
3129 :sibling-args
(:help-echo
"\
3132 (const :format
"DOS "
3133 :sibling-args
(:help-echo
"\
3136 (const :format
"TTY%n"
3137 :sibling-args
(:help-echo
"\
3138 Plain text terminals.")
3140 (group :sibling-args
(:help-echo
"\
3141 Only match the frames with the specified color support.")
3142 (const :format
"Class: "
3144 (checklist :inline t
3146 (const :format
"Color "
3147 :sibling-args
(:help-echo
"\
3148 Match color frames.")
3150 (const :format
"Grayscale "
3151 :sibling-args
(:help-echo
"\
3152 Match grayscale frames.")
3154 (const :format
"Monochrome%n"
3155 :sibling-args
(:help-echo
"\
3156 Match frames with no color support.")
3158 (group :sibling-args
(:help-echo
"\
3159 The minimum number of colors the frame should support.")
3160 (const :format
"" min-colors
)
3161 (integer :tag
"Minimum number of colors" ))
3162 (group :sibling-args
(:help-echo
"\
3163 Only match frames with the specified intensity.")
3165 Background brightness: "
3167 (checklist :inline t
3169 (const :format
"Light "
3170 :sibling-args
(:help-echo
"\
3171 Match frames with light backgrounds.")
3173 (const :format
"Dark\n"
3174 :sibling-args
(:help-echo
"\
3175 Match frames with dark backgrounds.")
3177 (group :sibling-args
(:help-echo
"\
3178 Only match frames that support the specified face attributes.")
3179 (const :format
"Supports attributes:" supports
)
3180 (custom-face-edit :inline t
:format
"%n%v"))))))
3182 ;;; The `custom-face' Widget.
3184 (defface custom-face-tag
3185 `((t (:weight bold
:height
1.2 :inherit variable-pitch
)))
3186 "Face used for face tags."
3187 :group
'custom-faces
)
3188 ;; backward-compatibility alias
3189 (put 'custom-face-tag-face
'face-alias
'custom-face-tag
)
3191 (defcustom custom-face-default-form
'selected
3192 "Default form of displaying face definition."
3193 :type
'(choice (const all
)
3196 :group
'custom-buffer
3199 (define-widget 'custom-face
'custom
3201 :sample-face
'custom-face-tag-face
3202 :help-echo
"Set or reset this face."
3203 :documentation-property
#'face-doc-string
3204 :value-create
'custom-face-value-create
3205 :action
'custom-face-action
3206 :custom-category
'face
3207 :custom-form nil
; defaults to value of `custom-face-default-form'
3208 :custom-set
'custom-face-set
3209 :custom-save
'custom-face-save
3210 :custom-reset-current
'custom-redraw
3211 :custom-reset-saved
'custom-face-reset-saved
3212 :custom-reset-standard
'custom-face-reset-standard
3213 :custom-standard-value
'custom-face-standard-value
3214 :custom-menu
'custom-face-menu-create
)
3216 (define-widget 'custom-face-all
'editable-list
3217 "An editable list of display specifications and attributes."
3218 :entry-format
"%i %d %v"
3219 :insert-button-args
'(:help-echo
"Insert new display specification here.")
3220 :append-button-args
'(:help-echo
"Append new display specification here.")
3221 :delete-button-args
'(:help-echo
"Delete this display specification.")
3222 :args
'((group :format
"%v" custom-display custom-face-edit
)))
3224 (defconst custom-face-all
(widget-convert 'custom-face-all
)
3225 "Converted version of the `custom-face-all' widget.")
3227 (define-widget 'custom-display-unselected
'item
3228 "A display specification that doesn't match the selected display."
3229 :match
'custom-display-unselected-match
)
3231 (defun custom-display-unselected-match (widget value
)
3232 "Non-nil if VALUE is an unselected display specification."
3233 (not (face-spec-set-match-display value
(selected-frame))))
3235 (define-widget 'custom-face-selected
'group
3236 "Edit the attributes of the selected display in a face specification."
3237 :args
'((choice :inline t
3238 (group :tag
"With Defaults" :inline t
3239 (group (const :tag
"" default
)
3240 (custom-face-edit :tag
" Default\n Attributes"))
3243 (group custom-display-unselected sexp
))
3244 (group (sexp :format
"")
3245 (custom-face-edit :tag
" Overriding\n Attributes"))
3249 (group :tag
"No Defaults" :inline t
3252 (group custom-display-unselected sexp
))
3253 (group (sexp :format
"")
3254 (custom-face-edit :tag
"\n Attributes"))
3261 (defconst custom-face-selected
(widget-convert 'custom-face-selected
)
3262 "Converted version of the `custom-face-selected' widget.")
3264 (defun custom-filter-face-spec (spec filter-index
&optional default-filter
)
3265 "Return a canonicalized version of SPEC using.
3266 FILTER-INDEX is the index in the entry for each attribute in
3267 `custom-face-attributes' at which the appropriate filter function can be
3268 found, and DEFAULT-FILTER is the filter to apply for attributes that
3270 (mapcar (lambda (entry)
3271 ;; Filter a single face-spec entry
3272 (let ((tests (car entry
))
3274 ;; Handle both old- and new-style attribute syntax
3275 (if (listp (car (cdr entry
)))
3278 (filtered-attrs nil
))
3279 ;; Filter each face attribute
3280 (while unfiltered-attrs
3281 (let* ((attr (pop unfiltered-attrs
))
3282 (pre-filtered-value (pop unfiltered-attrs
))
3284 (or (nth filter-index
(assq attr custom-face-attributes
))
3288 (funcall filter pre-filtered-value
)
3289 pre-filtered-value
)))
3290 (push filtered-value filtered-attrs
)
3291 (push attr filtered-attrs
)))
3293 (list tests filtered-attrs
)))
3296 (defun custom-pre-filter-face-spec (spec)
3297 "Return SPEC changed as necessary for editing by the face customization widget.
3298 SPEC must be a full face spec."
3299 (custom-filter-face-spec spec
2))
3301 (defun custom-post-filter-face-spec (spec)
3302 "Return the customized SPEC in a form suitable for setting the face."
3303 (custom-filter-face-spec spec
3))
3305 (defun custom-face-value-create (widget)
3306 "Create a list of the display specifications for WIDGET."
3307 (let ((buttons (widget-get widget
:buttons
))
3309 (symbol (widget-get widget
:value
))
3310 (tag (widget-get widget
:tag
))
3311 (state (widget-get widget
:custom-state
))
3313 (is-last (widget-get widget
:custom-last
))
3314 (prefix (widget-get widget
:custom-prefix
)))
3316 (setq tag
(prin1-to-string symbol
)))
3317 (cond ((eq custom-buffer-style
'tree
)
3318 (insert prefix
(if is-last
" `--- " " |--- "))
3319 (push (widget-create-child-and-convert
3320 widget
'custom-browse-face-tag
)
3322 (insert " " tag
"\n")
3323 (widget-put widget
:buttons buttons
))
3327 (widget-specify-sample widget begin
(point))
3328 (if (eq custom-buffer-style
'face
)
3330 (if (string-match "face\\'" tag
)
3332 (insert " face: ")))
3334 (push (widget-create-child-and-convert widget
'item
3341 (push (widget-create-child-and-convert
3343 :help-echo
"Hide or show this face."
3346 :action
'custom-toggle-parent
3347 (not (eq state
'hidden
)))
3351 (let ((magic (widget-create-child-and-convert
3352 widget
'custom-magic nil
)))
3353 (widget-put widget
:custom-magic magic
)
3354 (push magic buttons
))
3356 (widget-put widget
:buttons buttons
)
3357 ;; Insert documentation.
3358 (widget-default-format-handler widget ?h
)
3359 ;; The comment field
3360 (unless (eq state
'hidden
)
3361 (let* ((comment (get symbol
'face-comment
))
3363 (widget-create-child-and-convert
3364 widget
'custom-comment
3366 :value
(or comment
""))))
3367 (widget-put widget
:comment-widget comment-widget
)
3368 (push comment-widget children
)))
3370 (unless (eq state
'hidden
)
3371 (when (eq (widget-get widget
:custom-level
) 1)
3372 (custom-add-parent-links widget
))
3373 (custom-add-see-also widget
))
3375 (unless (eq (preceding-char) ?
\n)
3377 (unless (eq state
'hidden
)
3378 (message "Creating face editor...")
3379 (custom-load-widget widget
)
3380 (unless (widget-get widget
:custom-form
)
3381 (widget-put widget
:custom-form custom-face-default-form
))
3382 (let* ((symbol (widget-value widget
))
3383 (spec (or (get symbol
'customized-face
)
3384 (get symbol
'saved-face
)
3385 (get symbol
'face-defface-spec
)
3386 ;; Attempt to construct it.
3387 (list (list t
(custom-face-attributes-get
3388 symbol
(selected-frame))))))
3389 (form (widget-get widget
:custom-form
))
3390 (indent (widget-get widget
:indent
))
3392 ;; If the user has changed this face in some other way,
3393 ;; edit it as the user has specified it.
3394 (if (not (face-spec-match-p symbol spec
(selected-frame)))
3395 (setq spec
(list (list t
(face-attr-construct symbol
(selected-frame))))))
3396 (setq spec
(custom-pre-filter-face-spec spec
))
3397 (setq edit
(widget-create-child-and-convert
3399 (cond ((and (eq form
'selected
)
3400 (widget-apply custom-face-selected
3402 (when indent
(insert-char ?\ indent
))
3403 'custom-face-selected
)
3404 ((and (not (eq form
'lisp
))
3405 (widget-apply custom-face-all
3409 (when indent
(insert-char ?\ indent
))
3412 (custom-face-state-set widget
)
3413 (push edit children
)
3414 (widget-put widget
:children children
))
3415 (message "Creating face editor...done"))))))
3417 (defvar custom-face-menu
3418 `(("Set for Current Session" custom-face-set
)
3419 ,@(when (or custom-file user-init-file
)
3420 '(("Save for Future Sessions" custom-face-save
)))
3421 ("Undo Edits" custom-redraw
3423 (memq (widget-get widget
:custom-state
) '(modified changed
))))
3424 ("Reset to Saved" custom-face-reset-saved
3426 (or (get (widget-value widget
) 'saved-face
)
3427 (get (widget-value widget
) 'saved-face-comment
))))
3428 ,@(when (or custom-file user-init-file
)
3429 '(("Erase Customization" custom-face-reset-standard
3431 (get (widget-value widget
) 'face-defface-spec
)))))
3432 ("---" ignore ignore
)
3433 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
3434 ("---" ignore ignore
)
3435 ("For Current Display" custom-face-edit-selected
3437 (not (eq (widget-get widget
:custom-form
) 'selected
))))
3438 ("For All Kinds of Displays" custom-face-edit-all
3440 (not (eq (widget-get widget
:custom-form
) 'all
))))
3441 ("Show Lisp Expression" custom-face-edit-lisp
3443 (not (eq (widget-get widget
:custom-form
) 'lisp
)))))
3444 "Alist of actions for the `custom-face' widget.
3445 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3446 the menu entry, ACTION is the function to call on the widget when the
3447 menu is selected, and FILTER is a predicate which takes a `custom-face'
3448 widget as an argument, and returns non-nil if ACTION is valid on that
3449 widget. If FILTER is nil, ACTION is always valid.")
3451 (defun custom-face-edit-selected (widget)
3452 "Edit selected attributes of the value of WIDGET."
3453 (widget-put widget
:custom-state
'unknown
)
3454 (widget-put widget
:custom-form
'selected
)
3455 (custom-redraw widget
))
3457 (defun custom-face-edit-all (widget)
3458 "Edit all attributes of the value of WIDGET."
3459 (widget-put widget
:custom-state
'unknown
)
3460 (widget-put widget
:custom-form
'all
)
3461 (custom-redraw widget
))
3463 (defun custom-face-edit-lisp (widget)
3464 "Edit the Lisp representation of the value of WIDGET."
3465 (widget-put widget
:custom-state
'unknown
)
3466 (widget-put widget
:custom-form
'lisp
)
3467 (custom-redraw widget
))
3469 (defun custom-face-state-set (widget)
3470 "Set the state of WIDGET."
3471 (let* ((symbol (widget-value widget
))
3472 (comment (get symbol
'face-comment
))
3476 (setq tmp
(get symbol
'customized-face
))
3477 (setq temp
(get symbol
'customized-face-comment
))
3479 (if (equal temp comment
)
3483 (setq tmp
(get symbol
'saved-face
))
3484 (setq temp
(get symbol
'saved-face-comment
))
3486 (if (equal temp comment
)
3488 ((eq 'user
(caar (get symbol
'theme-face
)))
3490 ((eq 'changed
(caar (get symbol
'theme-face
)))
3494 ((get symbol
'face-defface-spec
)
3495 (if (equal comment nil
)
3500 ;; If the user called set-face-attribute to change the default
3501 ;; for new frames, this face is "set outside of Customize".
3502 (if (and (not (eq state
'rogue
))
3503 (get symbol
'face-modified
))
3504 (setq state
'changed
))
3505 (widget-put widget
:custom-state state
)))
3507 (defun custom-face-action (widget &optional event
)
3508 "Show the menu for `custom-face' WIDGET.
3509 Optional EVENT is the location for the menu."
3510 (if (eq (widget-get widget
:custom-state
) 'hidden
)
3511 (custom-toggle-hide widget
)
3512 (let* ((completion-ignore-case t
)
3513 (symbol (widget-get widget
:value
))
3514 (answer (widget-choose (concat "Operation on "
3515 (custom-unlispify-tag-name symbol
))
3516 (custom-menu-filter custom-face-menu
3520 (funcall answer widget
)))))
3522 (defun custom-face-set (widget)
3523 "Make the face attributes in WIDGET take effect."
3524 (let* ((symbol (widget-value widget
))
3525 (child (car (widget-get widget
:children
)))
3526 (value (custom-post-filter-face-spec (widget-value child
)))
3527 (comment-widget (widget-get widget
:comment-widget
))
3528 (comment (widget-value comment-widget
)))
3529 (when (equal comment
"")
3531 ;; Make the comment invisible by hand if it's empty
3532 (custom-comment-hide comment-widget
))
3533 (put symbol
'customized-face value
)
3534 (custom-push-theme 'theme-face symbol
'user
'set value
)
3535 (if (face-spec-choose value
)
3536 (face-spec-set symbol value
)
3537 ;; face-set-spec ignores empty attribute lists, so just give it
3538 ;; something harmless instead.
3539 (face-spec-set symbol
'((t :foreground unspecified
))))
3540 (put symbol
'customized-face-comment comment
)
3541 (put symbol
'face-comment comment
)
3542 (custom-face-state-set widget
)
3543 (custom-redraw-magic widget
)))
3545 (defun custom-face-save (widget)
3546 "Save in `.emacs' the face attributes in WIDGET."
3547 (let* ((symbol (widget-value widget
))
3548 (child (car (widget-get widget
:children
)))
3549 (value (custom-post-filter-face-spec (widget-value child
)))
3550 (comment-widget (widget-get widget
:comment-widget
))
3551 (comment (widget-value comment-widget
)))
3552 (when (equal comment
"")
3554 ;; Make the comment invisible by hand if it's empty
3555 (custom-comment-hide comment-widget
))
3556 (custom-push-theme 'theme-face symbol
'user
'set value
)
3557 (if (face-spec-choose value
)
3558 (face-spec-set symbol value
)
3559 ;; face-set-spec ignores empty attribute lists, so just give it
3560 ;; something harmless instead.
3561 (face-spec-set symbol
'((t :foreground unspecified
))))
3562 (unless (eq (widget-get widget
:custom-state
) 'standard
)
3563 (put symbol
'saved-face value
))
3564 (put symbol
'customized-face nil
)
3565 (put symbol
'face-comment comment
)
3566 (put symbol
'customized-face-comment nil
)
3567 (put symbol
'saved-face-comment comment
)
3569 (custom-face-state-set widget
)
3570 (custom-redraw-magic widget
)))
3572 ;; For backward compatibility.
3573 (define-obsolete-function-alias 'custom-face-save-command
'custom-face-save
3576 (defun custom-face-reset-saved (widget)
3577 "Restore WIDGET to the face's default attributes."
3578 (let* ((symbol (widget-value widget
))
3579 (child (car (widget-get widget
:children
)))
3580 (value (get symbol
'saved-face
))
3581 (comment (get symbol
'saved-face-comment
))
3582 (comment-widget (widget-get widget
:comment-widget
)))
3583 (unless (or value comment
)
3584 (error "No saved value for this face"))
3585 (put symbol
'customized-face nil
)
3586 (put symbol
'customized-face-comment nil
)
3587 (custom-push-theme 'theme-face symbol
'user
'set value
)
3588 (face-spec-set symbol value
)
3589 (put symbol
'face-comment comment
)
3590 (widget-value-set child value
)
3591 ;; This call manages the comment visibility
3592 (widget-value-set comment-widget
(or comment
""))
3593 (custom-face-state-set widget
)
3594 (custom-redraw-magic widget
)))
3596 (defun custom-face-standard-value (widget)
3597 (get (widget-value widget
) 'face-defface-spec
))
3599 (defun custom-face-reset-standard (widget)
3600 "Restore WIDGET to the face's standard attribute values.
3601 This operation eliminates any saved attributes for the face,
3602 restoring it to the state of a face that has never been customized."
3603 (let* ((symbol (widget-value widget
))
3604 (child (car (widget-get widget
:children
)))
3605 (value (get symbol
'face-defface-spec
))
3606 (comment-widget (widget-get widget
:comment-widget
)))
3608 (error "No standard setting for this face"))
3609 (put symbol
'customized-face nil
)
3610 (put symbol
'customized-face-comment nil
)
3611 (custom-push-theme 'theme-face symbol
'user
'reset
)
3612 (face-spec-set symbol value
)
3613 (custom-theme-recalc-face symbol
)
3614 (when (or (get symbol
'saved-face
) (get symbol
'saved-face-comment
))
3615 (put symbol
'saved-face nil
)
3616 (put symbol
'saved-face-comment nil
)
3618 (put symbol
'face-comment nil
)
3619 (widget-value-set child
3620 (custom-pre-filter-face-spec
3621 (list (list t
(custom-face-attributes-get
3623 ;; This call manages the comment visibility
3624 (widget-value-set comment-widget
"")
3625 (custom-face-state-set widget
)
3626 (custom-redraw-magic widget
)))
3628 ;;; The `face' Widget.
3630 (defvar widget-face-prompt-value-history nil
3631 "History of input to `widget-face-prompt-value'.")
3633 (define-widget 'face
'symbol
3634 "A Lisp face name (with sample)."
3635 :format
"%{%t%}: (%{sample%}) %v"
3638 :sample-face-get
'widget-face-sample-face-get
3639 :notify
'widget-face-notify
3640 :match
(lambda (widget value
) (facep value
))
3641 :complete-function
(lambda ()
3643 (lisp-complete-symbol 'facep
))
3644 :prompt-match
'facep
3645 :prompt-history
'widget-face-prompt-value-history
3646 :validate
(lambda (widget)
3647 (unless (facep (widget-value widget
))
3649 :error
(format "Invalid face: %S"
3650 (widget-value widget
)))
3653 (defun widget-face-sample-face-get (widget)
3654 (let ((value (widget-value widget
)))
3659 (defun widget-face-notify (widget child
&optional event
)
3660 "Update the sample, and notify the parent."
3661 (overlay-put (widget-get widget
:sample-overlay
)
3662 'face
(widget-apply widget
:sample-face-get
))
3663 (widget-default-notify widget child event
))
3666 ;;; The `hook' Widget.
3668 (define-widget 'hook
'list
3669 "An Emacs Lisp hook."
3670 :value-to-internal
(lambda (widget value
)
3671 (if (and value
(symbolp value
))
3674 :match
(lambda (widget value
)
3676 (widget-group-match widget value
)))
3677 ;; Avoid adding undefined functions to the hook, especially for
3678 ;; things like `find-file-hook' or even more basic ones, to avoid
3680 :set
(lambda (symbol value
)
3683 (add-hook symbol elt
))))
3684 :convert-widget
'custom-hook-convert-widget
3687 (defun custom-hook-convert-widget (widget)
3688 ;; Handle `:options'.
3689 (let* ((options (widget-get widget
:options
))
3690 (other `(editable-list :inline t
3691 :entry-format
"%i %d%v"
3692 (function :format
" %v")))
3694 (list `(checklist :inline t
3695 ,@(mapcar (lambda (entry)
3696 `(function-item ,entry
))
3700 (widget-put widget
:args args
)
3703 ;;; The `custom-group-link' Widget.
3705 (define-widget 'custom-group-link
'link
3706 "Show parent in other window when activated."
3707 :button-face
'custom-link
3708 :mouse-face
'highlight
3709 :pressed-face
'highlight
3710 :help-echo
"Create customization buffer for this group."
3711 :keymap custom-mode-link-map
3712 :follow-link
'mouse-face
3713 :action
'custom-group-link-action
)
3715 (defun custom-group-link-action (widget &rest ignore
)
3716 (customize-group (widget-value widget
)))
3718 ;;; The `custom-group' Widget.
3720 (defcustom custom-group-tag-faces nil
3721 ;; In XEmacs, this ought to play games with font size.
3722 ;; Fixme: make it do so in Emacs.
3723 "Face used for group tags.
3724 The first member is used for level 1 groups, the second for level 2,
3725 and so forth. The remaining group tags are shown with `custom-group-tag'."
3726 :type
'(repeat face
)
3727 :group
'custom-faces
)
3729 (defface custom-group-tag-1
3732 (:foreground
"pink" :weight bold
:height
1.2 :inherit variable-pitch
))
3733 (((min-colors 88) (class color
)
3735 (:foreground
"red1" :weight bold
:height
1.2 :inherit variable-pitch
))
3738 (:foreground
"red" :weight bold
:height
1.2 :inherit variable-pitch
))
3740 "Face used for group tags."
3741 :group
'custom-faces
)
3742 ;; backward-compatibility alias
3743 (put 'custom-group-tag-face-1
'face-alias
'custom-group-tag-1
)
3745 (defface custom-group-tag
3748 (:foreground
"light blue" :weight bold
:height
1.2))
3749 (((min-colors 88) (class color
)
3751 (:foreground
"blue1" :weight bold
:height
1.2))
3754 (:foreground
"blue" :weight bold
:height
1.2))
3756 "Face used for low level group tags."
3757 :group
'custom-faces
)
3758 ;; backward-compatibility alias
3759 (put 'custom-group-tag-face
'face-alias
'custom-group-tag
)
3761 (define-widget 'custom-group
'custom
3764 :sample-face-get
'custom-group-sample-face-get
3765 :documentation-property
'group-documentation
3766 :help-echo
"Set or reset all members of this group."
3767 :value-create
'custom-group-value-create
3768 :action
'custom-group-action
3769 :custom-category
'group
3770 :custom-set
'custom-group-set
3771 :custom-save
'custom-group-save
3772 :custom-reset-current
'custom-group-reset-current
3773 :custom-reset-saved
'custom-group-reset-saved
3774 :custom-reset-standard
'custom-group-reset-standard
3775 :custom-menu
'custom-group-menu-create
)
3777 (defun custom-group-sample-face-get (widget)
3778 ;; Use :sample-face.
3779 (or (nth (1- (widget-get widget
:custom-level
)) custom-group-tag-faces
)
3782 (define-widget 'custom-group-visibility
'visibility
3783 "An indicator and manipulator for hidden group contents."
3784 :create
'custom-group-visibility-create
)
3786 (defun custom-group-visibility-create (widget)
3787 (let ((visible (widget-value widget
)))
3789 (insert "--------")))
3790 (widget-default-create widget
))
3792 (defun custom-group-members (symbol groups-only
)
3793 "Return SYMBOL's custom group members.
3794 If GROUPS-ONLY non-nil, return only those members that are groups."
3795 (if (not groups-only
)
3796 (get symbol
'custom-group
)
3798 (dolist (entry (get symbol
'custom-group
))
3799 (when (eq (nth 1 entry
) 'custom-group
)
3800 (push entry members
)))
3801 (nreverse members
))))
3803 (defun custom-group-value-create (widget)
3804 "Insert a customize group for WIDGET in the current buffer."
3805 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
3806 (custom-load-widget widget
))
3807 (let* ((state (widget-get widget
:custom-state
))
3808 (level (widget-get widget
:custom-level
))
3809 ;; (indent (widget-get widget :indent))
3810 (prefix (widget-get widget
:custom-prefix
))
3811 (buttons (widget-get widget
:buttons
))
3812 (tag (widget-get widget
:tag
))
3813 (symbol (widget-value widget
))
3814 (members (custom-group-members symbol
3815 (and (eq custom-buffer-style
'tree
)
3816 custom-browse-only-groups
))))
3817 (cond ((and (eq custom-buffer-style
'tree
)
3819 (or members
(custom-unloaded-widget-p widget
)))
3820 (custom-browse-insert-prefix prefix
)
3821 (push (widget-create-child-and-convert
3822 widget
'custom-browse-visibility
3823 ;; :tag-glyph "plus"
3827 ;; (widget-glyph-insert nil "-- " "horizontal")
3828 (push (widget-create-child-and-convert
3829 widget
'custom-browse-group-tag
)
3831 (insert " " tag
"\n")
3832 (widget-put widget
:buttons buttons
))
3833 ((and (eq custom-buffer-style
'tree
)
3834 (zerop (length members
)))
3835 (custom-browse-insert-prefix prefix
)
3837 ;; (widget-glyph-insert nil "[ ]" "empty")
3838 ;; (widget-glyph-insert nil "-- " "horizontal")
3839 (push (widget-create-child-and-convert
3840 widget
'custom-browse-group-tag
)
3842 (insert " " tag
"\n")
3843 (widget-put widget
:buttons buttons
))
3844 ((eq custom-buffer-style
'tree
)
3845 (custom-browse-insert-prefix prefix
)
3846 (if (zerop (length members
))
3848 (custom-browse-insert-prefix prefix
)
3850 ;; (widget-glyph-insert nil "[ ]" "empty")
3851 ;; (widget-glyph-insert nil "-- " "horizontal")
3852 (push (widget-create-child-and-convert
3853 widget
'custom-browse-group-tag
)
3855 (insert " " tag
"\n")
3856 (widget-put widget
:buttons buttons
))
3857 (push (widget-create-child-and-convert
3858 widget
'custom-browse-visibility
3859 ;; :tag-glyph "minus"
3863 ;; (widget-glyph-insert nil "-\\ " "top")
3864 (push (widget-create-child-and-convert
3865 widget
'custom-browse-group-tag
)
3867 (insert " " tag
"\n")
3868 (widget-put widget
:buttons buttons
)
3869 (message "Creating group...")
3870 (let* ((members (custom-sort-items members
3871 custom-browse-sort-alphabetically
3872 custom-browse-order-groups
))
3873 (prefixes (widget-get widget
:custom-prefixes
))
3874 (custom-prefix-list (custom-prefix-add symbol prefixes
))
3875 (extra-prefix (if (widget-get widget
:custom-last
)
3878 (prefix (concat prefix extra-prefix
))
3881 (setq entry
(car members
)
3882 members
(cdr members
))
3883 (push (widget-create-child-and-convert
3884 widget
(nth 1 entry
)
3886 :tag
(custom-unlispify-tag-name (nth 0 entry
))
3887 :custom-prefixes custom-prefix-list
3888 :custom-level
(1+ level
)
3889 :custom-last
(null members
)
3890 :value
(nth 0 entry
)
3891 :custom-prefix prefix
)
3893 (widget-put widget
:children
(reverse children
)))
3894 (message "Creating group...done")))
3897 ;; Create level indicator.
3898 (unless (eq custom-buffer-style
'links
)
3899 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3902 (let ((begin (point)))
3904 (widget-specify-sample widget begin
(point)))
3906 ;; Create link/visibility indicator.
3907 (if (eq custom-buffer-style
'links
)
3908 (push (widget-create-child-and-convert
3909 widget
'custom-group-link
3913 (push (widget-create-child-and-convert
3914 widget
'custom-group-visibility
3915 :help-echo
"Show members of this group."
3916 :action
'custom-toggle-parent
3917 (not (eq state
'hidden
)))
3920 ;; Create magic button.
3921 (let ((magic (widget-create-child-and-convert
3922 widget
'custom-magic nil
)))
3923 (widget-put widget
:custom-magic magic
)
3924 (push magic buttons
))
3926 (widget-put widget
:buttons buttons
)
3927 ;; Insert documentation.
3928 (if (and (eq custom-buffer-style
'links
) (> level
1))
3929 (widget-put widget
:documentation-indent
0))
3930 (widget-default-format-handler widget ?h
))
3933 ;; Add parent groups references above the group.
3934 (if t
;;; This should test that the buffer
3935 ;;; was made to display a group.
3937 (if (custom-add-parent-links widget
3938 "Go to parent group:")
3940 ;; Create level indicator.
3941 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3944 (let ((start (point)))
3946 (widget-specify-sample widget start
(point)))
3948 ;; Create visibility indicator.
3949 (unless (eq custom-buffer-style
'links
)
3951 (push (widget-create-child-and-convert
3953 :help-echo
"Hide members of this group."
3954 :action
'custom-toggle-parent
3955 (not (eq state
'hidden
)))
3958 ;; Create more dashes.
3959 ;; Use 76 instead of 75 to compensate for the temporary "<"
3960 ;; added by `widget-insert'.
3961 (insert-char ?-
(- 76 (current-column)
3962 (* custom-buffer-indent level
)))
3964 ;; Create magic button.
3965 (let ((magic (widget-create-child-and-convert
3966 widget
'custom-magic
3969 (widget-put widget
:custom-magic magic
)
3970 (push magic buttons
))
3972 (widget-put widget
:buttons buttons
)
3973 ;; Insert documentation.
3974 (widget-default-format-handler widget ?h
)
3976 (if nil
;;; This should test that the buffer
3977 ;;; was not made to display a group.
3979 (insert-char ?\ custom-buffer-indent
)
3980 (custom-add-parent-links widget
)))
3981 (custom-add-see-also widget
3982 (make-string (* custom-buffer-indent level
)
3985 (message "Creating group...")
3986 (let* ((members (custom-sort-items members
3987 custom-buffer-sort-alphabetically
3988 custom-buffer-order-groups
))
3989 (prefixes (widget-get widget
:custom-prefixes
))
3990 (custom-prefix-list (custom-prefix-add symbol prefixes
))
3991 (length (length members
))
3993 (children (mapcar (lambda (entry)
3994 (widget-insert "\n")
3996 Creating group members... %2d%%"
3997 (/ (* 100.0 count
) length
))
3998 (setq count
(1+ count
))
4000 (widget-create-child-and-convert
4001 widget
(nth 1 entry
)
4003 :tag
(custom-unlispify-tag-name
4005 :custom-prefixes custom-prefix-list
4006 :custom-level
(1+ level
)
4007 :value
(nth 0 entry
))
4008 (unless (eq (preceding-char) ?
\n)
4009 (widget-insert "\n"))))
4011 (message "Creating group magic...")
4012 (mapc 'custom-magic-reset children
)
4013 (message "Creating group state...")
4014 (widget-put widget
:children children
)
4015 (custom-group-state-update widget
)
4016 (message "Creating group... done"))
4019 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
4020 (insert "\\- " (widget-get widget
:tag
) " group end ")
4021 (insert-char ?-
(- 75 (current-column) (* custom-buffer-indent level
)))
4024 (defvar custom-group-menu
4025 `(("Set for Current Session" custom-group-set
4027 (eq (widget-get widget
:custom-state
) 'modified
)))
4028 ,@(when (or custom-file user-init-file
)
4029 '(("Save for Future Sessions" custom-group-save
4031 (memq (widget-get widget
:custom-state
) '(modified set
))))))
4032 ("Undo Edits" custom-group-reset-current
4034 (memq (widget-get widget
:custom-state
) '(modified))))
4035 ("Reset to Saved" custom-group-reset-saved
4037 (memq (widget-get widget
:custom-state
) '(modified set
))))
4038 ,@(when (or custom-file user-init-file
)
4039 '(("Erase Customization" custom-group-reset-standard
4041 (memq (widget-get widget
:custom-state
) '(modified set saved
)))))))
4042 "Alist of actions for the `custom-group' widget.
4043 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
4044 the menu entry, ACTION is the function to call on the widget when the
4045 menu is selected, and FILTER is a predicate which takes a `custom-group'
4046 widget as an argument, and returns non-nil if ACTION is valid on that
4047 widget. If FILTER is nil, ACTION is always valid.")
4049 (defun custom-group-action (widget &optional event
)
4050 "Show the menu for `custom-group' WIDGET.
4051 Optional EVENT is the location for the menu."
4052 (if (eq (widget-get widget
:custom-state
) 'hidden
)
4053 (custom-toggle-hide widget
)
4054 (let* ((completion-ignore-case t
)
4055 (answer (widget-choose (concat "Operation on "
4056 (custom-unlispify-tag-name
4057 (widget-get widget
:value
)))
4058 (custom-menu-filter custom-group-menu
4062 (funcall answer widget
)))))
4064 (defun custom-group-set (widget)
4065 "Set changes in all modified group members."
4066 (let ((children (widget-get widget
:children
)))
4067 (mapc (lambda (child)
4068 (when (eq (widget-get child
:custom-state
) 'modified
)
4069 (widget-apply child
:custom-set
)))
4072 (defun custom-group-save (widget)
4073 "Save all modified group members."
4074 (let ((children (widget-get widget
:children
)))
4075 (mapc (lambda (child)
4076 (when (memq (widget-get child
:custom-state
) '(modified set
))
4077 (widget-apply child
:custom-save
)))
4080 (defun custom-group-reset-current (widget)
4081 "Reset all modified group members."
4082 (let ((children (widget-get widget
:children
)))
4083 (mapc (lambda (child)
4084 (when (eq (widget-get child
:custom-state
) 'modified
)
4085 (widget-apply child
:custom-reset-current
)))
4088 (defun custom-group-reset-saved (widget)
4089 "Reset all modified or set group members."
4090 (let ((children (widget-get widget
:children
)))
4091 (mapc (lambda (child)
4092 (when (memq (widget-get child
:custom-state
) '(modified set
))
4093 (widget-apply child
:custom-reset-saved
)))
4096 (defun custom-group-reset-standard (widget)
4097 "Reset all modified, set, or saved group members."
4098 (let ((children (widget-get widget
:children
)))
4099 (mapc (lambda (child)
4100 (when (memq (widget-get child
:custom-state
)
4101 '(modified set saved
))
4102 (widget-apply child
:custom-reset-standard
)))
4105 (defun custom-group-state-update (widget)
4107 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
4108 (let* ((children (widget-get widget
:children
))
4109 (states (mapcar (lambda (child)
4110 (widget-get child
:custom-state
))
4112 (magics custom-magic-alist
)
4115 (let ((magic (car (car magics
))))
4116 (if (and (not (eq magic
'hidden
))
4117 (memq magic states
))
4120 (setq magics
(cdr magics
)))))
4121 (widget-put widget
:custom-state found
)))
4122 (custom-magic-reset widget
))
4124 ;;; Reading and writing the custom file.
4127 (defcustom custom-file nil
4128 "File used for storing customization information.
4129 The default is nil, which means to use your init file
4130 as specified by `user-init-file'. If the value is not nil,
4131 it should be an absolute file name.
4133 You can set this option through Custom, if you carefully read the
4134 last paragraph below. However, usually it is simpler to write
4135 something like the following in your init file:
4137 \(setq custom-file \"~/.emacs-custom.el\")
4140 Note that both lines are necessary: the first line tells Custom to
4141 save all customizations in this file, but does not load it.
4143 When you change this variable outside Custom, look in the
4144 previous custom file \(usually your init file) for the
4145 forms `(custom-set-variables ...)' and `(custom-set-faces ...)',
4146 and copy them (whichever ones you find) to the new custom file.
4147 This will preserve your existing customizations.
4149 If you save this option using Custom, Custom will write all
4150 currently saved customizations, including the new one for this
4151 option itself, into the file you specify, overwriting any
4152 `custom-set-variables' and `custom-set-faces' forms already
4153 present in that file. It will not delete any customizations from
4154 the old custom file. You should do that manually if that is what you
4155 want. You also have to put something like `\(load \"CUSTOM-FILE\")
4156 in your init file, where CUSTOM-FILE is the actual name of the
4157 file. Otherwise, Emacs will not load the file when it starts up,
4158 and hence will not set `custom-file' to that file either."
4159 :type
'(choice (const :tag
"Your Emacs init file" nil
)
4160 (file :format
"%t:%v%d"
4162 "Please read entire docstring below before setting \
4163 this through Custom.
4164 Click om \"More\" \(or position point there and press RETURN)
4165 if only the first line of the docstring is shown."))
4168 (defun custom-file ()
4169 "Return the file name for saving customizations."
4172 (let ((user-init-file user-init-file
)
4174 (if (eq system-type
'ms-dos
) "~/_emacs" "~/.emacs")))
4175 (when (null user-init-file
)
4176 (if (or (file-exists-p default-init-file
)
4177 (and (eq system-type
'windows-nt
)
4178 (file-exists-p "~/_emacs")))
4179 ;; Started with -q, i.e. the file containing
4180 ;; Custom settings hasn't been read. Saving
4181 ;; settings there would overwrite other settings.
4182 (error "Saving settings from \"emacs -q\" would overwrite existing customizations"))
4183 (setq user-init-file default-init-file
))
4187 (defun custom-save-all ()
4188 "Save all customizations in `custom-file'."
4189 (when (and (null custom-file
) init-file-had-error
)
4190 (error "Cannot save customizations; init file was not fully loaded"))
4191 (let* ((filename (custom-file))
4196 (recentf-expand-file-name (custom-file)))
4199 (old-buffer (find-buffer-visiting filename
)))
4200 (with-current-buffer (let ((find-file-visit-truename t
))
4201 (or old-buffer
(find-file-noselect filename
)))
4202 (unless (eq major-mode
'emacs-lisp-mode
)
4204 (let ((inhibit-read-only t
))
4205 (custom-save-variables)
4206 (custom-save-faces))
4207 (let ((file-precious-flag t
))
4210 (kill-buffer (current-buffer))))))
4213 (defun customize-save-customized ()
4214 "Save all user options which have been set in this session."
4216 (mapatoms (lambda (symbol)
4217 (let ((face (get symbol
'customized-face
))
4218 (value (get symbol
'customized-value
))
4219 (face-comment (get symbol
'customized-face-comment
))
4221 (get symbol
'customized-variable-comment
)))
4223 (put symbol
'saved-face face
)
4224 (custom-push-theme 'theme-face symbol
'user
'set value
)
4225 (put symbol
'customized-face nil
))
4227 (put symbol
'saved-value value
)
4228 (custom-push-theme 'theme-value symbol
'user
'set value
)
4229 (put symbol
'customized-value nil
))
4230 (when variable-comment
4231 (put symbol
'saved-variable-comment variable-comment
)
4232 (put symbol
'customized-variable-comment nil
))
4234 (put symbol
'saved-face-comment face-comment
)
4235 (put symbol
'customized-face-comment nil
)))))
4236 ;; We really should update all custom buffers here.
4239 ;; Editing the custom file contents in a buffer.
4241 (defun custom-save-delete (symbol)
4242 "Delete all calls to SYMBOL from the contents of the current buffer.
4243 Leave point at the old location of the first such call,
4244 or (if there were none) at the end of the buffer.
4246 This function does not save the buffer."
4247 (goto-char (point-min))
4248 ;; Skip all whitespace and comments.
4249 (while (forward-comment 1))
4251 (save-excursion (forward-sexp (buffer-size)))) ; Test for scan errors.
4254 (while t
;; We exit this loop only via throw.
4255 ;; Skip all whitespace and comments.
4256 (while (forward-comment 1))
4257 (let ((start (point))
4258 (sexp (condition-case nil
4259 (read (current-buffer))
4260 (end-of-file (throw 'found nil
)))))
4261 (when (and (listp sexp
)
4262 (eq (car sexp
) symbol
))
4263 (delete-region start
(point))
4265 (setq first
(point)))))))
4268 ;; Move in front of local variables, otherwise long Custom
4269 ;; entries would make them ineffective.
4270 (let ((pos (point-max))
4271 (case-fold-search t
))
4273 (goto-char (point-max))
4274 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
4276 (when (search-forward "Local Variables:" nil t
)
4277 (setq pos
(line-beginning-position))))
4280 (defun custom-save-variables ()
4281 "Save all customized variables in `custom-file'."
4283 (custom-save-delete 'custom-set-variables
)
4284 (let ((standard-output (current-buffer))
4285 (saved-list (make-list 1 0))
4287 ;; First create a sorted list of saved variables.
4290 (if (and (get symbol
'saved-value
)
4291 ;; ignore theme values
4292 (or (null (get symbol
'theme-value
))
4293 (eq 'user
(caar (get symbol
'theme-value
)))))
4294 (nconc saved-list
(list symbol
)))))
4295 (setq saved-list
(sort (cdr saved-list
) 'string
<))
4298 (princ "(custom-set-variables
4299 ;; custom-set-variables was added by Custom.
4300 ;; If you edit it by hand, you could mess it up, so be careful.
4301 ;; Your init file should contain only one such instance.
4302 ;; If there is more than one, they won't work right.\n")
4303 (dolist (symbol saved-list
)
4304 (let ((spec (car-safe (get symbol
'theme-value
)))
4305 (value (get symbol
'saved-value
))
4306 (requests (get symbol
'custom-requests
))
4307 (now (and (not (custom-variable-p symbol
))
4309 (eq (get symbol
'force-value
)
4311 (comment (get symbol
'saved-variable-comment
)))
4312 ;; Check REQUESTS for validity.
4313 (dolist (request requests
)
4314 (when (and (symbolp request
) (not (featurep request
)))
4315 (message "Unknown requested feature: %s" request
)
4316 (setq requests
(delq request requests
))))
4317 ;; Is there anything customized about this variable?
4318 (when (or (and spec
(eq (car spec
) 'user
))
4320 (and (null spec
) (get symbol
'saved-value
)))
4321 ;; Output an element for this variable.
4322 ;; It has the form (SYMBOL VALUE-FORM NOW REQUESTS COMMENT).
4323 ;; SYMBOL is the variable name.
4324 ;; VALUE-FORM is an expression to return the customized value.
4325 ;; NOW if non-nil means always set the variable immediately
4326 ;; when the customizations are reloaded. This is used
4327 ;; for rogue variables
4328 ;; REQUESTS is a list of packages to load before setting the
4329 ;; variable. Each element of it will be passed to `require'.
4330 ;; COMMENT is whatever comment the user has specified
4331 ;; with the customize facility.
4338 (when (or now requests comment
)
4341 (when (or requests comment
)
4351 (unless (looking-at "\n")
4354 (defun custom-save-faces ()
4355 "Save all customized faces in `custom-file'."
4357 (custom-save-delete 'custom-reset-faces
)
4358 (custom-save-delete 'custom-set-faces
)
4359 (let ((standard-output (current-buffer))
4360 (saved-list (make-list 1 0))
4362 ;; First create a sorted list of saved faces.
4365 (if (and (get symbol
'saved-face
)
4366 (eq 'user
(car (car-safe (get symbol
'theme-face
)))))
4367 (nconc saved-list
(list symbol
)))))
4368 (setq saved-list
(sort (cdr saved-list
) 'string
<))
4369 ;; The default face must be first, since it affects the others.
4370 (if (memq 'default saved-list
)
4371 (setq saved-list
(cons 'default
(delq 'default saved-list
))))
4374 (princ "(custom-set-faces
4375 ;; custom-set-faces was added by Custom.
4376 ;; If you edit it by hand, you could mess it up, so be careful.
4377 ;; Your init file should contain only one such instance.
4378 ;; If there is more than one, they won't work right.\n")
4379 (dolist (symbol saved-list
)
4380 (let ((spec (car-safe (get symbol
'theme-face
)))
4381 (value (get symbol
'saved-face
))
4382 (now (not (or (get symbol
'face-defface-spec
)
4383 (and (not (custom-facep symbol
))
4384 (not (get symbol
'force-face
))))))
4385 (comment (get symbol
'saved-face-comment
)))
4386 (when (or (and spec
(eq (nth 0 spec
) 'user
))
4388 (and (null spec
) (get symbol
'saved-face
)))
4389 ;; Don't print default face here.
4396 (when (or now comment
)
4406 (unless (looking-at "\n")
4409 ;;; The Customize Menu.
4413 (defcustom custom-menu-nesting
2
4414 "Maximum nesting in custom menus."
4416 :group
'custom-menu
)
4418 (defun custom-face-menu-create (widget symbol
)
4419 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
4420 (vector (custom-unlispify-menu-entry symbol
)
4421 `(customize-face ',symbol
)
4424 (defun custom-variable-menu-create (widget symbol
)
4425 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
4426 (let ((type (get symbol
'custom-type
)))
4427 (unless (listp type
)
4428 (setq type
(list type
)))
4429 (if (and type
(widget-get type
:custom-menu
))
4430 (widget-apply type
:custom-menu symbol
)
4431 (vector (custom-unlispify-menu-entry symbol
)
4432 `(customize-variable ',symbol
)
4435 ;; Add checkboxes to boolean variable entries.
4436 (widget-put (get 'boolean
'widget-type
)
4437 :custom-menu
(lambda (widget symbol
)
4438 (vector (custom-unlispify-menu-entry symbol
)
4439 `(customize-variable ',symbol
)
4441 ':selected symbol
)))
4443 (defun custom-group-menu-create (widget symbol
)
4444 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
4445 `( ,(custom-unlispify-menu-entry symbol t
)
4446 :filter
(lambda (&rest junk
)
4447 (let* ((menu (custom-menu-create ',symbol
)))
4448 (if (consp menu
) (cdr menu
) menu
)))))
4451 (defun custom-menu-create (symbol)
4452 "Create menu for customization group SYMBOL.
4453 The menu is in a format applicable to `easy-menu-define'."
4454 (let* ((deactivate-mark nil
)
4455 (item (vector (custom-unlispify-menu-entry symbol
)
4456 `(customize-group ',symbol
)
4458 (if (and (or (not (boundp 'custom-menu-nesting
))
4459 (>= custom-menu-nesting
0))
4461 (custom-load-symbol symbol
)
4462 (< (length (get symbol
'custom-group
)) widget-menu-max-size
)))
4463 (let ((custom-prefix-list (custom-prefix-add symbol
4464 custom-prefix-list
))
4465 (members (custom-sort-items (get symbol
'custom-group
)
4466 custom-menu-sort-alphabetically
4467 custom-menu-order-groups
)))
4468 `(,(custom-unlispify-menu-entry symbol t
)
4471 ,@(mapcar (lambda (entry)
4472 (widget-apply (if (listp (nth 1 entry
))
4474 (list (nth 1 entry
)))
4475 :custom-menu
(nth 0 entry
)))
4480 (defun customize-menu-create (symbol &optional name
)
4481 "Return a customize menu for customization group SYMBOL.
4482 If optional NAME is given, use that as the name of the menu.
4483 Otherwise the menu will be named `Customize'.
4484 The format is suitable for use with `easy-menu-define'."
4486 (setq name
"Customize"))
4488 :filter
(lambda (&rest junk
)
4489 (let ((menu (custom-menu-create ',symbol
)))
4490 (if (consp menu
) (cdr menu
) menu
)))))
4492 ;;; The Custom Mode.
4494 (defun Custom-no-edit (pos &optional event
)
4495 "Invoke button at POS, or refuse to allow editing of Custom buffer."
4497 (error "You can't edit this part of the Custom buffer"))
4499 (defun Custom-newline (pos &optional event
)
4500 "Invoke button at POS, or refuse to allow editing of Custom buffer."
4502 (let ((button (get-char-property pos
'button
)))
4504 (widget-apply-action button event
)
4505 (error "You can't edit this part of the Custom buffer"))))
4507 (easy-menu-define Custom-mode-menu
4509 "Menu used in customization buffers."
4511 ,(customize-menu-create 'customize
)
4512 ["Set" Custom-set t
]
4513 ["Save" Custom-save t
]
4514 ["Undo Edits" Custom-reset-current t
]
4515 ["Reset to Saved" Custom-reset-saved t
]
4516 ["Erase Customization" Custom-reset-standard t
]
4517 ["Info" (info "(emacs)Easy Customization") t
]))
4519 (defvar custom-field-keymap
4520 (let ((map (copy-keymap widget-field-keymap
)))
4521 (define-key map
"\C-c\C-c" 'Custom-set
)
4522 (define-key map
"\C-x\C-s" 'Custom-save
)
4524 "Keymap used inside editable fields in customization buffers.")
4526 (widget-put (get 'editable-field
'widget-type
) :keymap custom-field-keymap
)
4528 (defun Custom-goto-parent ()
4529 "Go to the parent group listed at the top of this buffer.
4530 If several parents are listed, go to the first of them."
4533 (goto-char (point-min))
4534 (if (search-forward "\nGo to parent group: " nil t
)
4535 (let* ((button (get-char-property (point) 'button
))
4536 (parent (downcase (widget-get button
:tag
))))
4537 (customize-group parent
)))))
4539 (defcustom custom-mode-hook nil
4540 "Hook called when entering Custom mode."
4542 :group
'custom-buffer
)
4544 (defun custom-state-buffer-message (widget)
4545 (if (eq (widget-get (widget-get widget
:parent
) :custom-state
) 'modified
)
4546 (message "To install your edits, invoke [State] and choose the Set operation")))
4548 (defun custom-mode ()
4549 "Major mode for editing customization buffers.
4551 The following commands are available:
4554 Move to next button, link or editable field. \\[widget-forward]
4555 Move to previous button, link or editable field. \\[advertised-widget-backward]
4556 \\<custom-field-keymap>\
4557 Complete content of editable text field. \\[widget-complete]
4558 \\<custom-mode-map>\
4559 Invoke button under the mouse pointer. \\[widget-button-click]
4560 Invoke button under point. \\[widget-button-press]
4561 Set all options from current text. \\[Custom-set]
4562 Make values in current text permanent. \\[Custom-save]
4563 Make text match actual option values. \\[Custom-reset-current]
4564 Reset options to permanent settings. \\[Custom-reset-saved]
4565 Erase customizations; set options
4566 and buffer text to the standard values. \\[Custom-reset-standard]
4568 Entry to this mode calls the value of `custom-mode-hook'
4569 if that value is non-nil."
4570 (kill-all-local-variables)
4571 (setq major-mode
'custom-mode
4573 (use-local-map custom-mode-map
)
4574 (easy-menu-add Custom-mode-menu
)
4575 (make-local-variable 'custom-options
)
4576 (make-local-variable 'custom-local-buffer
)
4577 (make-local-variable 'widget-documentation-face
)
4578 (setq widget-documentation-face
'custom-documentation
)
4579 (make-local-variable 'widget-button-face
)
4580 (setq widget-button-face custom-button
)
4582 ;; We need this because of the "More" button on docstrings.
4583 ;; Otherwise clicking on "More" can push point offscreen, which
4584 ;; causes the window to recenter on point, which pushes the
4585 ;; newly-revealed docstring offscreen; which is annoying. -- cyd.
4586 (set (make-local-variable 'widget-button-click-moves-point
) t
)
4588 (set (make-local-variable 'widget-button-pressed-face
) custom-button-pressed
)
4589 (set (make-local-variable 'widget-mouse-face
) custom-button-mouse
)
4591 ;; When possible, use relief for buttons, not bracketing. This test
4592 ;; may not be optimal.
4593 (when custom-raised-buttons
4594 (set (make-local-variable 'widget-push-button-prefix
) "")
4595 (set (make-local-variable 'widget-push-button-suffix
) "")
4596 (set (make-local-variable 'widget-link-prefix
) "")
4597 (set (make-local-variable 'widget-link-suffix
) ""))
4598 (add-hook 'widget-edit-functions
'custom-state-buffer-message nil t
)
4599 (run-mode-hooks 'custom-mode-hook
))
4601 (put 'custom-mode
'mode-class
'special
)
4604 '("^No user option defaults have been changed since Emacs "
4606 "^No \\(?:customized\\|rogue\\|saved\\) user options"
4607 "^No customizable items matching "
4608 "^There are unset changes"
4609 "^Cannot set hidden variable"
4610 "^No \\(?:saved\\|backup\\) value for "
4611 "^No standard setting known for "
4612 "^No standard setting for this face"
4613 "^Saving settings from \"emacs -q\" would overwrite existing customizations"))
4614 (add-to-list 'debug-ignored-errors regexp
))
4620 ;; arch-tag: 64533aa4-1b1a-48c3-8812-f9dc718e8a6f
4621 ;;; cus-edit.el ends here