1 ;;; cus-edit.el --- tools for customizing Emacs and Lisp packages
3 ;; Copyright (C) 1996, 1997, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007 Free Software Foundation, Inc.
6 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
8 ;; Keywords: help, faces
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 3, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
29 ;; This file implements the code to create and edit customize buffers.
33 ;; No commands should have names starting with `custom-' because
34 ;; that interferes with completion. Use `customize-' for commands
35 ;; that the user will run with M-x, and `Custom-' for interactive commands.
37 ;; The identity of a customize option is represented by a Lisp symbol.
38 ;; The following values are associated with an option.
40 ;; 0. The current value.
42 ;; This is the value of the option as seen by "the rest of Emacs".
44 ;; Usually extracted by 'default-value', but can be extracted with
45 ;; different means if the option symbol has the 'custom-get'
46 ;; property. Similarly, set-default (or the 'custom-set' property)
49 ;; 1. The widget value.
51 ;; This is the value shown in the widget in a customize buffer.
53 ;; 2. The customized value.
55 ;; This is the last value given to the option through customize.
57 ;; It is stored in the 'customized-value' property of the option, in a
58 ;; cons-cell whose car evaluates to the customized value.
60 ;; 3. The saved value.
62 ;; This is last value saved from customize.
64 ;; It is stored in the 'saved-value' property of the option, in a
65 ;; cons-cell whose car evaluates to the saved value.
67 ;; 4. The standard value.
69 ;; This is the value given in the 'defcustom' declaration.
71 ;; It is stored in the 'standard-value' property of the option, in a
72 ;; cons-cell whose car evaluates to the standard value.
74 ;; 5. The "think" value.
76 ;; This is what customize thinks the current value should be.
78 ;; This is the customized value, if any such value exists, otherwise
79 ;; the saved value, if that exists, and as a last resort the standard
82 ;; The reason for storing values unevaluated: This is so you can have
83 ;; values that depend on the environment. For example, you can have a
84 ;; variable that has one value when Emacs is running under a window
85 ;; system, and another value on a tty. Since the evaluation is only done
86 ;; when the variable is first initialized, this is only relevant for the
87 ;; saved (and standard) values, but affect others values for
90 ;; You can see (and modify and save) this unevaluated value by selecting
91 ;; "Show Saved Lisp Expression" from the Lisp interface. This will
92 ;; give you the unevaluated saved value, if any, otherwise the
93 ;; unevaluated standard value.
95 ;; The possible states for a customize widget are:
99 ;; The state has not been determined yet.
103 ;; The widget value is different from the current value.
107 ;; The current value is different from the "think" value.
111 ;; The "think" value is the customized value.
115 ;; The "think" value is the saved value.
119 ;; The "think" value is the standard value.
123 ;; There is no standard value. This means that the variable was
124 ;; not defined with defcustom, nor handled in cus-start.el. Most
125 ;; standard interactive Custom commands do not let you create a
126 ;; Custom buffer containing such variables. However, such Custom
127 ;; buffers can be created, for instance, by calling
128 ;; `customize-apropos' with a prefix arg or by calling
129 ;; `customize-option' non-interactively.
133 ;; There is no widget value.
137 ;; The widget value is not valid member of the :type specified for the
145 (defvar custom-versions-load-alist
) ; from cus-load
146 (defvar recentf-exclude
) ; from recentf.el
156 (put 'custom-define-hook
'custom-type
'hook
)
157 (put 'custom-define-hook
'standard-value
'(nil))
158 (custom-add-to-group 'customize
'custom-define-hook
'custom-variable
)
160 ;;; Customization Groups.
163 "Customization of the One True Editor."
164 :link
'(custom-manual "(emacs)Top"))
166 ;; Most of these groups are stolen from `finder.el',
167 (defgroup editing nil
168 "Basic text editing facilities."
172 "Abbreviation handling, typing shortcuts, macros."
176 (defgroup matching nil
177 "Various sorts of searching and matching."
180 (defgroup emulations nil
181 "Emulations of other editors."
182 :link
'(custom-manual "(emacs)Emulation")
189 (defgroup outlines nil
190 "Support for hierarchical outlining."
193 (defgroup external nil
194 "Interfacing to external utilities."
197 (defgroup processes nil
198 "Process, subshell, compilation, and job control support."
202 (defgroup convenience nil
203 "Convenience features for faster editing."
206 (defgroup programming nil
207 "Support for programming in other languages."
210 (defgroup languages nil
211 "Specialized modes for editing programming languages."
215 "Lisp support, including Emacs Lisp."
216 :link
'(custom-group-link :tag
"Font Lock Faces group" font-lock-faces
)
221 "Support for the C language and related languages."
222 :link
'(custom-group-link :tag
"Font Lock Faces group" font-lock-faces
)
223 :link
'(custom-manual "(ccmode)")
231 "Support for object-oriented programming."
234 (defgroup applications nil
235 "Applications written in Emacs."
238 (defgroup calendar nil
239 "Calendar and time management support."
240 :group
'applications
)
243 "Modes for electronic-mail handling."
244 :group
'applications
)
247 "Support for netnews reading and posting."
248 :link
'(custom-manual "(gnus)")
249 :group
'applications
)
252 "Games, jokes and amusements."
253 :group
'applications
)
255 (defgroup development nil
256 "Support for further development of Emacs."
260 "Support for Emacs documentation."
263 (defgroup extensions nil
264 "Emacs Lisp language extensions."
267 (defgroup internal nil
268 "Code for Emacs internals, build process, defaults."
272 "Maintenance aids for the Emacs development group."
276 (defgroup environment nil
277 "Fitting Emacs with its environment."
281 "Communications, networking, remote access to files."
285 (defgroup hardware nil
286 "Support for interfacing with exotic hardware."
289 (defgroup terminals nil
290 "Support for terminal types."
294 "Front-ends/assistants for, or emulators of, UNIX features."
298 "Support code for vms."
302 "Internationalization and alternate character-set support."
303 :link
'(custom-manual "(emacs)International")
308 "The X Window system."
312 "Support for Emacs frames and window systems."
316 "Support editing files of data."
320 "Support editing files."
328 "Code related to the TeX formatter."
329 :link
'(custom-group-link :tag
"Font Lock Faces group" font-lock-faces
)
333 "Support for multiple fonts."
336 (defgroup hypermedia nil
337 "Support for links between text or other media types."
341 "Support for on-line help systems."
344 (defgroup multimedia nil
345 "Non-textual support, specifically images and sound."
349 "Code local to your site."
352 (defgroup customize
'((widgets custom-group
))
353 "Customization of the Customization support."
357 (defgroup custom-faces nil
358 "Faces used by customize."
362 (defgroup custom-browse nil
363 "Control customize browser."
367 (defgroup custom-buffer nil
368 "Control customize buffers."
372 (defgroup custom-menu nil
373 "Control customize menus."
377 (defgroup abbrev-mode nil
378 "Word abbreviations mode."
379 :link
'(custom-manual "(emacs)Abbrevs")
383 "Storage allocation and gc for GNU Emacs Lisp interpreter."
384 :tag
"Storage Allocation"
388 "Undoing changes in buffers."
389 :link
'(custom-manual "(emacs)Undo")
392 (defgroup mode-line nil
393 "Content of the modeline."
396 (defgroup editing-basics nil
397 "Most basic editing facilities."
400 (defgroup display nil
401 "How characters are displayed in buffers."
404 (defgroup execute nil
405 "Executing external commands."
408 (defgroup installation nil
409 "The Emacs installation."
417 "Internal Emacs limits."
421 "Debugging Emacs itself."
424 (defgroup minibuffer nil
425 "Controlling the behavior of the minibuffer."
426 :link
'(custom-manual "(emacs)Minibuffer")
429 (defgroup keyboard nil
430 "Input from the keyboard."
434 "Input from the mouse."
438 "Input from the menus."
442 "Handling data from drag and drop."
445 (defgroup auto-save nil
446 "Preventing accidental loss of data."
449 (defgroup processes-basics nil
450 "Basic stuff dealing with processes."
454 "MULE Emacs internationalization."
457 (defgroup windows nil
458 "Windows within a frame."
459 :link
'(custom-manual "(emacs)Windows")
463 "Mac specific features."
464 :link
'(custom-manual "(emacs)Mac OS")
469 ;;; Custom mode keymaps
471 (defvar custom-mode-map
472 ;; This keymap should be dense, but a dense keymap would prevent inheriting
473 ;; "\r" bindings from the parent map.
474 ;; Actually, this misfeature of dense keymaps was fixed on 2001-11-26.
475 (let ((map (make-keymap)))
476 (set-keymap-parent map widget-keymap
)
477 (define-key map
[remap self-insert-command
] 'Custom-no-edit
)
478 (define-key map
"\^m" 'Custom-newline
)
479 (define-key map
" " 'scroll-up
)
480 (define-key map
"\177" 'scroll-down
)
481 (define-key map
"\C-c\C-c" 'Custom-set
)
482 (define-key map
"\C-x\C-s" 'Custom-save
)
483 (define-key map
"q" 'Custom-buffer-done
)
484 (define-key map
"u" 'Custom-goto-parent
)
485 (define-key map
"n" 'widget-forward
)
486 (define-key map
"p" 'widget-backward
)
488 "Keymap for `custom-mode'.")
490 (defvar custom-mode-link-map
491 (let ((map (make-keymap)))
492 (set-keymap-parent map custom-mode-map
)
493 (define-key map
[down-mouse-2
] nil
)
494 (define-key map
[down-mouse-1
] 'mouse-drag-region
)
495 (define-key map
[mouse-2
] 'widget-move-and-invoke
)
497 "Local keymap for links in `custom-mode'.")
502 (defun custom-split-regexp-maybe (regexp)
503 "If REGEXP is a string, split it to a list at `\\|'.
504 You can get the original back from the result with:
505 (mapconcat 'identity result \"\\|\")
507 IF REGEXP is not a string, return it unchanged."
509 (split-string regexp
"\\\\|")
512 (defun custom-variable-prompt ()
513 "Prompt for a custom variable, defaulting to the variable at point.
514 Return a list suitable for use in `interactive'."
515 (let* ((v (variable-at-point))
516 (default (and (symbolp v
) (custom-variable-p v
) (symbol-name v
)))
517 (enable-recursive-minibuffers t
)
519 (setq val
(completing-read
520 (if default
(format "Customize variable (default %s): " default
)
521 "Customize variable: ")
522 obarray
'custom-variable-p t nil nil default
))
523 (list (if (equal val
"")
524 (if (symbolp v
) v nil
)
527 (defun custom-menu-filter (menu widget
)
528 "Convert MENU to the form used by `widget-choose'.
529 MENU should be in the same format as `custom-variable-menu'.
530 WIDGET is the widget to apply the filter entries of MENU on."
532 current name action filter
)
534 (setq current
(car menu
)
536 action
(nth 1 current
)
537 filter
(nth 2 current
)
539 (if (or (null filter
) (funcall filter widget
))
540 (push (cons name action
) result
)
546 (defvar custom-prefix-list nil
547 "List of prefixes that should be ignored by `custom-unlispify'.")
549 (defcustom custom-unlispify-menu-entries t
550 "Display menu entries as words instead of symbols if non-nil."
554 (defcustom custom-unlispify-remove-prefixes nil
555 "Non-nil means remove group prefixes from option names in buffer."
557 :group
'custom-buffer
560 (defun custom-unlispify-menu-entry (symbol &optional no-suffix
)
561 "Convert SYMBOL into a menu entry."
562 (cond ((not custom-unlispify-menu-entries
)
563 (symbol-name symbol
))
564 ((get symbol
'custom-tag
)
566 (get symbol
'custom-tag
)
567 (concat (get symbol
'custom-tag
) "...")))
569 (with-current-buffer (get-buffer-create " *Custom-Work*")
571 (princ symbol
(current-buffer))
572 (goto-char (point-min))
573 ;; FIXME: Boolean variables are not predicates, so they shouldn't
574 ;; end with `-p'. -stef
575 ;; (when (and (eq (get symbol 'custom-type) 'boolean)
576 ;; (re-search-forward "-p\\'" nil t))
577 ;; (replace-match "" t t)
578 ;; (goto-char (point-min)))
579 (if custom-unlispify-remove-prefixes
580 (let ((prefixes custom-prefix-list
)
583 (setq prefix
(car prefixes
))
584 (if (search-forward prefix
(+ (point) (length prefix
)) t
)
587 (delete-region (point-min) (point)))
588 (setq prefixes
(cdr prefixes
))))))
589 (subst-char-in-region (point-min) (point-max) ?- ?\ t
)
590 (capitalize-region (point-min) (point-max))
592 (goto-char (point-max))
596 (defcustom custom-unlispify-tag-names t
597 "Display tag names as words instead of symbols if non-nil."
598 :group
'custom-buffer
601 (defun custom-unlispify-tag-name (symbol)
602 "Convert SYMBOL into a menu entry."
603 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names
))
604 (custom-unlispify-menu-entry symbol t
)))
606 (defun custom-prefix-add (symbol prefixes
)
607 "Add SYMBOL to list of ignored PREFIXES."
608 (cons (or (get symbol
'custom-prefix
)
609 (concat (symbol-name symbol
) "-"))
614 (defcustom custom-guess-name-alist
620 ("-function\\'" function
)
621 ("-functions\\'" (repeat function
))
622 ("-list\\'" (repeat sexp
))
623 ("-alist\\'" (repeat (cons sexp sexp
))))
624 "Alist of (MATCH TYPE).
626 MATCH should be a regexp matching the name of a symbol, and TYPE should
627 be a widget suitable for editing the value of that symbol. The TYPE
628 of the first entry where MATCH matches the name of the symbol will be
631 This is used for guessing the type of variables not declared with
633 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
634 :group
'custom-buffer
)
636 (defcustom custom-guess-doc-alist
637 '(("\\`\\*?Non-nil " boolean
))
638 "Alist of (MATCH TYPE).
640 MATCH should be a regexp matching a documentation string, and TYPE
641 should be a widget suitable for editing the value of a variable with
642 that documentation string. The TYPE of the first entry where MATCH
643 matches the name of the symbol will be used.
645 This is used for guessing the type of variables not declared with
647 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
648 :group
'custom-buffer
)
650 (defun custom-guess-type (symbol)
651 "Guess a widget suitable for editing the value of SYMBOL.
652 This is done by matching SYMBOL with `custom-guess-name-alist' and
653 if that fails, the doc string with `custom-guess-doc-alist'."
654 (let ((name (symbol-name symbol
))
655 (names custom-guess-name-alist
)
658 (setq current
(car names
)
660 (when (string-match (nth 0 current
) name
)
661 (setq found
(nth 1 current
)
664 (let ((doc (documentation-property symbol
'variable-documentation
))
665 (docs custom-guess-doc-alist
))
668 (setq current
(car docs
)
670 (when (string-match (nth 0 current
) doc
)
671 (setq found
(nth 1 current
)
678 (defcustom custom-browse-sort-alphabetically nil
679 "If non-nil, sort customization group alphabetically in `custom-browse'."
681 :group
'custom-browse
)
683 (defcustom custom-browse-order-groups nil
684 "If non-nil, order group members within each customization group.
685 If `first', order groups before non-groups.
686 If `last', order groups after non-groups."
687 :type
'(choice (const first
)
689 (const :tag
"none" nil
))
690 :group
'custom-browse
)
692 (defcustom custom-browse-only-groups nil
693 "If non-nil, show group members only within each customization group."
695 :group
'custom-browse
)
698 (defcustom custom-buffer-sort-alphabetically nil
699 "If non-nil, sort each customization group alphabetically in Custom buffer."
701 :group
'custom-buffer
)
703 (defcustom custom-buffer-order-groups
'last
704 "If non-nil, order group members within each customization group.
705 If `first', order groups before non-groups.
706 If `last', order groups after non-groups."
707 :type
'(choice (const first
)
709 (const :tag
"none" nil
))
710 :group
'custom-buffer
)
713 (defcustom custom-menu-sort-alphabetically nil
714 "If non-nil, sort each customization group alphabetically in menus."
718 (defcustom custom-menu-order-groups
'first
719 "If non-nil, order group members within each customization group.
720 If `first', order groups before non-groups.
721 If `last', order groups after non-groups."
722 :type
'(choice (const first
)
724 (const :tag
"none" nil
))
727 ;;;###autoload (add-hook 'same-window-regexps "\\`\\*Customiz.*\\*\\'")
729 (defun custom-sort-items (items sort-alphabetically order-groups
)
730 "Return a sorted copy of ITEMS.
731 ITEMS should be a `custom-group' property.
732 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
733 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
734 groups after non-groups, if nil do not order groups at all."
735 (sort (copy-sequence items
)
737 (let ((typea (nth 1 a
)) (typeb (nth 1 b
))
738 (namea (nth 0 a
)) (nameb (nth 0 b
)))
739 (cond ((not order-groups
)
740 ;; Since we don't care about A and B order, maybe sort.
741 (when sort-alphabetically
742 (string-lessp namea nameb
)))
743 ((eq typea
'custom-group
)
744 ;; If B is also a group, maybe sort. Otherwise, order A and B.
745 (if (eq typeb
'custom-group
)
746 (when sort-alphabetically
747 (string-lessp namea nameb
))
748 (eq order-groups
'first
)))
749 ((eq typeb
'custom-group
)
750 ;; Since A cannot be a group, order A and B.
751 (eq order-groups
'last
))
753 ;; Since A and B cannot be groups, sort.
754 (string-lessp namea nameb
)))))))
756 ;;; Custom Mode Commands.
758 ;; This variable is used by `custom-tool-bar-map', or directly by
759 ;; `custom-buffer-create-internal' if the toolbar is not present and
760 ;; `custom-buffer-verbose-help' is non-nil.
762 (defvar custom-commands
763 '(("Set for current session" Custom-set t
764 "Apply all settings in this buffer to the current session"
766 ("Save for future sessions" Custom-save
767 (or custom-file user-init-file
)
768 "Apply all settings in this buffer and save them for future Emacs sessions."
770 ("Undo edits" Custom-reset-current t
771 "Restore all settings in this buffer to reflect their current values."
773 ("Reset to saved" Custom-reset-saved t
774 "Restore all settings in this buffer to their saved values (if any)."
776 ("Erase customizations" Custom-reset-standard
777 (or custom-file user-init-file
)
778 "Un-customize all settings in this buffer and save them with standard values."
780 ("Help for Customize" Custom-help t
781 "Get help for using Customize."
783 ("Exit" Custom-buffer-done t
"Exit Customize." "exit")))
785 (defun Custom-help ()
786 "Read the node on Easy Customization in the Emacs manual."
788 (info "(emacs)Easy Customization"))
790 (defvar custom-reset-menu
791 '(("Undo Edits" . Custom-reset-current
)
792 ("Reset to Saved" . Custom-reset-saved
)
793 ("Erase Customizations (use standard values)" . Custom-reset-standard
))
794 "Alist of actions for the `Reset' button.
795 The key is a string containing the name of the action, the value is a
796 Lisp function taking the widget as an element which will be called
797 when the action is chosen.")
799 (defvar custom-options nil
800 "Customization widgets in the current buffer.")
802 (defun custom-command-apply (fun query
&optional strong-query
)
803 "Call function FUN on all widgets in `custom-options'.
804 If there is more than one widget, ask user for confirmation using
805 the query string QUERY, using `y-or-n-p' if STRONG-QUERY is nil,
806 and `yes-or-no-p' otherwise."
807 (if (or (and (= 1 (length custom-options
))
808 (memq (widget-type (car custom-options
))
809 '(custom-variable custom-face
)))
810 (funcall (if strong-query
'yes-or-no-p
'y-or-n-p
) query
))
811 (progn (mapc fun custom-options
) t
)
815 (defun Custom-set (&rest ignore
)
816 "Set the current value of all edited settings in the buffer."
818 (custom-command-apply
820 (when (eq (widget-get child
:custom-state
) 'modified
)
821 (widget-apply child
:custom-set
)))
822 "Set all values according to this buffer? "))
824 (defun Custom-save (&rest ignore
)
825 "Set all edited settings, then save all settings that have been set.
826 If a setting was edited and set before, this saves it.
827 If a setting was merely edited before, this sets it then saves it."
829 (if (custom-command-apply
831 (when (memq (widget-get child
:custom-state
)
832 '(modified set changed rogue
))
833 (widget-apply child
:custom-save
)))
834 "Save all settings in this buffer? " t
)
837 (defun custom-reset (widget &optional event
)
838 "Select item from reset menu."
839 (let* ((completion-ignore-case t
)
840 (answer (widget-choose "Reset settings"
846 (defun Custom-reset-current (&rest ignore
)
847 "Reset all edited settings in the buffer to show their current values."
849 (custom-command-apply
851 (if (memq (widget-get widget
:custom-state
) '(modified changed
))
852 (widget-apply widget
:custom-reset-current
)))
853 "Reset all settings' buffer text to show current values? "))
855 (defun Custom-reset-saved (&rest ignore
)
856 "Reset all edited or set settings in the buffer to their saved value.
857 This also shows the saved values in the buffer."
859 (custom-command-apply
861 (if (memq (widget-get widget
:custom-state
) '(modified set changed rogue
))
862 (widget-apply widget
:custom-reset-saved
)))
863 "Reset all settings (current values and buffer text) to saved values? "))
865 (defun Custom-reset-standard (&rest ignore
)
866 "Erase all customization (either current or saved) for the group members.
867 The immediate result is to restore them to their standard values.
868 This operation eliminates any saved values for the group members,
869 making them as if they had never been customized at all."
871 (custom-command-apply
873 (and (or (null (widget-get widget
:custom-standard-value
))
874 (widget-apply widget
:custom-standard-value
))
875 (memq (widget-get widget
:custom-state
)
876 '(modified set changed saved rogue
))
877 (widget-apply widget
:custom-reset-standard
)))
878 "Erase all customizations for settings in this buffer? " t
))
880 ;;; The Customize Commands
882 (defun custom-prompt-variable (prompt-var prompt-val
&optional comment
)
883 "Prompt for a variable and a value and return them as a list.
884 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
885 prompt for the value. The %s escape in PROMPT-VAL is replaced with
886 the name of the variable.
888 If the variable has a `variable-interactive' property, that is used as if
889 it were the arg to `interactive' (which see) to interactively read the value.
891 If the variable has a `custom-type' property, it must be a widget and the
892 `:prompt-value' property of that widget will be used for reading the value.
894 If optional COMMENT argument is non-nil, also prompt for a comment and return
895 it as the third element in the list."
896 (let* ((var (read-variable prompt-var
))
897 (minibuffer-help-form '(describe-variable var
))
899 (let ((prop (get var
'variable-interactive
))
900 (type (get var
'custom-type
))
901 (prompt (format prompt-val var
)))
903 (setq type
(list type
)))
905 ;; Use VAR's `variable-interactive' property
906 ;; as an interactive spec for prompting.
907 (call-interactively `(lambda (arg)
911 (widget-prompt-value type
917 (eval-minibuffer prompt
))))))
920 (read-string "Comment: " (get var
'variable-comment
)))
924 (defun customize-set-value (variable value
&optional comment
)
925 "Set VARIABLE to VALUE, and return VALUE. VALUE is a Lisp object.
927 If VARIABLE has a `variable-interactive' property, that is used as if
928 it were the arg to `interactive' (which see) to interactively read the value.
930 If VARIABLE has a `custom-type' property, it must be a widget and the
931 `:prompt-value' property of that widget will be used for reading the value.
933 If given a prefix (or a COMMENT argument), also prompt for a comment."
934 (interactive (custom-prompt-variable "Set variable: "
938 (cond ((string= comment
"")
939 (put variable
'variable-comment nil
))
941 (put variable
'variable-comment comment
)))
942 (set variable value
))
945 (defun customize-set-variable (variable value
&optional comment
)
946 "Set the default for VARIABLE to VALUE, and return VALUE.
947 VALUE is a Lisp object.
949 If VARIABLE has a `custom-set' property, that is used for setting
950 VARIABLE, otherwise `set-default' is used.
952 If VARIABLE has a `variable-interactive' property, that is used as if
953 it were the arg to `interactive' (which see) to interactively read the value.
955 If VARIABLE has a `custom-type' property, it must be a widget and the
956 `:prompt-value' property of that widget will be used for reading the value.
958 If given a prefix (or a COMMENT argument), also prompt for a comment."
959 (interactive (custom-prompt-variable "Set variable: "
960 "Set customized value for %s to: "
962 (custom-load-symbol variable
)
963 (custom-push-theme 'theme-value variable
'user
'set
(custom-quote value
))
964 (funcall (or (get variable
'custom-set
) 'set-default
) variable value
)
965 (put variable
'customized-value
(list (custom-quote value
)))
966 (cond ((string= comment
"")
967 (put variable
'variable-comment nil
)
968 (put variable
'customized-variable-comment nil
))
970 (put variable
'variable-comment comment
)
971 (put variable
'customized-variable-comment comment
)))
975 (defun customize-save-variable (variable value
&optional comment
)
976 "Set the default for VARIABLE to VALUE, and save it for future sessions.
979 If VARIABLE has a `custom-set' property, that is used for setting
980 VARIABLE, otherwise `set-default' is used.
982 If VARIABLE has a `variable-interactive' property, that is used as if
983 it were the arg to `interactive' (which see) to interactively read the value.
985 If VARIABLE has a `custom-type' property, it must be a widget and the
986 `:prompt-value' property of that widget will be used for reading the value.
988 If given a prefix (or a COMMENT argument), also prompt for a comment."
989 (interactive (custom-prompt-variable "Set and save variable: "
990 "Set and save value for %s as: "
992 (funcall (or (get variable
'custom-set
) 'set-default
) variable value
)
993 (put variable
'saved-value
(list (custom-quote value
)))
994 (custom-push-theme 'theme-value variable
'user
'set
(custom-quote value
))
995 (cond ((string= comment
"")
996 (put variable
'variable-comment nil
)
997 (put variable
'saved-variable-comment nil
))
999 (put variable
'variable-comment comment
)
1000 (put variable
'saved-variable-comment comment
)))
1001 (put variable
'customized-value nil
)
1002 (put variable
'customized-variable-comment nil
)
1008 "Select a customization buffer which you can use to set user options.
1009 User options are structured into \"groups\".
1010 Initially the top-level group `Emacs' and its immediate subgroups
1011 are shown; the contents of those subgroups are initially hidden."
1013 (customize-group 'emacs
))
1016 (defun customize-mode (mode)
1017 "Customize options related to the current major mode.
1018 If a prefix \\[universal-argument] was given (or if the current major mode has no known group),
1019 then prompt for the MODE to customize."
1022 (let ((completion-regexp-list '("-mode\\'"))
1023 (group (custom-group-of-mode major-mode
)))
1024 (if (and group
(not current-prefix-arg
))
1027 (completing-read (if group
1028 (format "Major mode (default %s): " major-mode
)
1031 'custom-group-of-mode
1032 t nil nil
(if group
(symbol-name major-mode
))))))))
1033 (customize-group (custom-group-of-mode mode
)))
1035 (defun customize-read-group ()
1036 (let ((completion-ignore-case t
))
1037 (completing-read "Customize group (default emacs): "
1040 (or (and (get symbol
'custom-loads
)
1041 (not (get symbol
'custom-autoload
)))
1042 (get symbol
'custom-group
)))
1046 (defun customize-group (&optional group
)
1047 "Customize GROUP, which must be a customization group."
1048 (interactive (list (customize-read-group)))
1049 (when (stringp group
)
1050 (if (string-equal "" group
)
1052 (setq group
(intern group
))))
1053 (let ((name (format "*Customize Group: %s*"
1054 (custom-unlispify-tag-name group
))))
1055 (if (get-buffer name
)
1056 (pop-to-buffer name
)
1057 (custom-buffer-create
1058 (list (list group
'custom-group
))
1060 (concat " for group "
1061 (custom-unlispify-tag-name group
))))))
1064 (defun customize-group-other-window (&optional group
)
1065 "Customize GROUP, which must be a customization group, in another window."
1066 (interactive (list (customize-read-group)))
1067 (let ((pop-up-windows t
)
1068 (same-window-buffer-names nil
)
1069 (same-window-regexps nil
))
1070 (customize-group group
)))
1073 (defalias 'customize-variable
'customize-option
)
1076 (defun customize-option (symbol)
1077 "Customize SYMBOL, which must be a user option variable."
1078 (interactive (custom-variable-prompt))
1080 (error "No variable specified"))
1081 (let ((basevar (indirect-variable symbol
)))
1082 (custom-buffer-create (list (list basevar
'custom-variable
))
1083 (format "*Customize Option: %s*"
1084 (custom-unlispify-tag-name basevar
)))
1085 (unless (eq symbol basevar
)
1086 (message "`%s' is an alias for `%s'" symbol basevar
))))
1089 (defalias 'customize-variable-other-window
'customize-option-other-window
)
1092 (defun customize-option-other-window (symbol)
1093 "Customize SYMBOL, which must be a user option variable.
1094 Show the buffer in another window, but don't select it."
1095 (interactive (custom-variable-prompt))
1097 (error "No variable specified"))
1098 (let ((basevar (indirect-variable symbol
)))
1099 (custom-buffer-create-other-window
1100 (list (list basevar
'custom-variable
))
1101 (format "*Customize Option: %s*" (custom-unlispify-tag-name basevar
)))
1102 (unless (eq symbol basevar
)
1103 (message "`%s' is an alias for `%s'" symbol basevar
))))
1105 (defvar customize-changed-options-previous-release
"21.1"
1106 "Version for `customize-changed-options' to refer back to by default.")
1108 ;; Packages will update this variable, so make it available.
1110 (defvar customize-package-emacs-version-alist nil
1111 "Alist mapping versions of a package to Emacs versions.
1112 We use this for packages that have their own names, but are released
1113 as part of Emacs itself.
1115 Each elements looks like this:
1117 (PACKAGE (PVERSION . EVERSION)...)
1119 Here PACKAGE is the name of a package, as a symbol. After
1120 PACKAGE come one or more elements, each associating a
1121 package version PVERSION with the first Emacs version
1122 EVERSION in which it (or a subsequent version of PACKAGE)
1123 was first released. Both PVERSION and EVERSION are strings.
1124 PVERSION should be a string that this package used in
1125 the :package-version keyword for `defcustom', `defgroup',
1128 For example, the MH-E package updates this alist as follows:
1130 (add-to-list 'customize-package-emacs-version-alist
1131 '(MH-E (\"6.0\" . \"22.1\") (\"6.1\" . \"22.1\")
1132 (\"7.0\" . \"22.1\") (\"7.1\" . \"22.1\")
1133 (\"7.2\" . \"22.1\") (\"7.3\" . \"22.1\")
1134 (\"7.4\" . \"22.1\") (\"8.0\" . \"22.1\")))
1136 The value of PACKAGE needs to be unique and it needs to match the
1137 PACKAGE value appearing in the :package-version keyword. Since
1138 the user might see the value in a error message, a good choice is
1139 the official name of the package, such as MH-E or Gnus.")
1142 (defalias 'customize-changed
'customize-changed-options
)
1145 (defun customize-changed-options (since-version)
1146 "Customize all settings whose meanings have changed in Emacs itself.
1147 This includes new user option variables and faces, and new
1148 customization groups, as well as older options and faces whose meanings
1149 or default values have changed since the previous major Emacs release.
1151 With argument SINCE-VERSION (a string), customize all settings
1152 that were added or redefined since that version."
1156 (read-from-minibuffer
1157 (format "Customize options changed, since version (default %s): "
1158 customize-changed-options-previous-release
))))
1159 (if (equal since-version
"")
1160 (setq since-version nil
)
1161 (unless (condition-case nil
1162 (numberp (read since-version
))
1164 (signal 'wrong-type-argument
(list 'numberp since-version
))))
1165 (unless since-version
1166 (setq since-version customize-changed-options-previous-release
))
1168 ;; Load the information for versions since since-version. We use
1169 ;; custom-load-symbol for this.
1170 (put 'custom-versions-load-alist
'custom-loads nil
)
1171 (dolist (elt custom-versions-load-alist
)
1172 (if (customize-version-lessp since-version
(car elt
))
1173 (dolist (load (cdr elt
))
1174 (custom-add-load 'custom-versions-load-alist load
))))
1175 (custom-load-symbol 'custom-versions-load-alist
)
1176 (put 'custom-versions-load-alist
'custom-loads nil
)
1181 (let* ((package-version (get symbol
'custom-package-version
))
1183 (or (and package-version
1184 (customize-package-emacs-version symbol
1186 (get symbol
'custom-version
))))
1188 (when (customize-version-lessp since-version version
)
1189 (if (or (get symbol
'custom-group
)
1190 (get symbol
'group-documentation
))
1191 (push (list symbol
'custom-group
) found
))
1192 (if (custom-variable-p symbol
)
1193 (push (list symbol
'custom-variable
) found
))
1194 (if (custom-facep symbol
)
1195 (push (list symbol
'custom-face
) found
)))))))
1197 (custom-buffer-create (custom-sort-items found t
'first
)
1198 "*Customize Changed Options*")
1199 (error "No user option defaults have been changed since Emacs %s"
1202 (defun customize-package-emacs-version (symbol package-version
)
1203 "Return the Emacs version in which SYMBOL's meaning last changed.
1204 PACKAGE-VERSION has the form (PACKAGE . VERSION). We use
1205 `customize-package-emacs-version-alist' to find the version of
1206 Emacs that is associated with version VERSION of PACKAGE."
1207 (let (package-versions emacs-version
)
1208 ;; Use message instead of error since we want user to be able to
1209 ;; see the rest of the symbols even if a package author has
1210 ;; botched things up.
1211 (cond ((not (listp package-version
))
1212 (message "Invalid package-version value for %s" symbol
))
1213 ((setq package-versions
(assq (car package-version
)
1214 customize-package-emacs-version-alist
))
1216 (cdr (assoc (cdr package-version
) package-versions
)))
1217 (unless emacs-version
1218 (message "%s version %s not found in %s" symbol
1219 (cdr package-version
)
1220 "customize-package-emacs-version-alist")))
1222 (message "Package %s version %s lists no corresponding Emacs version"
1223 (car package-version
)
1224 (cdr package-version
))))
1227 (defun customize-version-lessp (version1 version2
)
1228 ;; Why are the versions strings, and given that they are, why aren't
1229 ;; they converted to numbers and compared as such here? -- fx
1231 ;; In case someone made a mistake and left out the quotes
1232 ;; in the :version value.
1233 (if (numberp version2
)
1234 (setq version2
(prin1-to-string version2
)))
1235 (let (major1 major2 minor1 minor2
)
1236 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version1
)
1237 (setq major1
(read (or (match-string 1 version1
)
1239 (setq minor1
(read (or (match-string 3 version1
)
1241 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version2
)
1242 (setq major2
(read (or (match-string 1 version2
)
1244 (setq minor2
(read (or (match-string 3 version2
)
1246 (or (< major1 major2
)
1247 (and (= major1 major2
)
1248 (< minor1 minor2
)))))
1251 (defun customize-face (&optional face
)
1252 "Customize FACE, which should be a face name or nil.
1253 If FACE is nil, customize all faces. If FACE is actually a
1254 face-alias, customize the face it is aliased to.
1256 Interactively, when point is on text which has a face specified,
1257 suggest to customize that face, if it's customizable."
1258 (interactive (list (read-face-name "Customize face" "all faces" t
)))
1259 (if (member face
'(nil ""))
1260 (setq face
(face-list)))
1261 (if (and (listp face
) (null (cdr face
)))
1262 (setq face
(car face
)))
1264 (custom-buffer-create
1266 (mapcar (lambda (s) (list s
'custom-face
)) face
)
1268 "*Customize Faces*")
1269 ;; If FACE is actually an alias, customize the face it is aliased to.
1270 (if (get face
'face-alias
)
1271 (setq face
(get face
'face-alias
)))
1272 (unless (facep face
)
1273 (error "Invalid face %S" face
))
1274 (custom-buffer-create
1275 (list (list face
'custom-face
))
1276 (format "*Customize Face: %s*"
1277 (custom-unlispify-tag-name face
)))))
1280 (defun customize-face-other-window (&optional face
)
1281 "Show customization buffer for face FACE in other window.
1282 If FACE is actually a face-alias, customize the face it is aliased to.
1284 Interactively, when point is on text which has a face specified,
1285 suggest to customize that face, if it's customizable."
1286 (interactive (list (read-face-name "Customize face" "all faces" t
)))
1287 (let ((pop-up-windows t
)
1288 (same-window-buffer-names nil
)
1289 (same-window-regexps nil
))
1290 (customize-face face
)))
1292 (defalias 'customize-customized
'customize-unsaved
)
1295 (defun customize-unsaved ()
1296 "Customize all user options set in this session but not saved."
1299 (mapatoms (lambda (symbol)
1300 (and (or (get symbol
'customized-face
)
1301 (get symbol
'customized-face-comment
))
1302 (custom-facep symbol
)
1303 (push (list symbol
'custom-face
) found
))
1304 (and (or (get symbol
'customized-value
)
1305 (get symbol
'customized-variable-comment
))
1307 (push (list symbol
'custom-variable
) found
))))
1309 (error "No user options are set but unsaved")
1310 (custom-buffer-create (custom-sort-items found t nil
)
1311 "*Customize Unsaved*"))))
1314 (defun customize-rogue ()
1315 "Customize all user variables modified outside customize."
1318 (mapatoms (lambda (symbol)
1319 (let ((cval (or (get symbol
'customized-value
)
1320 (get symbol
'saved-value
)
1321 (get symbol
'standard-value
))))
1322 (when (and cval
;Declared with defcustom.
1323 (default-boundp symbol
) ;Has a value.
1324 (not (equal (eval (car cval
))
1325 ;; Which does not match customize.
1326 (default-value symbol
))))
1327 (push (list symbol
'custom-variable
) found
)))))
1329 (error "No rogue user options")
1330 (custom-buffer-create (custom-sort-items found t nil
)
1331 "*Customize Rogue*"))))
1333 (defun customize-saved ()
1334 "Customize all already saved user options."
1337 (mapatoms (lambda (symbol)
1338 (and (or (get symbol
'saved-face
)
1339 (get symbol
'saved-face-comment
))
1340 (custom-facep symbol
)
1341 (push (list symbol
'custom-face
) found
))
1342 (and (or (get symbol
'saved-value
)
1343 (get symbol
'saved-variable-comment
))
1345 (push (list symbol
'custom-variable
) found
))))
1347 (error "No saved user options")
1348 (custom-buffer-create (custom-sort-items found t nil
)
1349 "*Customize Saved*"))))
1352 (defun customize-apropos (regexp &optional all
)
1353 "Customize all loaded options, faces and groups matching REGEXP.
1354 If ALL is `options', include only options.
1355 If ALL is `faces', include only faces.
1356 If ALL is `groups', include only groups.
1357 If ALL is t (interactively, with prefix arg), include variables
1358 that are not customizable options, as well as faces and groups
1359 \(but we recommend using `apropos-variable' instead)."
1360 (interactive "sCustomize (regexp): \nP")
1362 (mapatoms (lambda (symbol)
1363 (when (string-match regexp
(symbol-name symbol
))
1364 (when (and (not (memq all
'(faces options
)))
1365 (get symbol
'custom-group
))
1366 (push (list symbol
'custom-group
) found
))
1367 (when (and (not (memq all
'(options groups
)))
1368 (custom-facep symbol
))
1369 (push (list symbol
'custom-face
) found
))
1370 (when (and (not (memq all
'(groups faces
)))
1372 (eq (indirect-variable symbol
) symbol
)
1373 (or (get symbol
'saved-value
)
1374 (custom-variable-p symbol
)
1375 (and (not (memq all
'(nil options
)))
1376 (get symbol
'variable-documentation
))))
1377 (push (list symbol
'custom-variable
) found
)))))
1379 (error "No %s matching %s"
1382 (format "customizable %s"
1383 (if (memq all
'(options faces groups
))
1387 (custom-buffer-create
1388 (custom-sort-items found t custom-buffer-order-groups
)
1389 "*Customize Apropos*"))))
1392 (defun customize-apropos-options (regexp &optional arg
)
1393 "Customize all loaded customizable options matching REGEXP.
1394 With prefix arg, include variables that are not customizable options
1395 \(but we recommend using `apropos-variable' instead)."
1396 (interactive "sCustomize options (regexp): \nP")
1397 (customize-apropos regexp
(or arg
'options
)))
1400 (defun customize-apropos-faces (regexp)
1401 "Customize all loaded faces matching REGEXP."
1402 (interactive "sCustomize faces (regexp): \n")
1403 (customize-apropos regexp
'faces
))
1406 (defun customize-apropos-groups (regexp)
1407 "Customize all loaded groups matching REGEXP."
1408 (interactive "sCustomize groups (regexp): \n")
1409 (customize-apropos regexp
'groups
))
1413 (defcustom custom-buffer-style
'links
1414 "Control the presentation style for customization buffers.
1415 The value should be a symbol, one of:
1417 brackets: groups nest within each other with big horizontal brackets.
1418 links: groups have links to subgroups."
1419 :type
'(radio (const brackets
)
1421 :group
'custom-buffer
)
1423 (defcustom custom-buffer-done-kill nil
1424 "*Non-nil means exiting a Custom buffer should kill it."
1427 :group
'custom-buffer
)
1429 (defcustom custom-buffer-indent
3
1430 "Number of spaces to indent nested groups."
1432 :group
'custom-buffer
)
1434 (defun custom-get-fresh-buffer (name)
1435 "Get a fresh new buffer with name NAME.
1436 If the buffer already exist, clean it up to be like new.
1437 Beware: it's not quite like new. Good enough for custom, but maybe
1439 ;; To be more complete, we should also kill all permanent-local variables,
1440 ;; but it's not needed for custom.
1441 (let ((buf (get-buffer name
)))
1442 (when (and buf
(buffer-local-value 'buffer-file-name buf
))
1443 ;; This will check if the file is not saved.
1447 (get-buffer-create name
)
1448 (with-current-buffer buf
1449 (kill-all-local-variables)
1450 (run-hooks 'kill-buffer-hook
)
1451 ;; Delete overlays before erasing the buffer so the overlay hooks
1452 ;; don't get run spuriously when we erase the buffer.
1453 (let ((ols (overlay-lists)))
1454 (dolist (ol (nconc (car ols
) (cdr ols
)))
1455 (delete-overlay ol
)))
1460 (defun custom-buffer-create (options &optional name description
)
1461 "Create a buffer containing OPTIONS.
1462 Optional NAME is the name of the buffer.
1463 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1464 SYMBOL is a customization option, and WIDGET is a widget for editing
1466 (pop-to-buffer (custom-get-fresh-buffer (or name
"*Customization*")))
1467 (custom-buffer-create-internal options description
))
1470 (defun custom-buffer-create-other-window (options &optional name description
)
1471 "Create a buffer containing OPTIONS, and display it in another window.
1472 The result includes selecting that window.
1473 Optional NAME is the name of the buffer.
1474 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1475 SYMBOL is a customization option, and WIDGET is a widget for editing
1477 (unless name
(setq name
"*Customization*"))
1478 (let ((pop-up-windows t
)
1479 (same-window-buffer-names nil
)
1480 (same-window-regexps nil
))
1481 (pop-to-buffer (custom-get-fresh-buffer name
))
1482 (custom-buffer-create-internal options description
)))
1484 (defcustom custom-reset-button-menu nil
1485 "If non-nil, only show a single reset button in customize buffers.
1486 This button will have a menu with all three reset operations."
1488 :group
'custom-buffer
)
1490 (defcustom custom-buffer-verbose-help t
1491 "If non-nil, include explanatory text in the customization buffer."
1493 :group
'custom-buffer
)
1495 (defun Custom-buffer-done (&rest ignore
)
1496 "Exit current Custom buffer according to `custom-buffer-done-kill'."
1498 (quit-window custom-buffer-done-kill
))
1500 (defvar custom-button nil
1501 "Face used for buttons in customization buffers.")
1503 (defvar custom-button-mouse nil
1504 "Mouse face used for buttons in customization buffers.")
1506 (defvar custom-button-pressed nil
1507 "Face used for pressed buttons in customization buffers.")
1509 (defcustom custom-raised-buttons
(not (equal (face-valid-attribute-values :box
)
1510 '(("unspecified" . unspecified
))))
1511 "If non-nil, indicate active buttons in a `raised-button' style.
1512 Otherwise use brackets."
1515 :group
'custom-buffer
1516 :set
(lambda (variable value
)
1517 (custom-set-default variable value
)
1519 (if value
'custom-button
'custom-button-unraised
))
1520 (setq custom-button-mouse
1521 (if value
'custom-button-mouse
'highlight
))
1522 (setq custom-button-pressed
1524 'custom-button-pressed
1525 'custom-button-pressed-unraised
))))
1527 (defun custom-buffer-create-internal (options &optional description
)
1529 (let ((init-file (or custom-file user-init-file
)))
1530 ;; Insert verbose help at the top of the custom buffer.
1531 (when custom-buffer-verbose-help
1532 (widget-insert "Editing a setting changes only the text in this buffer."
1535 To set apply your changes, use the Save or Set buttons.
1536 Saving a change normally works by editing your init file."
1538 Currently, these settings cannot be saved for future Emacs sessions,
1539 possibly because you started Emacs with `-q'.")
1540 "\nFor details, see ")
1541 (widget-create 'custom-manual
1542 :tag
"Saving Customizations"
1543 "(emacs)Saving Customizations")
1544 (widget-insert " in the ")
1545 (widget-create 'custom-manual
1547 :help-echo
"Read the Emacs manual."
1549 (widget-insert "."))
1550 ;; Insert custom command buttons if the toolbar is not in use.
1552 (widget-insert "\n")
1553 ;; tool-bar is not dumped in builds without x.
1554 (when (not (and (bound-and-true-p tool-bar-mode
) (display-graphic-p)))
1555 (if custom-buffer-verbose-help
1557 Operate on all settings in this buffer that are not marked HIDDEN:\n"))
1558 (let ((button (lambda (tag action active help icon
)
1561 (widget-create 'push-button
:tag tag
1562 :help-echo help
:action action
))))
1563 (commands custom-commands
))
1564 (apply button
(pop commands
)) ; Set for current session
1565 (apply button
(pop commands
)) ; Save for future sessions
1566 (if custom-reset-button-menu
1569 (widget-create 'push-button
1571 :help-echo
"Show a menu with reset operations."
1572 :mouse-down-action
'ignore
1573 :action
'custom-reset
))
1574 (widget-insert "\n")
1575 (apply button
(pop commands
)) ; Undo edits
1576 (apply button
(pop commands
)) ; Reset to saved
1577 (apply button
(pop commands
)) ; Erase customization
1579 (pop commands
) ; Help (omitted)
1580 (apply button
(pop commands
))))) ; Exit
1581 (widget-insert "\n\n"))
1583 ;; Now populate the custom buffer.
1584 (message "Creating customization items...")
1585 (buffer-disable-undo)
1586 (setq custom-options
1587 (if (= (length options
) 1)
1588 (mapcar (lambda (entry)
1589 (widget-create (nth 1 entry
)
1590 :documentation-shown t
1591 :custom-state
'unknown
1592 :tag
(custom-unlispify-tag-name
1594 :value
(nth 0 entry
)))
1597 (length (length options
)))
1598 (mapcar (lambda (entry)
1600 (message "Creating customization items ...%2d%%"
1601 (/ (* 100.0 count
) length
))
1602 (widget-create (nth 1 entry
)
1603 :tag
(custom-unlispify-tag-name
1605 :value
(nth 0 entry
))
1606 (setq count
(1+ count
))
1607 (unless (eq (preceding-char) ?
\n)
1608 (widget-insert "\n"))
1609 (widget-insert "\n")))
1611 (unless (eq (preceding-char) ?
\n)
1612 (widget-insert "\n"))
1613 (message "Creating customization items ...done")
1614 (message "Resetting customization items...")
1615 (unless (eq custom-buffer-style
'tree
)
1616 (mapc 'custom-magic-reset custom-options
))
1617 (message "Resetting customization items...done")
1618 (message "Creating customization setup...")
1620 (buffer-enable-undo)
1621 (goto-char (point-min))
1622 (message "Creating customization setup...done"))
1624 ;;; The Tree Browser.
1627 (defun customize-browse (&optional group
)
1628 "Create a tree browser for the customize hierarchy."
1631 (setq group
'emacs
))
1632 (let ((name "*Customize Browser*"))
1633 (pop-to-buffer (custom-get-fresh-buffer name
)))
1635 (widget-insert (format "\
1636 %s buttons; type RET or click mouse-1
1637 on a button to invoke its action.
1638 Invoke [+] to expand a group, and [-] to collapse an expanded group.\n"
1639 (if custom-raised-buttons
1640 "`Raised' text indicates"
1641 "Square brackets indicate")))
1644 (if custom-browse-only-groups
1646 Invoke the [Group] button below to edit that item in another window.\n\n")
1647 (widget-insert "Invoke the ")
1648 (widget-create 'item
1651 :tag-glyph
"folder")
1652 (widget-insert ", ")
1653 (widget-create 'item
1657 (widget-insert ", and ")
1658 (widget-create 'item
1661 :tag-glyph
"option")
1662 (widget-insert " buttons below to edit that
1663 item in another window.\n\n"))
1664 (let ((custom-buffer-style 'tree
))
1665 (widget-create 'custom-group
1667 :custom-state
'unknown
1668 :tag
(custom-unlispify-tag-name group
)
1671 (goto-char (point-min)))
1673 (define-widget 'custom-browse-visibility
'item
1674 "Control visibility of items in the customize tree browser."
1676 :action
'custom-browse-visibility-action
)
1678 (defun custom-browse-visibility-action (widget &rest ignore
)
1679 (let ((custom-buffer-style 'tree
))
1680 (custom-toggle-parent widget
)))
1682 (define-widget 'custom-browse-group-tag
'custom-group-link
1683 "Show parent in other window when activated."
1686 :action
'custom-browse-group-tag-action
)
1688 (defun custom-browse-group-tag-action (widget &rest ignore
)
1689 (let ((parent (widget-get widget
:parent
)))
1690 (customize-group-other-window (widget-value parent
))))
1692 (define-widget 'custom-browse-variable-tag
'custom-group-link
1693 "Show parent in other window when activated."
1696 :action
'custom-browse-variable-tag-action
)
1698 (defun custom-browse-variable-tag-action (widget &rest ignore
)
1699 (let ((parent (widget-get widget
:parent
)))
1700 (customize-variable-other-window (widget-value parent
))))
1702 (define-widget 'custom-browse-face-tag
'custom-group-link
1703 "Show parent in other window when activated."
1706 :action
'custom-browse-face-tag-action
)
1708 (defun custom-browse-face-tag-action (widget &rest ignore
)
1709 (let ((parent (widget-get widget
:parent
)))
1710 (customize-face-other-window (widget-value parent
))))
1712 (defconst custom-browse-alist
'((" " "space")
1718 (defun custom-browse-insert-prefix (prefix)
1719 "Insert PREFIX. On XEmacs convert it to line graphics."
1720 ;; Fixme: do graphics.
1721 (if nil
; (string-match "XEmacs" emacs-version)
1724 (while (not (string-equal prefix
""))
1725 (let ((entry (substring prefix
0 3)))
1726 (setq prefix
(substring prefix
3))
1727 (let ((overlay (make-overlay (1- (point)) (point) nil t nil
))
1728 (name (nth 1 (assoc entry custom-browse-alist
))))
1729 (overlay-put overlay
'end-glyph
(widget-glyph-find name entry
))
1730 (overlay-put overlay
'start-open t
)
1731 (overlay-put overlay
'end-open t
)))))
1734 ;;; Modification of Basic Widgets.
1736 ;; We add extra properties to the basic widgets needed here. This is
1737 ;; fine, as long as we are careful to stay within out own namespace.
1739 ;; We want simple widgets to be displayed by default, but complex
1740 ;; widgets to be hidden.
1742 (widget-put (get 'item
'widget-type
) :custom-show t
)
1743 (widget-put (get 'editable-field
'widget-type
)
1744 :custom-show
(lambda (widget value
)
1745 (let ((pp (pp-to-string value
)))
1746 (cond ((string-match "\n" pp
)
1751 (widget-put (get 'menu-choice
'widget-type
) :custom-show t
)
1753 ;;; The `custom-manual' Widget.
1755 (define-widget 'custom-manual
'info-link
1756 "Link to the manual entry for this customization option."
1757 :help-echo
"Read the manual entry for this option."
1758 :keymap custom-mode-link-map
1759 :follow-link
'mouse-face
1760 :button-face
'custom-link
1761 :mouse-face
'highlight
1762 :pressed-face
'highlight
1765 ;;; The `custom-magic' Widget.
1767 (defgroup custom-magic-faces nil
1768 "Faces used by the magic button."
1769 :group
'custom-faces
1770 :group
'custom-buffer
)
1772 (defface custom-invalid
'((((class color
))
1773 (:foreground
"yellow1" :background
"red1"))
1775 (:weight bold
:slant italic
:underline t
)))
1776 "Face used when the customize item is invalid."
1777 :group
'custom-magic-faces
)
1778 ;; backward-compatibility alias
1779 (put 'custom-invalid-face
'face-alias
'custom-invalid
)
1781 (defface custom-rogue
'((((class color
))
1782 (:foreground
"pink" :background
"black"))
1785 "Face used when the customize item is not defined for customization."
1786 :group
'custom-magic-faces
)
1787 ;; backward-compatibility alias
1788 (put 'custom-rogue-face
'face-alias
'custom-rogue
)
1790 (defface custom-modified
'((((min-colors 88) (class color
))
1791 (:foreground
"white" :background
"blue1"))
1793 (:foreground
"white" :background
"blue"))
1795 (:slant italic
:bold
)))
1796 "Face used when the customize item has been modified."
1797 :group
'custom-magic-faces
)
1798 ;; backward-compatibility alias
1799 (put 'custom-modified-face
'face-alias
'custom-modified
)
1801 (defface custom-set
'((((min-colors 88) (class color
))
1802 (:foreground
"blue1" :background
"white"))
1804 (:foreground
"blue" :background
"white"))
1807 "Face used when the customize item has been set."
1808 :group
'custom-magic-faces
)
1809 ;; backward-compatibility alias
1810 (put 'custom-set-face
'face-alias
'custom-set
)
1812 (defface custom-changed
'((((min-colors 88) (class color
))
1813 (:foreground
"white" :background
"blue1"))
1815 (:foreground
"white" :background
"blue"))
1818 "Face used when the customize item has been changed."
1819 :group
'custom-magic-faces
)
1820 ;; backward-compatibility alias
1821 (put 'custom-changed-face
'face-alias
'custom-changed
)
1823 (defface custom-themed
'((((min-colors 88) (class color
))
1824 (:foreground
"white" :background
"blue1"))
1826 (:foreground
"white" :background
"blue"))
1829 "Face used when the customize item has been set by a theme."
1830 :group
'custom-magic-faces
)
1832 (defface custom-saved
'((t (:underline t
)))
1833 "Face used when the customize item has been saved."
1834 :group
'custom-magic-faces
)
1835 ;; backward-compatibility alias
1836 (put 'custom-saved-face
'face-alias
'custom-saved
)
1838 (defconst custom-magic-alist
1839 '((nil "#" underline
"\
1840 UNINITIALIZED, you should not see this.")
1841 (unknown "?" italic
"\
1842 UNKNOWN, you should not see this.")
1843 (hidden "-" default
"\
1844 HIDDEN, invoke \"Show\" in the previous line to show." "\
1845 group now hidden, invoke \"Show\", above, to show contents.")
1846 (invalid "x" custom-invalid
"\
1847 INVALID, the displayed value cannot be set.")
1848 (modified "*" custom-modified
"\
1849 EDITED, shown value does not take effect until you set or save it." "\
1850 something in this group has been edited but not set.")
1851 (set "+" custom-set
"\
1852 SET for current session only." "\
1853 something in this group has been set but not saved.")
1854 (changed ":" custom-changed
"\
1855 CHANGED outside Customize; operating on it here may be unreliable." "\
1856 something in this group has been changed outside customize.")
1857 (saved "!" custom-saved
"\
1859 something in this group has been set and saved.")
1860 (themed "o" custom-themed
"\
1862 visible group members are all at standard values.")
1863 (rogue "@" custom-rogue
"\
1864 NO CUSTOMIZATION DATA; not intended to be customized." "\
1865 something in this group is not prepared for customization.")
1866 (standard " " nil
"\
1868 visible group members are all at standard values."))
1869 "Alist of customize option states.
1870 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1872 STATE is one of the following symbols:
1875 For internal use, should never occur.
1877 For internal use, should never occur.
1879 This item is not being displayed.
1881 This item is modified, but has an invalid form.
1883 This item is modified, and has a valid form.
1885 This item has been set but not saved.
1887 The current value of this item has been changed outside Customize.
1889 This item is marked for saving.
1891 This item has no customization information.
1893 This item is unchanged from the standard setting.
1895 MAGIC is a string used to present that state.
1897 FACE is a face used to present the state.
1899 ITEM-DESC is a string describing the state for options.
1901 GROUP-DESC is a string describing the state for groups. If this is
1902 left out, ITEM-DESC will be used.
1904 The string %c in either description will be replaced with the
1905 category of the item. These are `group'. `option', and `face'.
1907 The list should be sorted most significant first.")
1909 (defcustom custom-magic-show
'long
1910 "If non-nil, show textual description of the state.
1911 If `long', show a full-line description, not just one word."
1912 :type
'(choice (const :tag
"no" nil
)
1914 (other :tag
"short" short
))
1915 :group
'custom-buffer
)
1917 (defcustom custom-magic-show-hidden
'(option face
)
1918 "Control whether the State button is shown for hidden items.
1919 The value should be a list with the custom categories where the State
1920 button should be visible. Possible categories are `group', `option',
1922 :type
'(set (const group
) (const option
) (const face
))
1923 :group
'custom-buffer
)
1925 (defcustom custom-magic-show-button nil
1926 "Show a \"magic\" button indicating the state of each customization option."
1928 :group
'custom-buffer
)
1930 (define-widget 'custom-magic
'default
1931 "Show and manipulate state for a customization option."
1933 :action
'widget-parent-action
1936 :value-create
'custom-magic-value-create
1937 :value-delete
'widget-children-value-delete
)
1939 (defun widget-magic-mouse-down-action (widget &optional event
)
1940 ;; Non-nil unless hidden.
1941 (not (eq (widget-get (widget-get (widget-get widget
:parent
) :parent
)
1945 (defun custom-magic-value-create (widget)
1946 "Create compact status report for WIDGET."
1947 (let* ((parent (widget-get widget
:parent
))
1948 (state (widget-get parent
:custom-state
))
1949 (hidden (eq state
'hidden
))
1950 (entry (assq state custom-magic-alist
))
1951 (magic (nth 1 entry
))
1952 (face (nth 2 entry
))
1953 (category (widget-get parent
:custom-category
))
1954 (text (or (and (eq category
'group
)
1957 (form (widget-get parent
:custom-form
))
1959 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text
)
1960 (setq text
(concat (match-string 1 text
)
1961 (symbol-name category
)
1962 (match-string 2 text
))))
1963 (when (and custom-magic-show
1965 (memq category custom-magic-show-hidden
)))
1967 (when (and (eq category
'group
)
1968 (not (and (eq custom-buffer-style
'links
)
1969 (> (widget-get parent
:custom-level
) 1))))
1970 (insert-char ?\
(* custom-buffer-indent
1971 (widget-get parent
:custom-level
))))
1972 (push (widget-create-child-and-convert
1974 :help-echo
"Change the state of this item."
1975 :format
(if hidden
"%t" "%[%t%]")
1976 :button-prefix
'widget-push-button-prefix
1977 :button-suffix
'widget-push-button-suffix
1978 :mouse-down-action
'widget-magic-mouse-down-action
1982 (let ((start (point)))
1983 (if (eq custom-magic-show
'long
)
1985 (insert (symbol-name state
)))
1986 (cond ((eq form
'lisp
)
1988 ((eq form
'mismatch
)
1989 (insert " (mismatch)")))
1990 (put-text-property start
(point) 'face
'custom-state
))
1992 (when (and (eq category
'group
)
1993 (not (and (eq custom-buffer-style
'links
)
1994 (> (widget-get parent
:custom-level
) 1))))
1995 (insert-char ?\
(* custom-buffer-indent
1996 (widget-get parent
:custom-level
))))
1997 (when custom-magic-show-button
1998 (when custom-magic-show
1999 (let ((indent (widget-get parent
:indent
)))
2001 (insert-char ? indent
))))
2002 (push (widget-create-child-and-convert
2004 :mouse-down-action
'widget-magic-mouse-down-action
2008 :help-echo
"Change the state."
2009 :format
(if hidden
"%t" "%[%t%]")
2010 :tag
(if (memq form
'(lisp mismatch
))
2011 (concat "(" magic
")")
2012 (concat "[" magic
"]")))
2015 (widget-put widget
:children children
)))
2017 (defun custom-magic-reset (widget)
2018 "Redraw the :custom-magic property of WIDGET."
2019 (let ((magic (widget-get widget
:custom-magic
)))
2020 (widget-value-set magic
(widget-value magic
))))
2022 ;;; The `custom' Widget.
2024 (defface custom-button
2025 '((((type x w32 mac
) (class color
)) ; Like default modeline
2026 (:box
(:line-width
2 :style released-button
)
2027 :background
"lightgrey" :foreground
"black"))
2030 "Face for custom buffer buttons if `custom-raised-buttons' is non-nil."
2032 :group
'custom-faces
)
2033 ;; backward-compatibility alias
2034 (put 'custom-button-face
'face-alias
'custom-button
)
2036 (defface custom-button-mouse
2037 '((((type x w32 mac
) (class color
))
2038 (:box
(:line-width
2 :style released-button
)
2039 :background
"grey90" :foreground
"black"))
2042 "Mouse face for custom buffer buttons if `custom-raised-buttons' is non-nil."
2044 :group
'custom-faces
)
2046 (defface custom-button-unraised
2047 '((t :inherit underline
))
2048 "Face for custom buffer buttons if `custom-raised-buttons' is nil."
2050 :group
'custom-faces
)
2053 (if custom-raised-buttons
'custom-button
'custom-button-unraised
))
2055 (setq custom-button-mouse
2056 (if custom-raised-buttons
'custom-button-mouse
'highlight
))
2058 (defface custom-button-pressed
2059 '((((type x w32 mac
) (class color
))
2060 (:box
(:line-width
2 :style pressed-button
)
2061 :background
"lightgrey" :foreground
"black"))
2063 (:inverse-video t
)))
2064 "Face for pressed custom buttons if `custom-raised-buttons' is non-nil."
2066 :group
'custom-faces
)
2067 ;; backward-compatibility alias
2068 (put 'custom-button-pressed-face
'face-alias
'custom-button-pressed
)
2070 (defface custom-button-pressed-unraised
2071 '((default :inherit custom-button-unraised
)
2072 (((class color
) (background light
)) :foreground
"magenta4")
2073 (((class color
) (background dark
)) :foreground
"violet"))
2074 "Face for pressed custom buttons if `custom-raised-buttons' is nil."
2076 :group
'custom-faces
)
2078 (setq custom-button-pressed
2079 (if custom-raised-buttons
2080 'custom-button-pressed
2081 'custom-button-pressed-unraised
))
2083 (defface custom-documentation
'((t nil
))
2084 "Face used for documentation strings in customization buffers."
2085 :group
'custom-faces
)
2086 ;; backward-compatibility alias
2087 (put 'custom-documentation-face
'face-alias
'custom-documentation
)
2089 (defface custom-state
'((((class color
)
2091 (:foreground
"lime green"))
2094 (:foreground
"dark green"))
2096 "Face used for State descriptions in the customize buffer."
2097 :group
'custom-faces
)
2098 ;; backward-compatibility alias
2099 (put 'custom-state-face
'face-alias
'custom-state
)
2101 (defface custom-link
2102 '((t :inherit link
))
2103 "Face for links in customization buffers."
2105 :group
'custom-faces
)
2107 (define-widget 'custom
'default
2108 "Customize a user option."
2110 :convert-widget
'custom-convert-widget
2111 :notify
'custom-notify
2114 :custom-state
'hidden
2115 :documentation-property
'widget-subclass-responsibility
2116 :value-create
'widget-subclass-responsibility
2117 :value-delete
'widget-children-value-delete
2118 :value-get
'widget-value-value-get
2119 :validate
'widget-children-validate
2120 :match
(lambda (widget value
) (symbolp value
)))
2122 (defun custom-convert-widget (widget)
2123 "Initialize :value and :tag from :args in WIDGET."
2124 (let ((args (widget-get widget
:args
)))
2126 (widget-put widget
:value
(widget-apply widget
2127 :value-to-internal
(car args
)))
2128 (widget-put widget
:tag
(custom-unlispify-tag-name (car args
)))
2129 (widget-put widget
:args nil
)))
2132 (defun custom-notify (widget &rest args
)
2133 "Keep track of changes."
2134 (let ((state (widget-get widget
:custom-state
)))
2135 (unless (eq state
'modified
)
2136 (unless (memq state
'(nil unknown hidden
))
2137 (widget-put widget
:custom-state
'modified
))
2138 (custom-magic-reset widget
)
2139 (apply 'widget-default-notify widget args
))))
2141 (defun custom-redraw (widget)
2142 "Redraw WIDGET with current settings."
2143 (let ((line (count-lines (point-min) (point)))
2144 (column (current-column))
2146 (from (marker-position (widget-get widget
:from
)))
2147 (to (marker-position (widget-get widget
:to
))))
2149 (widget-value-set widget
(widget-value widget
))
2150 (custom-redraw-magic widget
))
2151 (when (and (>= pos from
) (<= pos to
))
2156 (goto-line (1+ line
)))
2157 (move-to-column column
))
2160 (defun custom-redraw-magic (widget)
2161 "Redraw WIDGET state with current settings."
2163 (let ((magic (widget-get widget
:custom-magic
)))
2165 (widget-value-set magic
(widget-value magic
))
2166 (when (setq widget
(widget-get widget
:group
))
2167 (custom-group-state-update widget
)))
2169 (setq widget nil
)))))
2172 (defun custom-show (widget value
)
2173 "Non-nil if WIDGET should be shown with VALUE by default."
2174 (let ((show (widget-get widget
:custom-show
)))
2180 (funcall show widget value
)))))
2182 (defun custom-load-widget (widget)
2183 "Load all dependencies for WIDGET."
2184 (custom-load-symbol (widget-value widget
)))
2186 (defun custom-unloaded-symbol-p (symbol)
2187 "Return non-nil if the dependencies of SYMBOL have not yet been loaded."
2189 (loads (get symbol
'custom-loads
))
2192 (setq load
(car loads
)
2194 (cond ((symbolp load
)
2195 (unless (featurep load
)
2197 ((assoc load load-history
))
2198 ((assoc (locate-library load
) load-history
)
2204 (defun custom-unloaded-widget-p (widget)
2205 "Return non-nil if the dependencies of WIDGET have not yet been loaded."
2206 (custom-unloaded-symbol-p (widget-value widget
)))
2208 (defun custom-toggle-hide (widget)
2209 "Toggle visibility of WIDGET."
2210 (custom-load-widget widget
)
2211 (let ((state (widget-get widget
:custom-state
)))
2212 (cond ((memq state
'(invalid modified
))
2213 (error "There are unset changes"))
2215 (widget-put widget
:custom-state
'unknown
))
2217 (widget-put widget
:documentation-shown nil
)
2218 (widget-put widget
:custom-state
'hidden
)))
2219 (custom-redraw widget
)
2222 (defun custom-toggle-parent (widget &rest ignore
)
2223 "Toggle visibility of parent of WIDGET."
2224 (custom-toggle-hide (widget-get widget
:parent
)))
2226 (defun custom-add-see-also (widget &optional prefix
)
2227 "Add `See also ...' to WIDGET if there are any links.
2228 Insert PREFIX first if non-nil."
2229 (let* ((symbol (widget-get widget
:value
))
2230 (links (get symbol
'custom-links
))
2231 (many (> (length links
) 2))
2232 (buttons (widget-get widget
:buttons
))
2233 (indent (widget-get widget
:indent
)))
2236 (insert-char ?\ indent
))
2239 (insert "See also ")
2241 (push (widget-create-child-and-convert
2243 :button-face
'custom-link
2244 :mouse-face
'highlight
2245 :pressed-face
'highlight
)
2247 (setq links
(cdr links
))
2256 (widget-put widget
:buttons buttons
))))
2258 (defun custom-add-parent-links (widget &optional initial-string
)
2259 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
2260 The value is non-nil if any parents were found.
2261 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
2262 (let ((name (widget-value widget
))
2263 (type (widget-type widget
))
2264 (buttons (widget-get widget
:buttons
))
2267 (insert (or initial-string
"Parent groups:"))
2268 (mapatoms (lambda (symbol)
2269 (when (member (list name type
) (get symbol
'custom-group
))
2271 (push (widget-create-child-and-convert
2272 widget
'custom-group-link
2273 :tag
(custom-unlispify-tag-name symbol
)
2276 (setq parents
(cons symbol parents
)))))
2277 (and (null (get name
'custom-links
)) ;No links of its own.
2278 (= (length parents
) 1) ;A single parent.
2279 (let* ((links (delq nil
(mapcar (lambda (w)
2280 (unless (eq (widget-type w
)
2283 (get (car parents
) 'custom-links
))))
2284 (many (> (length links
) 2)))
2286 (insert "\nParent documentation: ")
2288 (push (widget-create-child-and-convert
2290 :button-face
'custom-link
2291 :mouse-face
'highlight
2292 :pressed-face
'highlight
)
2294 (setq links
(cdr links
))
2305 (delete-region start
(point)))
2306 (widget-put widget
:buttons buttons
)
2309 ;;; The `custom-comment' Widget.
2311 ;; like the editable field
2312 (defface custom-comment
'((((type tty
))
2313 :background
"yellow3"
2314 :foreground
"black")
2315 (((class grayscale color
)
2317 :background
"gray85")
2318 (((class grayscale color
)
2320 :background
"dim gray")
2323 "Face used for comments on variables or faces"
2325 :group
'custom-faces
)
2326 ;; backward-compatibility alias
2327 (put 'custom-comment-face
'face-alias
'custom-comment
)
2329 ;; like font-lock-comment-face
2330 (defface custom-comment-tag
2331 '((((class color
) (background dark
)) (:foreground
"gray80"))
2332 (((class color
) (background light
)) (:foreground
"blue4"))
2333 (((class grayscale
) (background light
))
2334 (:foreground
"DimGray" :weight bold
:slant italic
))
2335 (((class grayscale
) (background dark
))
2336 (:foreground
"LightGray" :weight bold
:slant italic
))
2338 "Face used for variables or faces comment tags"
2339 :group
'custom-faces
)
2340 ;; backward-compatibility alias
2341 (put 'custom-comment-tag-face
'face-alias
'custom-comment-tag
)
2343 (define-widget 'custom-comment
'string
2346 :help-echo
"Edit a comment here."
2347 :sample-face
'custom-comment-tag-face
2348 :value-face
'custom-comment-face
2350 :create
'custom-comment-create
)
2352 (defun custom-comment-create (widget)
2353 (let* ((null-comment (equal "" (widget-value widget
))))
2354 (if (or (widget-get (widget-get widget
:parent
) :comment-shown
)
2356 (widget-default-create widget
)
2357 ;; `widget-default-delete' expects markers in these slots --
2358 ;; maybe it shouldn't.
2359 (widget-put widget
:from
(point-marker))
2360 (widget-put widget
:to
(point-marker)))))
2362 (defun custom-comment-hide (widget)
2363 (widget-put (widget-get widget
:parent
) :comment-shown nil
))
2365 ;; Those functions are for the menu. WIDGET is NOT the comment widget. It's
2366 ;; the global custom one
2367 (defun custom-comment-show (widget)
2368 (widget-put widget
:comment-shown t
)
2369 (custom-redraw widget
)
2372 (defun custom-comment-invisible-p (widget)
2373 (let ((val (widget-value (widget-get widget
:comment-widget
))))
2375 (not (widget-get widget
:comment-shown
)))))
2377 ;;; The `custom-variable' Widget.
2379 ;; When this was underlined blue, users confused it with a
2380 ;; Mosaic-style hyperlink...
2381 (defface custom-variable-tag
2384 (:foreground
"light blue" :weight bold
))
2385 (((min-colors 88) (class color
)
2387 (:foreground
"blue1" :weight bold
))
2390 (:foreground
"blue" :weight bold
))
2392 "Face used for unpushable variable tags."
2393 :group
'custom-faces
)
2394 ;; backward-compatibility alias
2395 (put 'custom-variable-tag-face
'face-alias
'custom-variable-tag
)
2397 (defface custom-variable-button
'((t (:underline t
:weight bold
)))
2398 "Face used for pushable variable tags."
2399 :group
'custom-faces
)
2400 ;; backward-compatibility alias
2401 (put 'custom-variable-button-face
'face-alias
'custom-variable-button
)
2403 (defcustom custom-variable-default-form
'edit
2404 "Default form of displaying variable values."
2405 :type
'(choice (const edit
)
2407 :group
'custom-buffer
2410 (defun custom-variable-documentation (variable)
2411 "Return documentation of VARIABLE for use in Custom buffer.
2412 Normally just return the docstring. But if VARIABLE automatically
2413 becomes buffer local when set, append a message to that effect."
2414 (if (and (local-variable-if-set-p variable
)
2415 (or (not (local-variable-p variable
))
2417 (local-variable-if-set-p variable
))))
2418 (concat (documentation-property variable
'variable-documentation
)
2420 This variable automatically becomes buffer-local when set outside Custom.
2421 However, setting it through Custom sets the default value.")
2422 (documentation-property variable
'variable-documentation
)))
2424 (define-widget 'custom-variable
'custom
2425 "Customize variable."
2427 :help-echo
"Set or reset this variable."
2428 :documentation-property
#'custom-variable-documentation
2429 :custom-category
'option
2431 :custom-menu
'custom-variable-menu-create
2432 :custom-form nil
; defaults to value of `custom-variable-default-form'
2433 :value-create
'custom-variable-value-create
2434 :action
'custom-variable-action
2435 :custom-set
'custom-variable-set
2436 :custom-save
'custom-variable-save
2437 :custom-reset-current
'custom-redraw
2438 :custom-reset-saved
'custom-variable-reset-saved
2439 :custom-reset-standard
'custom-variable-reset-standard
2440 :custom-standard-value
'custom-variable-standard-value
)
2442 (defun custom-variable-type (symbol)
2443 "Return a widget suitable for editing the value of SYMBOL.
2444 If SYMBOL has a `custom-type' property, use that.
2445 Otherwise, try matching SYMBOL against `custom-guess-name-alist' and
2446 try matching its doc string against `custom-guess-doc-alist'."
2447 (let* ((type (or (get symbol
'custom-type
)
2448 (and (not (get symbol
'standard-value
))
2449 (custom-guess-type symbol
))
2451 (options (get symbol
'custom-options
))
2452 (tmp (if (listp type
)
2453 (copy-sequence type
)
2456 (widget-put tmp
:options options
))
2459 (defun custom-variable-value-create (widget)
2460 "Here is where you edit the variable's value."
2461 (custom-load-widget widget
)
2462 (unless (widget-get widget
:custom-form
)
2463 (widget-put widget
:custom-form custom-variable-default-form
))
2464 (let* ((buttons (widget-get widget
:buttons
))
2465 (children (widget-get widget
:children
))
2466 (form (widget-get widget
:custom-form
))
2467 (state (widget-get widget
:custom-state
))
2468 (symbol (widget-get widget
:value
))
2469 (tag (widget-get widget
:tag
))
2470 (type (custom-variable-type symbol
))
2471 (conv (widget-convert type
))
2472 (get (or (get symbol
'custom-get
) 'default-value
))
2473 (prefix (widget-get widget
:custom-prefix
))
2474 (last (widget-get widget
:custom-last
))
2475 (value (if (default-boundp symbol
)
2476 (funcall get symbol
)
2477 (widget-get conv
:value
))))
2478 ;; If the widget is new, the child determines whether it is hidden.
2480 ((custom-show type value
)
2481 (setq state
'unknown
))
2483 (setq state
'hidden
)))
2484 ;; If we don't know the state, see if we need to edit it in lisp form.
2485 (when (eq state
'unknown
)
2486 (unless (widget-apply conv
:match value
)
2487 ;; (widget-apply (widget-convert type) :match value)
2488 (setq form
'mismatch
)))
2489 ;; Now we can create the child widget.
2490 (cond ((eq custom-buffer-style
'tree
)
2491 (insert prefix
(if last
" `--- " " |--- "))
2492 (push (widget-create-child-and-convert
2493 widget
'custom-browse-variable-tag
)
2495 (insert " " tag
"\n")
2496 (widget-put widget
:buttons buttons
))
2498 ;; Indicate hidden value.
2499 (push (widget-create-child-and-convert
2502 :sample-face
'custom-variable-tag-face
2506 (push (widget-create-child-and-convert
2508 :help-echo
"Show the value of this option."
2510 :action
'custom-toggle-parent
2513 ((memq form
'(lisp mismatch
))
2514 ;; In lisp mode edit the saved value when possible.
2515 (let* ((value (cond ((get symbol
'saved-value
)
2516 (car (get symbol
'saved-value
)))
2517 ((get symbol
'standard-value
)
2518 (car (get symbol
'standard-value
)))
2519 ((default-boundp symbol
)
2520 (custom-quote (funcall get symbol
)))
2522 (custom-quote (widget-get conv
:value
))))))
2523 (insert (symbol-name symbol
) ": ")
2524 (push (widget-create-child-and-convert
2526 :help-echo
"Hide the value of this option."
2529 :action
'custom-toggle-parent
2533 (push (widget-create-child-and-convert
2535 :button-face
'custom-variable-button-face
2537 :tag
(symbol-name symbol
)
2543 (let* ((format (widget-get type
:format
))
2544 tag-format value-format
)
2545 (unless (string-match ":" format
)
2546 (error "Bad format"))
2547 (setq tag-format
(substring format
0 (match-end 0)))
2548 (setq value-format
(substring format
(match-end 0)))
2549 (push (widget-create-child-and-convert
2552 :action
'custom-tag-action
2553 :help-echo
"Change value of this option."
2554 :mouse-down-action
'custom-tag-mouse-down-action
2555 :button-face
'custom-variable-button-face
2556 :sample-face
'custom-variable-tag-face
2560 (push (widget-create-child-and-convert
2562 :help-echo
"Hide the value of this option."
2565 :action
'custom-toggle-parent
2568 (push (widget-create-child-and-convert
2570 :format value-format
2573 (unless (eq custom-buffer-style
'tree
)
2574 (unless (eq (preceding-char) ?
\n)
2575 (widget-insert "\n"))
2576 ;; Create the magic button.
2577 (let ((magic (widget-create-child-and-convert
2578 widget
'custom-magic nil
)))
2579 (widget-put widget
:custom-magic magic
)
2580 (push magic buttons
))
2581 (widget-put widget
:buttons buttons
)
2582 ;; Insert documentation.
2583 (widget-put widget
:documentation-indent
3)
2584 (widget-add-documentation-string-button
2585 widget
:visibility-widget
'custom-visibility
)
2587 ;; The comment field
2588 (unless (eq state
'hidden
)
2589 (let* ((comment (get symbol
'variable-comment
))
2591 (widget-create-child-and-convert
2592 widget
'custom-comment
2594 :value
(or comment
""))))
2595 (widget-put widget
:comment-widget comment-widget
)
2596 ;; Don't push it !!! Custom assumes that the first child is the
2598 (setq children
(append children
(list comment-widget
)))))
2599 ;; Update the rest of the properties properties.
2600 (widget-put widget
:custom-form form
)
2601 (widget-put widget
:children children
)
2602 ;; Now update the state.
2603 (if (eq state
'hidden
)
2604 (widget-put widget
:custom-state state
)
2605 (custom-variable-state-set widget
))
2607 (unless (eq state
'hidden
)
2608 (when (eq (widget-get widget
:custom-level
) 1)
2609 (custom-add-parent-links widget
))
2610 (custom-add-see-also widget
)))))
2612 (defun custom-tag-action (widget &rest args
)
2613 "Pass :action to first child of WIDGET's parent."
2614 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2617 (defun custom-tag-mouse-down-action (widget &rest args
)
2618 "Pass :mouse-down-action to first child of WIDGET's parent."
2619 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2620 :mouse-down-action args
))
2622 (defun custom-variable-state-set (widget)
2623 "Set the state of WIDGET."
2624 (let* ((symbol (widget-value widget
))
2625 (get (or (get symbol
'custom-get
) 'default-value
))
2626 (value (if (default-boundp symbol
)
2627 (funcall get symbol
)
2628 (widget-get widget
:value
)))
2629 (comment (get symbol
'variable-comment
))
2632 (state (cond ((progn (setq tmp
(get symbol
'customized-value
))
2634 (get symbol
'customized-variable-comment
))
2636 (if (condition-case nil
2637 (and (equal value
(eval (car tmp
)))
2638 (equal comment temp
))
2642 ((progn (setq tmp
(get symbol
'theme-value
))
2643 (setq temp
(get symbol
'saved-variable-comment
))
2645 (if (condition-case nil
2646 (and (equal comment temp
)
2649 (car (custom-variable-theme-value
2653 ((eq (caar tmp
) 'user
) 'saved
)
2654 ((eq (caar tmp
) 'changed
)
2655 (if (condition-case nil
2659 (car (get symbol
'standard-value
)))))
2661 ;; The value was originally set outside
2662 ;; custom, but it was set to the standard
2663 ;; value (probably an autoloaded defcustom).
2668 ((setq tmp
(get symbol
'standard-value
))
2669 (if (condition-case nil
2670 (and (equal value
(eval (car tmp
)))
2671 (equal comment nil
))
2676 (widget-put widget
:custom-state state
)))
2678 (defun custom-variable-standard-value (widget)
2679 (get (widget-value widget
) 'standard-value
))
2681 (defvar custom-variable-menu
2682 `(("Set for Current Session" custom-variable-set
2684 (eq (widget-get widget
:custom-state
) 'modified
)))
2685 ;; Note that in all the backquoted code in this file, we test
2686 ;; init-file-user rather than user-init-file. This is in case
2687 ;; cus-edit is loaded by something in site-start.el, because
2688 ;; user-init-file is not set at that stage.
2689 ;; http://lists.gnu.org/archive/html/emacs-devel/2007-10/msg00310.html
2690 ,@(when (or custom-file init-file-user
)
2691 '(("Save for Future Sessions" custom-variable-save
2693 (memq (widget-get widget
:custom-state
)
2694 '(modified set changed rogue
))))))
2695 ("Undo Edits" custom-redraw
2697 (and (default-boundp (widget-value widget
))
2698 (memq (widget-get widget
:custom-state
) '(modified changed
)))))
2699 ("Reset to Saved" custom-variable-reset-saved
2701 (and (or (get (widget-value widget
) 'saved-value
)
2702 (get (widget-value widget
) 'saved-variable-comment
))
2703 (memq (widget-get widget
:custom-state
)
2704 '(modified set changed rogue
)))))
2705 ,@(when (or custom-file init-file-user
)
2706 '(("Erase Customization" custom-variable-reset-standard
2708 (and (get (widget-value widget
) 'standard-value
)
2709 (memq (widget-get widget
:custom-state
)
2710 '(modified set changed saved rogue
)))))))
2711 ("Set to Backup Value" custom-variable-reset-backup
2713 (get (widget-value widget
) 'backup-value
)))
2714 ("---" ignore ignore
)
2715 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
2716 ("---" ignore ignore
)
2717 ("Show Current Value" custom-variable-edit
2719 (eq (widget-get widget
:custom-form
) 'lisp
)))
2720 ("Show Saved Lisp Expression" custom-variable-edit-lisp
2722 (eq (widget-get widget
:custom-form
) 'edit
))))
2723 "Alist of actions for the `custom-variable' widget.
2724 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2725 the menu entry, ACTION is the function to call on the widget when the
2726 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2727 widget as an argument, and returns non-nil if ACTION is valid on that
2728 widget. If FILTER is nil, ACTION is always valid.")
2730 (defun custom-variable-action (widget &optional event
)
2731 "Show the menu for `custom-variable' WIDGET.
2732 Optional EVENT is the location for the menu."
2733 (if (eq (widget-get widget
:custom-state
) 'hidden
)
2734 (custom-toggle-hide widget
)
2735 (unless (eq (widget-get widget
:custom-state
) 'modified
)
2736 (custom-variable-state-set widget
))
2737 (custom-redraw-magic widget
)
2738 (let* ((completion-ignore-case t
)
2739 (answer (widget-choose (concat "Operation on "
2740 (custom-unlispify-tag-name
2741 (widget-get widget
:value
)))
2742 (custom-menu-filter custom-variable-menu
2746 (funcall answer widget
)))))
2748 (defun custom-variable-edit (widget)
2749 "Edit value of WIDGET."
2750 (widget-put widget
:custom-state
'unknown
)
2751 (widget-put widget
:custom-form
'edit
)
2752 (custom-redraw widget
))
2754 (defun custom-variable-edit-lisp (widget)
2755 "Edit the Lisp representation of the value of WIDGET."
2756 (widget-put widget
:custom-state
'unknown
)
2757 (widget-put widget
:custom-form
'lisp
)
2758 (custom-redraw widget
))
2760 (defun custom-variable-set (widget)
2761 "Set the current value for the variable being edited by WIDGET."
2762 (let* ((form (widget-get widget
:custom-form
))
2763 (state (widget-get widget
:custom-state
))
2764 (child (car (widget-get widget
:children
)))
2765 (symbol (widget-value widget
))
2766 (set (or (get symbol
'custom-set
) 'set-default
))
2767 (comment-widget (widget-get widget
:comment-widget
))
2768 (comment (widget-value comment-widget
))
2770 (cond ((eq state
'hidden
)
2771 (error "Cannot set hidden variable"))
2772 ((setq val
(widget-apply child
:validate
))
2773 (goto-char (widget-get val
:from
))
2774 (error "%s" (widget-get val
:error
)))
2775 ((memq form
'(lisp mismatch
))
2776 (when (equal comment
"")
2778 ;; Make the comment invisible by hand if it's empty
2779 (custom-comment-hide comment-widget
))
2780 (custom-variable-backup-value widget
)
2781 (custom-push-theme 'theme-value symbol
'user
2782 'set
(custom-quote (widget-value child
)))
2783 (funcall set symbol
(eval (setq val
(widget-value child
))))
2784 (put symbol
'customized-value
(list val
))
2785 (put symbol
'variable-comment comment
)
2786 (put symbol
'customized-variable-comment comment
))
2788 (when (equal comment
"")
2790 ;; Make the comment invisible by hand if it's empty
2791 (custom-comment-hide comment-widget
))
2792 (custom-variable-backup-value widget
)
2793 (custom-push-theme 'theme-value symbol
'user
2794 'set
(custom-quote (widget-value child
)))
2795 (funcall set symbol
(setq val
(widget-value child
)))
2796 (put symbol
'customized-value
(list (custom-quote val
)))
2797 (put symbol
'variable-comment comment
)
2798 (put symbol
'customized-variable-comment comment
)))
2799 (custom-variable-state-set widget
)
2800 (custom-redraw-magic widget
)))
2802 (defun custom-variable-save (widget)
2803 "Set and save the value for the variable being edited by WIDGET."
2804 (let* ((form (widget-get widget
:custom-form
))
2805 (state (widget-get widget
:custom-state
))
2806 (child (car (widget-get widget
:children
)))
2807 (symbol (widget-value widget
))
2808 (set (or (get symbol
'custom-set
) 'set-default
))
2809 (comment-widget (widget-get widget
:comment-widget
))
2810 (comment (widget-value comment-widget
))
2812 (cond ((eq state
'hidden
)
2813 (error "Cannot set hidden variable"))
2814 ((setq val
(widget-apply child
:validate
))
2815 (goto-char (widget-get val
:from
))
2816 (error "Saving %s: %s" symbol
(widget-get val
:error
)))
2817 ((memq form
'(lisp mismatch
))
2818 (when (equal comment
"")
2820 ;; Make the comment invisible by hand if it's empty
2821 (custom-comment-hide comment-widget
))
2822 (put symbol
'saved-value
(list (widget-value child
)))
2823 (custom-push-theme 'theme-value symbol
'user
2824 'set
(custom-quote (widget-value child
)))
2825 (funcall set symbol
(eval (widget-value child
)))
2826 (put symbol
'variable-comment comment
)
2827 (put symbol
'saved-variable-comment comment
))
2829 (when (equal comment
"")
2831 ;; Make the comment invisible by hand if it's empty
2832 (custom-comment-hide comment-widget
))
2833 (put symbol
'saved-value
2834 (list (custom-quote (widget-value child
))))
2835 (custom-push-theme 'theme-value symbol
'user
2836 'set
(custom-quote (widget-value child
)))
2837 (funcall set symbol
(widget-value child
))
2838 (put symbol
'variable-comment comment
)
2839 (put symbol
'saved-variable-comment comment
)))
2840 (put symbol
'customized-value nil
)
2841 (put symbol
'customized-variable-comment nil
)
2843 (custom-variable-state-set widget
)
2844 (custom-redraw-magic widget
)))
2846 (defun custom-variable-reset-saved (widget)
2847 "Restore the saved value for the variable being edited by WIDGET.
2848 This also updates the buffer to show that value.
2849 The value that was current before this operation
2850 becomes the backup value, so you can get it again."
2851 (let* ((symbol (widget-value widget
))
2852 (set (or (get symbol
'custom-set
) 'set-default
))
2853 (value (get symbol
'saved-value
))
2854 (comment (get symbol
'saved-variable-comment
)))
2855 (cond ((or value comment
)
2856 (put symbol
'variable-comment comment
)
2857 (custom-variable-backup-value widget
)
2858 (custom-push-theme 'theme-value symbol
'user
'set
(car-safe value
))
2860 (funcall set symbol
(eval (car value
)))
2863 (error "No saved value for %s" symbol
)))
2864 (put symbol
'customized-value nil
)
2865 (put symbol
'customized-variable-comment nil
)
2866 (widget-put widget
:custom-state
'unknown
)
2867 ;; This call will possibly make the comment invisible
2868 (custom-redraw widget
)))
2870 (defun custom-variable-reset-standard (widget)
2871 "Restore the standard setting for the variable being edited by WIDGET.
2872 This operation eliminates any saved setting for the variable,
2873 restoring it to the state of a variable that has never been customized.
2874 The value that was current before this operation
2875 becomes the backup value, so you can get it again."
2876 (let* ((symbol (widget-value widget
)))
2877 (if (get symbol
'standard-value
)
2878 (custom-variable-backup-value widget
)
2879 (error "No standard setting known for %S" symbol
))
2880 (put symbol
'variable-comment nil
)
2881 (put symbol
'customized-value nil
)
2882 (put symbol
'customized-variable-comment nil
)
2883 (custom-push-theme 'theme-value symbol
'user
'reset
)
2884 (custom-theme-recalc-variable symbol
)
2885 (when (or (get symbol
'saved-value
) (get symbol
'saved-variable-comment
))
2886 (put symbol
'saved-value nil
)
2887 (put symbol
'saved-variable-comment nil
)
2889 (widget-put widget
:custom-state
'unknown
)
2890 ;; This call will possibly make the comment invisible
2891 (custom-redraw widget
)))
2893 (defun custom-variable-backup-value (widget)
2894 "Back up the current value for WIDGET's variable.
2895 The backup value is kept in the car of the `backup-value' property."
2896 (let* ((symbol (widget-value widget
))
2897 (get (or (get symbol
'custom-get
) 'default-value
))
2898 (type (custom-variable-type symbol
))
2899 (conv (widget-convert type
))
2900 (value (if (default-boundp symbol
)
2901 (funcall get symbol
)
2902 (widget-get conv
:value
))))
2903 (put symbol
'backup-value
(list value
))))
2905 (defun custom-variable-reset-backup (widget)
2906 "Restore the backup value for the variable being edited by WIDGET.
2907 The value that was current before this operation
2908 becomes the backup value, so you can use this operation repeatedly
2909 to switch between two values."
2910 (let* ((symbol (widget-value widget
))
2911 (set (or (get symbol
'custom-set
) 'set-default
))
2912 (value (get symbol
'backup-value
))
2913 (comment-widget (widget-get widget
:comment-widget
))
2914 (comment (widget-value comment-widget
)))
2917 (custom-variable-backup-value widget
)
2918 (custom-push-theme 'theme-value symbol
'user
'set value
)
2920 (funcall set symbol
(car value
))
2922 (error "No backup value for %s" symbol
))
2923 (put symbol
'customized-value
(list (car value
)))
2924 (put symbol
'variable-comment comment
)
2925 (put symbol
'customized-variable-comment comment
)
2926 (custom-variable-state-set widget
)
2927 ;; This call will possibly make the comment invisible
2928 (custom-redraw widget
)))
2930 ;;; The `custom-visibility' Widget
2932 (define-widget 'custom-visibility
'visibility
2933 "Show or hide a documentation string."
2934 :button-face
'custom-visibility
2935 :pressed-face
'custom-visibility
2936 :mouse-face
'highlight
2937 :pressed-face
'highlight
)
2939 (defface custom-visibility
2940 '((t :height
0.8 :inherit link
))
2941 "Face for the `custom-visibility' widget."
2943 :group
'custom-faces
)
2945 ;;; The `custom-face-edit' Widget.
2947 (define-widget 'custom-face-edit
'checklist
2948 "Edit face attributes."
2952 :button-args
'(:help-echo
"Control whether this attribute has any effect.")
2953 :value-to-internal
'custom-face-edit-fix-value
2954 :match
(lambda (widget value
)
2955 (widget-checklist-match widget
2956 (custom-face-edit-fix-value widget value
)))
2957 :convert-widget
'custom-face-edit-convert-widget
2958 :args
(mapcar (lambda (att)
2961 :sibling-args
(widget-get (nth 1 att
) :sibling-args
)
2962 (list 'const
:format
"" :value
(nth 0 att
))
2964 custom-face-attributes
))
2966 (defun custom-face-edit-fix-value (widget value
)
2967 "Ignoring WIDGET, convert :bold and :italic in VALUE to new form.
2968 Also change :reverse-video to :inverse-video."
2972 (let ((key (car value
))
2973 (val (car (cdr value
))))
2974 (cond ((eq key
:italic
)
2975 (push :slant result
)
2976 (push (if val
'italic
'normal
) result
))
2978 (push :weight result
)
2979 (push (if val
'bold
'normal
) result
))
2980 ((eq key
:reverse-video
)
2981 (push :inverse-video result
)
2985 (push val result
))))
2986 (setq value
(cdr (cdr value
))))
2987 (setq result
(nreverse result
))
2991 (defun custom-face-edit-convert-widget (widget)
2992 "Convert :args as widget types in WIDGET."
2995 :args
(mapcar (lambda (arg)
2997 :deactivate
'custom-face-edit-deactivate
2998 :activate
'custom-face-edit-activate
2999 :delete
'custom-face-edit-delete
))
3000 (widget-get widget
:args
)))
3003 (defun custom-face-edit-deactivate (widget)
3004 "Make face widget WIDGET inactive for user modifications."
3005 (unless (widget-get widget
:inactive
)
3006 (let ((tag (custom-face-edit-attribute-tag widget
))
3007 (from (copy-marker (widget-get widget
:from
)))
3008 (value (widget-value widget
))
3009 (inhibit-read-only t
)
3010 (inhibit-modification-hooks t
))
3013 (widget-default-delete widget
)
3014 (insert tag
": *\n")
3015 (widget-put widget
:inactive
3016 (cons value
(cons from
(- (point) from
))))))))
3018 (defun custom-face-edit-activate (widget)
3019 "Make face widget WIDGET active for user modifications."
3020 (let ((inactive (widget-get widget
:inactive
))
3021 (inhibit-read-only t
)
3022 (inhibit-modification-hooks t
))
3023 (when (consp inactive
)
3025 (goto-char (car (cdr inactive
)))
3026 (delete-region (point) (+ (point) (cdr (cdr inactive
))))
3027 (widget-put widget
:inactive nil
)
3028 (widget-apply widget
:create
)
3029 (widget-value-set widget
(car inactive
))
3032 (defun custom-face-edit-delete (widget)
3033 "Remove WIDGET from the buffer."
3034 (let ((inactive (widget-get widget
:inactive
))
3035 (inhibit-read-only t
)
3036 (inhibit-modification-hooks t
))
3038 ;; Widget is alive, we don't have to do anything special
3039 (widget-default-delete widget
)
3040 ;; WIDGET is already deleted because we did so to inactivate it;
3041 ;; now just get rid of the label we put in its place.
3042 (delete-region (car (cdr inactive
))
3043 (+ (car (cdr inactive
)) (cdr (cdr inactive
))))
3044 (widget-put widget
:inactive nil
))))
3047 (defun custom-face-edit-attribute-tag (widget)
3048 "Returns the first :tag property in WIDGET or one of its children."
3049 (let ((tag (widget-get widget
:tag
)))
3050 (or (and (not (equal tag
"")) tag
)
3051 (let ((children (widget-get widget
:children
)))
3052 (while (and (null tag
) children
)
3053 (setq tag
(custom-face-edit-attribute-tag (pop children
))))
3056 ;;; The `custom-display' Widget.
3058 (define-widget 'custom-display
'menu-choice
3059 "Select a display type."
3062 :help-echo
"Specify frames where the face attributes should be used."
3063 :args
'((const :tag
"all" t
)
3064 (const :tag
"defaults" default
)
3068 :args
((group :sibling-args
(:help-echo
"\
3069 Only match the specified window systems.")
3070 (const :format
"Type: "
3072 (checklist :inline t
3075 :sibling-args
(:help-echo
"\
3076 The X11 Window System.")
3078 (const :format
"PM "
3079 :sibling-args
(:help-echo
"\
3080 OS/2 Presentation Manager.")
3082 (const :format
"W32 "
3083 :sibling-args
(:help-echo
"\
3086 (const :format
"MAC "
3087 :sibling-args
(:help-echo
"\
3090 (const :format
"DOS "
3091 :sibling-args
(:help-echo
"\
3094 (const :format
"TTY%n"
3095 :sibling-args
(:help-echo
"\
3096 Plain text terminals.")
3098 (group :sibling-args
(:help-echo
"\
3099 Only match the frames with the specified color support.")
3100 (const :format
"Class: "
3102 (checklist :inline t
3104 (const :format
"Color "
3105 :sibling-args
(:help-echo
"\
3106 Match color frames.")
3108 (const :format
"Grayscale "
3109 :sibling-args
(:help-echo
"\
3110 Match grayscale frames.")
3112 (const :format
"Monochrome%n"
3113 :sibling-args
(:help-echo
"\
3114 Match frames with no color support.")
3116 (group :sibling-args
(:help-echo
"\
3117 The minimum number of colors the frame should support.")
3118 (const :format
"" min-colors
)
3119 (integer :tag
"Minimum number of colors" ))
3120 (group :sibling-args
(:help-echo
"\
3121 Only match frames with the specified intensity.")
3123 Background brightness: "
3125 (checklist :inline t
3127 (const :format
"Light "
3128 :sibling-args
(:help-echo
"\
3129 Match frames with light backgrounds.")
3131 (const :format
"Dark\n"
3132 :sibling-args
(:help-echo
"\
3133 Match frames with dark backgrounds.")
3135 (group :sibling-args
(:help-echo
"\
3136 Only match frames that support the specified face attributes.")
3137 (const :format
"Supports attributes:" supports
)
3138 (custom-face-edit :inline t
:format
"%n%v"))))))
3140 ;;; The `custom-face' Widget.
3142 (defface custom-face-tag
3143 `((t (:weight bold
:height
1.2 :inherit variable-pitch
)))
3144 "Face used for face tags."
3145 :group
'custom-faces
)
3146 ;; backward-compatibility alias
3147 (put 'custom-face-tag-face
'face-alias
'custom-face-tag
)
3149 (defcustom custom-face-default-form
'selected
3150 "Default form of displaying face definition."
3151 :type
'(choice (const all
)
3154 :group
'custom-buffer
3157 (define-widget 'custom-face
'custom
3159 :sample-face
'custom-face-tag-face
3160 :help-echo
"Set or reset this face."
3161 :documentation-property
#'face-doc-string
3162 :value-create
'custom-face-value-create
3163 :action
'custom-face-action
3164 :custom-category
'face
3165 :custom-form nil
; defaults to value of `custom-face-default-form'
3166 :custom-set
'custom-face-set
3167 :custom-save
'custom-face-save
3168 :custom-reset-current
'custom-redraw
3169 :custom-reset-saved
'custom-face-reset-saved
3170 :custom-reset-standard
'custom-face-reset-standard
3171 :custom-standard-value
'custom-face-standard-value
3172 :custom-menu
'custom-face-menu-create
)
3174 (define-widget 'custom-face-all
'editable-list
3175 "An editable list of display specifications and attributes."
3176 :entry-format
"%i %d %v"
3177 :insert-button-args
'(:help-echo
"Insert new display specification here.")
3178 :append-button-args
'(:help-echo
"Append new display specification here.")
3179 :delete-button-args
'(:help-echo
"Delete this display specification.")
3180 :args
'((group :format
"%v" custom-display custom-face-edit
)))
3182 (defconst custom-face-all
(widget-convert 'custom-face-all
)
3183 "Converted version of the `custom-face-all' widget.")
3185 (define-widget 'custom-display-unselected
'item
3186 "A display specification that doesn't match the selected display."
3187 :match
'custom-display-unselected-match
)
3189 (defun custom-display-unselected-match (widget value
)
3190 "Non-nil if VALUE is an unselected display specification."
3191 (not (face-spec-set-match-display value
(selected-frame))))
3193 (define-widget 'custom-face-selected
'group
3194 "Edit the attributes of the selected display in a face specification."
3195 :args
'((choice :inline t
3196 (group :tag
"With Defaults" :inline t
3197 (group (const :tag
"" default
)
3198 (custom-face-edit :tag
" Default\n Attributes"))
3201 (group custom-display-unselected sexp
))
3202 (group (sexp :format
"")
3203 (custom-face-edit :tag
" Overriding\n Attributes"))
3207 (group :tag
"No Defaults" :inline t
3210 (group custom-display-unselected sexp
))
3211 (group (sexp :format
"")
3212 (custom-face-edit :tag
"\n Attributes"))
3219 (defconst custom-face-selected
(widget-convert 'custom-face-selected
)
3220 "Converted version of the `custom-face-selected' widget.")
3222 (defun custom-filter-face-spec (spec filter-index
&optional default-filter
)
3223 "Return a canonicalized version of SPEC using.
3224 FILTER-INDEX is the index in the entry for each attribute in
3225 `custom-face-attributes' at which the appropriate filter function can be
3226 found, and DEFAULT-FILTER is the filter to apply for attributes that
3228 (mapcar (lambda (entry)
3229 ;; Filter a single face-spec entry
3230 (let ((tests (car entry
))
3232 ;; Handle both old- and new-style attribute syntax
3233 (if (listp (car (cdr entry
)))
3236 (filtered-attrs nil
))
3237 ;; Filter each face attribute
3238 (while unfiltered-attrs
3239 (let* ((attr (pop unfiltered-attrs
))
3240 (pre-filtered-value (pop unfiltered-attrs
))
3242 (or (nth filter-index
(assq attr custom-face-attributes
))
3246 (funcall filter pre-filtered-value
)
3247 pre-filtered-value
)))
3248 (push filtered-value filtered-attrs
)
3249 (push attr filtered-attrs
)))
3251 (list tests filtered-attrs
)))
3254 (defun custom-pre-filter-face-spec (spec)
3255 "Return SPEC changed as necessary for editing by the face customization widget.
3256 SPEC must be a full face spec."
3257 (custom-filter-face-spec spec
2))
3259 (defun custom-post-filter-face-spec (spec)
3260 "Return the customized SPEC in a form suitable for setting the face."
3261 (custom-filter-face-spec spec
3))
3263 (defun custom-face-value-create (widget)
3264 "Create a list of the display specifications for WIDGET."
3265 (let ((buttons (widget-get widget
:buttons
))
3267 (symbol (widget-get widget
:value
))
3268 (tag (widget-get widget
:tag
))
3269 (state (widget-get widget
:custom-state
))
3271 (is-last (widget-get widget
:custom-last
))
3272 (prefix (widget-get widget
:custom-prefix
)))
3274 (setq tag
(prin1-to-string symbol
)))
3275 (cond ((eq custom-buffer-style
'tree
)
3276 (insert prefix
(if is-last
" `--- " " |--- "))
3277 (push (widget-create-child-and-convert
3278 widget
'custom-browse-face-tag
)
3280 (insert " " tag
"\n")
3281 (widget-put widget
:buttons buttons
))
3285 (widget-specify-sample widget begin
(point))
3286 (if (eq custom-buffer-style
'face
)
3288 (if (string-match "face\\'" tag
)
3290 (insert " face: ")))
3292 (push (widget-create-child-and-convert widget
'item
3299 (push (widget-create-child-and-convert
3301 :help-echo
"Hide or show this face."
3304 :action
'custom-toggle-parent
3305 (not (eq state
'hidden
)))
3309 (let ((magic (widget-create-child-and-convert
3310 widget
'custom-magic nil
)))
3311 (widget-put widget
:custom-magic magic
)
3312 (push magic buttons
))
3314 (widget-put widget
:buttons buttons
)
3315 ;; Insert documentation.
3316 (widget-add-documentation-string-button
3317 widget
:visibility-widget
'custom-visibility
)
3319 ;; The comment field
3320 (unless (eq state
'hidden
)
3321 (let* ((comment (get symbol
'face-comment
))
3323 (widget-create-child-and-convert
3324 widget
'custom-comment
3326 :value
(or comment
""))))
3327 (widget-put widget
:comment-widget comment-widget
)
3328 (push comment-widget children
)))
3330 (unless (eq state
'hidden
)
3331 (when (eq (widget-get widget
:custom-level
) 1)
3332 (custom-add-parent-links widget
))
3333 (custom-add-see-also widget
))
3335 (unless (eq (preceding-char) ?
\n)
3337 (unless (eq state
'hidden
)
3338 (message "Creating face editor...")
3339 (custom-load-widget widget
)
3340 (unless (widget-get widget
:custom-form
)
3341 (widget-put widget
:custom-form custom-face-default-form
))
3342 (let* ((symbol (widget-value widget
))
3343 (spec (or (get symbol
'customized-face
)
3344 (get symbol
'saved-face
)
3345 (get symbol
'face-defface-spec
)
3346 ;; Attempt to construct it.
3347 (list (list t
(custom-face-attributes-get
3348 symbol
(selected-frame))))))
3349 (form (widget-get widget
:custom-form
))
3350 (indent (widget-get widget
:indent
))
3352 ;; If the user has changed this face in some other way,
3353 ;; edit it as the user has specified it.
3354 (if (not (face-spec-match-p symbol spec
(selected-frame)))
3355 (setq spec
(list (list t
(face-attr-construct symbol
(selected-frame))))))
3356 (setq spec
(custom-pre-filter-face-spec spec
))
3357 (setq edit
(widget-create-child-and-convert
3359 (cond ((and (eq form
'selected
)
3360 (widget-apply custom-face-selected
3362 (when indent
(insert-char ?\ indent
))
3363 'custom-face-selected
)
3364 ((and (not (eq form
'lisp
))
3365 (widget-apply custom-face-all
3369 (when indent
(insert-char ?\ indent
))
3372 (custom-face-state-set widget
)
3373 (push edit children
)
3374 (widget-put widget
:children children
))
3375 (message "Creating face editor...done"))))))
3377 (defvar custom-face-menu
3378 `(("Set for Current Session" custom-face-set
)
3379 ,@(when (or custom-file init-file-user
)
3380 '(("Save for Future Sessions" custom-face-save
)))
3381 ("Undo Edits" custom-redraw
3383 (memq (widget-get widget
:custom-state
) '(modified changed
))))
3384 ("Reset to Saved" custom-face-reset-saved
3386 (or (get (widget-value widget
) 'saved-face
)
3387 (get (widget-value widget
) 'saved-face-comment
))))
3388 ,@(when (or custom-file init-file-user
)
3389 '(("Erase Customization" custom-face-reset-standard
3391 (get (widget-value widget
) 'face-defface-spec
)))))
3392 ("---" ignore ignore
)
3393 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
3394 ("---" ignore ignore
)
3395 ("For Current Display" custom-face-edit-selected
3397 (not (eq (widget-get widget
:custom-form
) 'selected
))))
3398 ("For All Kinds of Displays" custom-face-edit-all
3400 (not (eq (widget-get widget
:custom-form
) 'all
))))
3401 ("Show Lisp Expression" custom-face-edit-lisp
3403 (not (eq (widget-get widget
:custom-form
) 'lisp
)))))
3404 "Alist of actions for the `custom-face' widget.
3405 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3406 the menu entry, ACTION is the function to call on the widget when the
3407 menu is selected, and FILTER is a predicate which takes a `custom-face'
3408 widget as an argument, and returns non-nil if ACTION is valid on that
3409 widget. If FILTER is nil, ACTION is always valid.")
3411 (defun custom-face-edit-selected (widget)
3412 "Edit selected attributes of the value of WIDGET."
3413 (widget-put widget
:custom-state
'unknown
)
3414 (widget-put widget
:custom-form
'selected
)
3415 (custom-redraw widget
))
3417 (defun custom-face-edit-all (widget)
3418 "Edit all attributes of the value of WIDGET."
3419 (widget-put widget
:custom-state
'unknown
)
3420 (widget-put widget
:custom-form
'all
)
3421 (custom-redraw widget
))
3423 (defun custom-face-edit-lisp (widget)
3424 "Edit the Lisp representation of the value of WIDGET."
3425 (widget-put widget
:custom-state
'unknown
)
3426 (widget-put widget
:custom-form
'lisp
)
3427 (custom-redraw widget
))
3429 (defun custom-face-state-set (widget)
3430 "Set the state of WIDGET."
3431 (let* ((symbol (widget-value widget
))
3432 (comment (get symbol
'face-comment
))
3436 (setq tmp
(get symbol
'customized-face
))
3437 (setq temp
(get symbol
'customized-face-comment
))
3439 (if (equal temp comment
)
3443 (setq tmp
(get symbol
'saved-face
))
3444 (setq temp
(get symbol
'saved-face-comment
))
3446 (if (equal temp comment
)
3448 ((eq 'user
(caar (get symbol
'theme-face
)))
3450 ((eq 'changed
(caar (get symbol
'theme-face
)))
3454 ((get symbol
'face-defface-spec
)
3455 (if (equal comment nil
)
3460 ;; If the user called set-face-attribute to change the default
3461 ;; for new frames, this face is "set outside of Customize".
3462 (if (and (not (eq state
'rogue
))
3463 (get symbol
'face-modified
))
3464 (setq state
'changed
))
3465 (widget-put widget
:custom-state state
)))
3467 (defun custom-face-action (widget &optional event
)
3468 "Show the menu for `custom-face' WIDGET.
3469 Optional EVENT is the location for the menu."
3470 (if (eq (widget-get widget
:custom-state
) 'hidden
)
3471 (custom-toggle-hide widget
)
3472 (let* ((completion-ignore-case t
)
3473 (symbol (widget-get widget
:value
))
3474 (answer (widget-choose (concat "Operation on "
3475 (custom-unlispify-tag-name symbol
))
3476 (custom-menu-filter custom-face-menu
3480 (funcall answer widget
)))))
3482 (defun custom-face-set (widget)
3483 "Make the face attributes in WIDGET take effect."
3484 (let* ((symbol (widget-value widget
))
3485 (child (car (widget-get widget
:children
)))
3486 (value (custom-post-filter-face-spec (widget-value child
)))
3487 (comment-widget (widget-get widget
:comment-widget
))
3488 (comment (widget-value comment-widget
)))
3489 (when (equal comment
"")
3491 ;; Make the comment invisible by hand if it's empty
3492 (custom-comment-hide comment-widget
))
3493 (put symbol
'customized-face value
)
3494 (custom-push-theme 'theme-face symbol
'user
'set value
)
3495 (if (face-spec-choose value
)
3496 (face-spec-set symbol value
)
3497 ;; face-set-spec ignores empty attribute lists, so just give it
3498 ;; something harmless instead.
3499 (face-spec-set symbol
'((t :foreground unspecified
))))
3500 (put symbol
'customized-face-comment comment
)
3501 (put symbol
'face-comment comment
)
3502 (custom-face-state-set widget
)
3503 (custom-redraw-magic widget
)))
3505 (defun custom-face-save (widget)
3506 "Save in `.emacs' the face attributes in WIDGET."
3507 (let* ((symbol (widget-value widget
))
3508 (child (car (widget-get widget
:children
)))
3509 (value (custom-post-filter-face-spec (widget-value child
)))
3510 (comment-widget (widget-get widget
:comment-widget
))
3511 (comment (widget-value comment-widget
)))
3512 (when (equal comment
"")
3514 ;; Make the comment invisible by hand if it's empty
3515 (custom-comment-hide comment-widget
))
3516 (custom-push-theme 'theme-face symbol
'user
'set value
)
3517 (if (face-spec-choose value
)
3518 (face-spec-set symbol value
)
3519 ;; face-set-spec ignores empty attribute lists, so just give it
3520 ;; something harmless instead.
3521 (face-spec-set symbol
'((t :foreground unspecified
))))
3522 (unless (eq (widget-get widget
:custom-state
) 'standard
)
3523 (put symbol
'saved-face value
))
3524 (put symbol
'customized-face nil
)
3525 (put symbol
'face-comment comment
)
3526 (put symbol
'customized-face-comment nil
)
3527 (put symbol
'saved-face-comment comment
)
3529 (custom-face-state-set widget
)
3530 (custom-redraw-magic widget
)))
3532 ;; For backward compatibility.
3533 (define-obsolete-function-alias 'custom-face-save-command
'custom-face-save
3536 (defun custom-face-reset-saved (widget)
3537 "Restore WIDGET to the face's default attributes."
3538 (let* ((symbol (widget-value widget
))
3539 (child (car (widget-get widget
:children
)))
3540 (value (get symbol
'saved-face
))
3541 (comment (get symbol
'saved-face-comment
))
3542 (comment-widget (widget-get widget
:comment-widget
)))
3543 (unless (or value comment
)
3544 (error "No saved value for this face"))
3545 (put symbol
'customized-face nil
)
3546 (put symbol
'customized-face-comment nil
)
3547 (custom-push-theme 'theme-face symbol
'user
'set value
)
3548 (face-spec-set symbol value
)
3549 (put symbol
'face-comment comment
)
3550 (widget-value-set child value
)
3551 ;; This call manages the comment visibility
3552 (widget-value-set comment-widget
(or comment
""))
3553 (custom-face-state-set widget
)
3554 (custom-redraw-magic widget
)))
3556 (defun custom-face-standard-value (widget)
3557 (get (widget-value widget
) 'face-defface-spec
))
3559 (defun custom-face-reset-standard (widget)
3560 "Restore WIDGET to the face's standard attribute values.
3561 This operation eliminates any saved attributes for the face,
3562 restoring it to the state of a face that has never been customized."
3563 (let* ((symbol (widget-value widget
))
3564 (child (car (widget-get widget
:children
)))
3565 (value (get symbol
'face-defface-spec
))
3566 (comment-widget (widget-get widget
:comment-widget
)))
3568 (error "No standard setting for this face"))
3569 (put symbol
'customized-face nil
)
3570 (put symbol
'customized-face-comment nil
)
3571 (custom-push-theme 'theme-face symbol
'user
'reset
)
3572 (face-spec-set symbol value
)
3573 (custom-theme-recalc-face symbol
)
3574 (when (or (get symbol
'saved-face
) (get symbol
'saved-face-comment
))
3575 (put symbol
'saved-face nil
)
3576 (put symbol
'saved-face-comment nil
)
3578 (put symbol
'face-comment nil
)
3579 (widget-value-set child
3580 (custom-pre-filter-face-spec
3581 (list (list t
(custom-face-attributes-get
3583 ;; This call manages the comment visibility
3584 (widget-value-set comment-widget
"")
3585 (custom-face-state-set widget
)
3586 (custom-redraw-magic widget
)))
3588 ;;; The `face' Widget.
3590 (defvar widget-face-prompt-value-history nil
3591 "History of input to `widget-face-prompt-value'.")
3593 (define-widget 'face
'symbol
3594 "A Lisp face name (with sample)."
3595 :format
"%{%t%}: (%{sample%}) %v"
3598 :sample-face-get
'widget-face-sample-face-get
3599 :notify
'widget-face-notify
3600 :match
(lambda (widget value
) (facep value
))
3601 :complete-function
(lambda ()
3603 (lisp-complete-symbol 'facep
))
3604 :prompt-match
'facep
3605 :prompt-history
'widget-face-prompt-value-history
3606 :validate
(lambda (widget)
3607 (unless (facep (widget-value widget
))
3609 :error
(format "Invalid face: %S"
3610 (widget-value widget
)))
3613 (defun widget-face-sample-face-get (widget)
3614 (let ((value (widget-value widget
)))
3619 (defun widget-face-notify (widget child
&optional event
)
3620 "Update the sample, and notify the parent."
3621 (overlay-put (widget-get widget
:sample-overlay
)
3622 'face
(widget-apply widget
:sample-face-get
))
3623 (widget-default-notify widget child event
))
3626 ;;; The `hook' Widget.
3628 (define-widget 'hook
'list
3629 "An Emacs Lisp hook."
3630 :value-to-internal
(lambda (widget value
)
3631 (if (and value
(symbolp value
))
3634 :match
(lambda (widget value
)
3636 (widget-group-match widget value
)))
3637 ;; Avoid adding undefined functions to the hook, especially for
3638 ;; things like `find-file-hook' or even more basic ones, to avoid
3640 :set
(lambda (symbol value
)
3643 (add-hook symbol elt
))))
3644 :convert-widget
'custom-hook-convert-widget
3647 (defun custom-hook-convert-widget (widget)
3648 ;; Handle `:options'.
3649 (let* ((options (widget-get widget
:options
))
3650 (other `(editable-list :inline t
3651 :entry-format
"%i %d%v"
3652 (function :format
" %v")))
3654 (list `(checklist :inline t
3655 ,@(mapcar (lambda (entry)
3656 `(function-item ,entry
))
3660 (widget-put widget
:args args
)
3663 ;;; The `custom-group-link' Widget.
3665 (define-widget 'custom-group-link
'link
3666 "Show parent in other window when activated."
3667 :button-face
'custom-link
3668 :mouse-face
'highlight
3669 :pressed-face
'highlight
3670 :help-echo
"Create customization buffer for this group."
3671 :keymap custom-mode-link-map
3672 :follow-link
'mouse-face
3673 :action
'custom-group-link-action
)
3675 (defun custom-group-link-action (widget &rest ignore
)
3676 (customize-group (widget-value widget
)))
3678 ;;; The `custom-group' Widget.
3680 (defcustom custom-group-tag-faces nil
3681 ;; In XEmacs, this ought to play games with font size.
3682 ;; Fixme: make it do so in Emacs.
3683 "Face used for group tags.
3684 The first member is used for level 1 groups, the second for level 2,
3685 and so forth. The remaining group tags are shown with `custom-group-tag'."
3686 :type
'(repeat face
)
3687 :group
'custom-faces
)
3689 (defface custom-group-tag-1
3692 (:foreground
"pink" :weight bold
:height
1.2 :inherit variable-pitch
))
3693 (((min-colors 88) (class color
)
3695 (:foreground
"red1" :weight bold
:height
1.2 :inherit variable-pitch
))
3698 (:foreground
"red" :weight bold
:height
1.2 :inherit variable-pitch
))
3700 "Face used for group tags."
3701 :group
'custom-faces
)
3702 ;; backward-compatibility alias
3703 (put 'custom-group-tag-face-1
'face-alias
'custom-group-tag-1
)
3705 (defface custom-group-tag
3708 (:foreground
"light blue" :weight bold
:height
1.2 :inherit variable-pitch
))
3709 (((min-colors 88) (class color
)
3711 (:foreground
"blue1" :weight bold
:height
1.2 :inherit variable-pitch
))
3714 (:foreground
"blue" :weight bold
:height
1.2 :inherit variable-pitch
))
3716 "Face used for low level group tags."
3717 :group
'custom-faces
)
3718 ;; backward-compatibility alias
3719 (put 'custom-group-tag-face
'face-alias
'custom-group-tag
)
3721 (define-widget 'custom-group
'custom
3724 :sample-face-get
'custom-group-sample-face-get
3725 :documentation-property
'group-documentation
3726 :help-echo
"Set or reset all members of this group."
3727 :value-create
'custom-group-value-create
3728 :action
'custom-group-action
3729 :custom-category
'group
3730 :custom-set
'custom-group-set
3731 :custom-save
'custom-group-save
3732 :custom-reset-current
'custom-group-reset-current
3733 :custom-reset-saved
'custom-group-reset-saved
3734 :custom-reset-standard
'custom-group-reset-standard
3735 :custom-menu
'custom-group-menu-create
)
3737 (defun custom-group-sample-face-get (widget)
3738 ;; Use :sample-face.
3739 (or (nth (1- (widget-get widget
:custom-level
)) custom-group-tag-faces
)
3742 (define-widget 'custom-group-visibility
'visibility
3743 "An indicator and manipulator for hidden group contents."
3744 :create
'custom-group-visibility-create
)
3746 (defun custom-group-visibility-create (widget)
3747 (let ((visible (widget-value widget
)))
3749 (insert "--------")))
3750 (widget-default-create widget
))
3752 (defun custom-group-members (symbol groups-only
)
3753 "Return SYMBOL's custom group members.
3754 If GROUPS-ONLY non-nil, return only those members that are groups."
3755 (if (not groups-only
)
3756 (get symbol
'custom-group
)
3758 (dolist (entry (get symbol
'custom-group
))
3759 (when (eq (nth 1 entry
) 'custom-group
)
3760 (push entry members
)))
3761 (nreverse members
))))
3763 (defun custom-group-value-create (widget)
3764 "Insert a customize group for WIDGET in the current buffer."
3765 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
3766 (custom-load-widget widget
))
3767 (let* ((state (widget-get widget
:custom-state
))
3768 (level (widget-get widget
:custom-level
))
3769 ;; (indent (widget-get widget :indent))
3770 (prefix (widget-get widget
:custom-prefix
))
3771 (buttons (widget-get widget
:buttons
))
3772 (tag (widget-get widget
:tag
))
3773 (symbol (widget-value widget
))
3774 (members (custom-group-members symbol
3775 (and (eq custom-buffer-style
'tree
)
3776 custom-browse-only-groups
))))
3777 (cond ((and (eq custom-buffer-style
'tree
)
3779 (or members
(custom-unloaded-widget-p widget
)))
3780 (custom-browse-insert-prefix prefix
)
3781 (push (widget-create-child-and-convert
3782 widget
'custom-browse-visibility
3783 ;; :tag-glyph "plus"
3787 ;; (widget-glyph-insert nil "-- " "horizontal")
3788 (push (widget-create-child-and-convert
3789 widget
'custom-browse-group-tag
)
3791 (insert " " tag
"\n")
3792 (widget-put widget
:buttons buttons
))
3793 ((and (eq custom-buffer-style
'tree
)
3794 (zerop (length members
)))
3795 (custom-browse-insert-prefix prefix
)
3797 ;; (widget-glyph-insert nil "[ ]" "empty")
3798 ;; (widget-glyph-insert nil "-- " "horizontal")
3799 (push (widget-create-child-and-convert
3800 widget
'custom-browse-group-tag
)
3802 (insert " " tag
"\n")
3803 (widget-put widget
:buttons buttons
))
3804 ((eq custom-buffer-style
'tree
)
3805 (custom-browse-insert-prefix prefix
)
3806 (if (zerop (length members
))
3808 (custom-browse-insert-prefix prefix
)
3810 ;; (widget-glyph-insert nil "[ ]" "empty")
3811 ;; (widget-glyph-insert nil "-- " "horizontal")
3812 (push (widget-create-child-and-convert
3813 widget
'custom-browse-group-tag
)
3815 (insert " " tag
"\n")
3816 (widget-put widget
:buttons buttons
))
3817 (push (widget-create-child-and-convert
3818 widget
'custom-browse-visibility
3819 ;; :tag-glyph "minus"
3823 ;; (widget-glyph-insert nil "-\\ " "top")
3824 (push (widget-create-child-and-convert
3825 widget
'custom-browse-group-tag
)
3827 (insert " " tag
"\n")
3828 (widget-put widget
:buttons buttons
)
3829 (message "Creating group...")
3830 (let* ((members (custom-sort-items members
3831 custom-browse-sort-alphabetically
3832 custom-browse-order-groups
))
3833 (prefixes (widget-get widget
:custom-prefixes
))
3834 (custom-prefix-list (custom-prefix-add symbol prefixes
))
3835 (extra-prefix (if (widget-get widget
:custom-last
)
3838 (prefix (concat prefix extra-prefix
))
3841 (setq entry
(car members
)
3842 members
(cdr members
))
3843 (push (widget-create-child-and-convert
3844 widget
(nth 1 entry
)
3846 :tag
(custom-unlispify-tag-name (nth 0 entry
))
3847 :custom-prefixes custom-prefix-list
3848 :custom-level
(1+ level
)
3849 :custom-last
(null members
)
3850 :value
(nth 0 entry
)
3851 :custom-prefix prefix
)
3853 (widget-put widget
:children
(reverse children
)))
3854 (message "Creating group...done")))
3857 ;; Create level indicator.
3859 (if (eq custom-buffer-style
'links
)
3860 (push (widget-create-child-and-convert
3861 widget
'custom-group-link
3865 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3867 (push (widget-create-child-and-convert
3868 widget
'custom-group-visibility
3869 :help-echo
"Show members of this group."
3870 :action
'custom-toggle-parent
3871 (not (eq state
'hidden
)))
3874 ;; Create magic button.
3875 (let ((magic (widget-create-child-and-convert
3876 widget
'custom-magic nil
)))
3877 (widget-put widget
:custom-magic magic
)
3878 (push magic buttons
))
3880 (widget-put widget
:buttons buttons
)
3881 ;; Insert documentation.
3882 (if (and (eq custom-buffer-style
'links
) (> level
1))
3883 (widget-put widget
:documentation-indent
0))
3884 (widget-add-documentation-string-button
3885 widget
:visibility-widget
'custom-visibility
))
3889 ;; Add parent groups references above the group.
3890 (if t
;;; This should test that the buffer
3891 ;;; was made to display a group.
3893 (if (custom-add-parent-links widget
3896 ;; Create level indicator.
3897 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3900 (let ((start (point)))
3901 (insert tag
" group: ")
3902 (widget-specify-sample widget start
(point)))
3903 (insert (widget-docstring widget
))
3904 ;; Create visibility indicator.
3905 (unless (eq custom-buffer-style
'links
)
3907 (push (widget-create-child-and-convert
3909 :help-echo
"Hide members of this group."
3910 :action
'custom-toggle-parent
3911 (not (eq state
'hidden
)))
3914 ;; Create more dashes.
3915 ;; Use 76 instead of 75 to compensate for the temporary "<"
3916 ;; added by `widget-insert'.
3917 (insert-char ?-
(- 76 (current-column)
3918 (* custom-buffer-indent level
)))
3920 ;; Create magic button.
3921 (let ((magic (widget-create-child-and-convert
3922 widget
'custom-magic
3925 (widget-put widget
:custom-magic magic
)
3926 (push magic buttons
))
3928 (widget-put widget
:buttons buttons
)
3929 ;; Insert documentation.
3930 (widget-add-documentation-string-button
3931 widget
:visibility-widget
'custom-visibility
)
3934 (if nil
;;; This should test that the buffer
3935 ;;; was not made to display a group.
3937 (insert-char ?\ custom-buffer-indent
)
3938 (custom-add-parent-links widget
)))
3939 (custom-add-see-also widget
3940 (make-string (* custom-buffer-indent level
)
3943 (message "Creating group...")
3944 (let* ((members (custom-sort-items members
3945 custom-buffer-sort-alphabetically
3946 custom-buffer-order-groups
))
3947 (prefixes (widget-get widget
:custom-prefixes
))
3948 (custom-prefix-list (custom-prefix-add symbol prefixes
))
3949 (length (length members
))
3951 (children (mapcar (lambda (entry)
3952 (widget-insert "\n")
3954 Creating group members... %2d%%"
3955 (/ (* 100.0 count
) length
))
3956 (setq count
(1+ count
))
3958 (widget-create-child-and-convert
3959 widget
(nth 1 entry
)
3961 :tag
(custom-unlispify-tag-name
3963 :custom-prefixes custom-prefix-list
3964 :custom-level
(1+ level
)
3965 :value
(nth 0 entry
))
3966 (unless (eq (preceding-char) ?
\n)
3967 (widget-insert "\n"))))
3969 (message "Creating group magic...")
3970 (mapc 'custom-magic-reset children
)
3971 (message "Creating group state...")
3972 (widget-put widget
:children children
)
3973 (custom-group-state-update widget
)
3974 (message "Creating group... done"))
3977 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3978 (insert "\\- " (widget-get widget
:tag
) " group end ")
3979 (insert-char ?-
(- 75 (current-column) (* custom-buffer-indent level
)))
3982 (defvar custom-group-menu
3983 `(("Set for Current Session" custom-group-set
3985 (eq (widget-get widget
:custom-state
) 'modified
)))
3986 ,@(when (or custom-file init-file-user
)
3987 '(("Save for Future Sessions" custom-group-save
3989 (memq (widget-get widget
:custom-state
) '(modified set
))))))
3990 ("Undo Edits" custom-group-reset-current
3992 (memq (widget-get widget
:custom-state
) '(modified))))
3993 ("Reset to Saved" custom-group-reset-saved
3995 (memq (widget-get widget
:custom-state
) '(modified set
))))
3996 ,@(when (or custom-file init-file-user
)
3997 '(("Erase Customization" custom-group-reset-standard
3999 (memq (widget-get widget
:custom-state
) '(modified set saved
)))))))
4000 "Alist of actions for the `custom-group' widget.
4001 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
4002 the menu entry, ACTION is the function to call on the widget when the
4003 menu is selected, and FILTER is a predicate which takes a `custom-group'
4004 widget as an argument, and returns non-nil if ACTION is valid on that
4005 widget. If FILTER is nil, ACTION is always valid.")
4007 (defun custom-group-action (widget &optional event
)
4008 "Show the menu for `custom-group' WIDGET.
4009 Optional EVENT is the location for the menu."
4010 (if (eq (widget-get widget
:custom-state
) 'hidden
)
4011 (custom-toggle-hide widget
)
4012 (let* ((completion-ignore-case t
)
4013 (answer (widget-choose (concat "Operation on "
4014 (custom-unlispify-tag-name
4015 (widget-get widget
:value
)))
4016 (custom-menu-filter custom-group-menu
4020 (funcall answer widget
)))))
4022 (defun custom-group-set (widget)
4023 "Set changes in all modified group members."
4024 (dolist (child (widget-get widget
:children
))
4025 (when (eq (widget-get child
:custom-state
) 'modified
)
4026 (widget-apply child
:custom-set
))))
4028 (defun custom-group-save (widget)
4029 "Save all modified group members."
4030 (dolist (child (widget-get widget
:children
))
4031 (when (memq (widget-get child
:custom-state
) '(modified set
))
4032 (widget-apply child
:custom-save
))))
4034 (defun custom-group-reset-current (widget)
4035 "Reset all modified group members."
4036 (dolist (child (widget-get widget
:children
))
4037 (when (eq (widget-get child
:custom-state
) 'modified
)
4038 (widget-apply child
:custom-reset-current
))))
4040 (defun custom-group-reset-saved (widget)
4041 "Reset all modified or set group members."
4042 (dolist (child (widget-get widget
:children
))
4043 (when (memq (widget-get child
:custom-state
) '(modified set
))
4044 (widget-apply child
:custom-reset-saved
))))
4046 (defun custom-group-reset-standard (widget)
4047 "Reset all modified, set, or saved group members."
4048 (dolist (child (widget-get widget
:children
))
4049 (when (memq (widget-get child
:custom-state
)
4050 '(modified set saved
))
4051 (widget-apply child
:custom-reset-standard
))))
4053 (defun custom-group-state-update (widget)
4055 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
4056 (let* ((children (widget-get widget
:children
))
4057 (states (mapcar (lambda (child)
4058 (widget-get child
:custom-state
))
4060 (magics custom-magic-alist
)
4063 (let ((magic (car (car magics
))))
4064 (if (and (not (eq magic
'hidden
))
4065 (memq magic states
))
4068 (setq magics
(cdr magics
)))))
4069 (widget-put widget
:custom-state found
)))
4070 (custom-magic-reset widget
))
4072 ;;; Reading and writing the custom file.
4075 (defcustom custom-file nil
4076 "File used for storing customization information.
4077 The default is nil, which means to use your init file
4078 as specified by `user-init-file'. If the value is not nil,
4079 it should be an absolute file name.
4081 You can set this option through Custom, if you carefully read the
4082 last paragraph below. However, usually it is simpler to write
4083 something like the following in your init file:
4085 \(setq custom-file \"~/.emacs-custom.el\")
4088 Note that both lines are necessary: the first line tells Custom to
4089 save all customizations in this file, but does not load it.
4091 When you change this variable outside Custom, look in the
4092 previous custom file \(usually your init file) for the
4093 forms `(custom-set-variables ...)' and `(custom-set-faces ...)',
4094 and copy them (whichever ones you find) to the new custom file.
4095 This will preserve your existing customizations.
4097 If you save this option using Custom, Custom will write all
4098 currently saved customizations, including the new one for this
4099 option itself, into the file you specify, overwriting any
4100 `custom-set-variables' and `custom-set-faces' forms already
4101 present in that file. It will not delete any customizations from
4102 the old custom file. You should do that manually if that is what you
4103 want. You also have to put something like `\(load \"CUSTOM-FILE\")
4104 in your init file, where CUSTOM-FILE is the actual name of the
4105 file. Otherwise, Emacs will not load the file when it starts up,
4106 and hence will not set `custom-file' to that file either."
4107 :type
'(choice (const :tag
"Your Emacs init file" nil
)
4108 (file :format
"%t:%v%d"
4110 "Please read entire docstring below before setting \
4111 this through Custom.
4112 Click om \"More\" \(or position point there and press RETURN)
4113 if only the first line of the docstring is shown."))
4116 (defun custom-file ()
4117 "Return the file name for saving customizations."
4120 (let ((user-init-file user-init-file
)
4122 (if (eq system-type
'ms-dos
) "~/_emacs" "~/.emacs")))
4123 (when (null user-init-file
)
4124 (if (or (file-exists-p default-init-file
)
4125 (and (eq system-type
'windows-nt
)
4126 (file-exists-p "~/_emacs")))
4127 ;; Started with -q, i.e. the file containing
4128 ;; Custom settings hasn't been read. Saving
4129 ;; settings there would overwrite other settings.
4130 (error "Saving settings from \"emacs -q\" would overwrite existing customizations"))
4131 (setq user-init-file default-init-file
))
4135 (defun custom-save-all ()
4136 "Save all customizations in `custom-file'."
4137 (when (and (null custom-file
) init-file-had-error
)
4138 (error "Cannot save customizations; init file was not fully loaded"))
4139 (let* ((filename (custom-file))
4144 (recentf-expand-file-name (custom-file)))
4147 (old-buffer (find-buffer-visiting filename
)))
4148 (with-current-buffer (let ((find-file-visit-truename t
))
4149 (or old-buffer
(find-file-noselect filename
)))
4150 (unless (eq major-mode
'emacs-lisp-mode
)
4152 (let ((inhibit-read-only t
))
4153 (custom-save-variables)
4154 (custom-save-faces))
4155 (let ((file-precious-flag t
))
4158 (kill-buffer (current-buffer))))))
4161 (defun customize-save-customized ()
4162 "Save all user options which have been set in this session."
4164 (mapatoms (lambda (symbol)
4165 (let ((face (get symbol
'customized-face
))
4166 (value (get symbol
'customized-value
))
4167 (face-comment (get symbol
'customized-face-comment
))
4169 (get symbol
'customized-variable-comment
)))
4171 (put symbol
'saved-face face
)
4172 (custom-push-theme 'theme-face symbol
'user
'set value
)
4173 (put symbol
'customized-face nil
))
4175 (put symbol
'saved-value value
)
4176 (custom-push-theme 'theme-value symbol
'user
'set value
)
4177 (put symbol
'customized-value nil
))
4178 (when variable-comment
4179 (put symbol
'saved-variable-comment variable-comment
)
4180 (put symbol
'customized-variable-comment nil
))
4182 (put symbol
'saved-face-comment face-comment
)
4183 (put symbol
'customized-face-comment nil
)))))
4184 ;; We really should update all custom buffers here.
4187 ;; Editing the custom file contents in a buffer.
4189 (defun custom-save-delete (symbol)
4190 "Delete all calls to SYMBOL from the contents of the current buffer.
4191 Leave point at the old location of the first such call,
4192 or (if there were none) at the end of the buffer.
4194 This function does not save the buffer."
4195 (goto-char (point-min))
4196 ;; Skip all whitespace and comments.
4197 (while (forward-comment 1))
4199 (save-excursion (forward-sexp (buffer-size)))) ; Test for scan errors.
4202 (while t
;; We exit this loop only via throw.
4203 ;; Skip all whitespace and comments.
4204 (while (forward-comment 1))
4205 (let ((start (point))
4206 (sexp (condition-case nil
4207 (read (current-buffer))
4208 (end-of-file (throw 'found nil
)))))
4209 (when (and (listp sexp
)
4210 (eq (car sexp
) symbol
))
4211 (delete-region start
(point))
4213 (setq first
(point)))))))
4216 ;; Move in front of local variables, otherwise long Custom
4217 ;; entries would make them ineffective.
4218 (let ((pos (point-max))
4219 (case-fold-search t
))
4221 (goto-char (point-max))
4222 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
4224 (when (search-forward "Local Variables:" nil t
)
4225 (setq pos
(line-beginning-position))))
4228 (defun custom-save-variables ()
4229 "Save all customized variables in `custom-file'."
4231 (custom-save-delete 'custom-set-variables
)
4232 (let ((standard-output (current-buffer))
4233 (saved-list (make-list 1 0))
4235 ;; First create a sorted list of saved variables.
4238 (if (and (get symbol
'saved-value
)
4239 ;; ignore theme values
4240 (or (null (get symbol
'theme-value
))
4241 (eq 'user
(caar (get symbol
'theme-value
)))))
4242 (nconc saved-list
(list symbol
)))))
4243 (setq saved-list
(sort (cdr saved-list
) 'string
<))
4246 (princ "(custom-set-variables
4247 ;; custom-set-variables was added by Custom.
4248 ;; If you edit it by hand, you could mess it up, so be careful.
4249 ;; Your init file should contain only one such instance.
4250 ;; If there is more than one, they won't work right.\n")
4251 (dolist (symbol saved-list
)
4252 (let ((spec (car-safe (get symbol
'theme-value
)))
4253 (value (get symbol
'saved-value
))
4254 (requests (get symbol
'custom-requests
))
4255 (now (and (not (custom-variable-p symbol
))
4257 (eq (get symbol
'force-value
)
4259 (comment (get symbol
'saved-variable-comment
)))
4260 ;; Check REQUESTS for validity.
4261 (dolist (request requests
)
4262 (when (and (symbolp request
) (not (featurep request
)))
4263 (message "Unknown requested feature: %s" request
)
4264 (setq requests
(delq request requests
))))
4265 ;; Is there anything customized about this variable?
4266 (when (or (and spec
(eq (car spec
) 'user
))
4268 (and (null spec
) (get symbol
'saved-value
)))
4269 ;; Output an element for this variable.
4270 ;; It has the form (SYMBOL VALUE-FORM NOW REQUESTS COMMENT).
4271 ;; SYMBOL is the variable name.
4272 ;; VALUE-FORM is an expression to return the customized value.
4273 ;; NOW if non-nil means always set the variable immediately
4274 ;; when the customizations are reloaded. This is used
4275 ;; for rogue variables
4276 ;; REQUESTS is a list of packages to load before setting the
4277 ;; variable. Each element of it will be passed to `require'.
4278 ;; COMMENT is whatever comment the user has specified
4279 ;; with the customize facility.
4286 (when (or now requests comment
)
4289 (when (or requests comment
)
4299 (unless (looking-at "\n")
4302 (defun custom-save-faces ()
4303 "Save all customized faces in `custom-file'."
4305 (custom-save-delete 'custom-reset-faces
)
4306 (custom-save-delete 'custom-set-faces
)
4307 (let ((standard-output (current-buffer))
4308 (saved-list (make-list 1 0))
4310 ;; First create a sorted list of saved faces.
4313 (if (and (get symbol
'saved-face
)
4314 (eq 'user
(car (car-safe (get symbol
'theme-face
)))))
4315 (nconc saved-list
(list symbol
)))))
4316 (setq saved-list
(sort (cdr saved-list
) 'string
<))
4317 ;; The default face must be first, since it affects the others.
4318 (if (memq 'default saved-list
)
4319 (setq saved-list
(cons 'default
(delq 'default saved-list
))))
4322 (princ "(custom-set-faces
4323 ;; custom-set-faces was added by Custom.
4324 ;; If you edit it by hand, you could mess it up, so be careful.
4325 ;; Your init file should contain only one such instance.
4326 ;; If there is more than one, they won't work right.\n")
4327 (dolist (symbol saved-list
)
4328 (let ((spec (car-safe (get symbol
'theme-face
)))
4329 (value (get symbol
'saved-face
))
4330 (now (not (or (get symbol
'face-defface-spec
)
4331 (and (not (custom-facep symbol
))
4332 (not (get symbol
'force-face
))))))
4333 (comment (get symbol
'saved-face-comment
)))
4334 (when (or (and spec
(eq (nth 0 spec
) 'user
))
4336 (and (null spec
) (get symbol
'saved-face
)))
4337 ;; Don't print default face here.
4344 (when (or now comment
)
4354 (unless (looking-at "\n")
4357 ;;; The Customize Menu.
4361 (defcustom custom-menu-nesting
2
4362 "Maximum nesting in custom menus."
4364 :group
'custom-menu
)
4366 (defun custom-face-menu-create (widget symbol
)
4367 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
4368 (vector (custom-unlispify-menu-entry symbol
)
4369 `(customize-face ',symbol
)
4372 (defun custom-variable-menu-create (widget symbol
)
4373 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
4374 (let ((type (get symbol
'custom-type
)))
4375 (unless (listp type
)
4376 (setq type
(list type
)))
4377 (if (and type
(widget-get type
:custom-menu
))
4378 (widget-apply type
:custom-menu symbol
)
4379 (vector (custom-unlispify-menu-entry symbol
)
4380 `(customize-variable ',symbol
)
4383 ;; Add checkboxes to boolean variable entries.
4384 (widget-put (get 'boolean
'widget-type
)
4385 :custom-menu
(lambda (widget symbol
)
4386 (vector (custom-unlispify-menu-entry symbol
)
4387 `(customize-variable ',symbol
)
4389 ':selected symbol
)))
4391 (defun custom-group-menu-create (widget symbol
)
4392 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
4393 `( ,(custom-unlispify-menu-entry symbol t
)
4394 :filter
(lambda (&rest junk
)
4395 (let* ((menu (custom-menu-create ',symbol
)))
4396 (if (consp menu
) (cdr menu
) menu
)))))
4399 (defun custom-menu-create (symbol)
4400 "Create menu for customization group SYMBOL.
4401 The menu is in a format applicable to `easy-menu-define'."
4402 (let* ((deactivate-mark nil
)
4403 (item (vector (custom-unlispify-menu-entry symbol
)
4404 `(customize-group ',symbol
)
4406 (if (and (or (not (boundp 'custom-menu-nesting
))
4407 (>= custom-menu-nesting
0))
4409 (custom-load-symbol symbol
)
4410 (< (length (get symbol
'custom-group
)) widget-menu-max-size
)))
4411 (let ((custom-prefix-list (custom-prefix-add symbol
4412 custom-prefix-list
))
4413 (members (custom-sort-items (get symbol
'custom-group
)
4414 custom-menu-sort-alphabetically
4415 custom-menu-order-groups
)))
4416 `(,(custom-unlispify-menu-entry symbol t
)
4419 ,@(mapcar (lambda (entry)
4420 (widget-apply (if (listp (nth 1 entry
))
4422 (list (nth 1 entry
)))
4423 :custom-menu
(nth 0 entry
)))
4428 (defun customize-menu-create (symbol &optional name
)
4429 "Return a customize menu for customization group SYMBOL.
4430 If optional NAME is given, use that as the name of the menu.
4431 Otherwise the menu will be named `Customize'.
4432 The format is suitable for use with `easy-menu-define'."
4434 (setq name
"Customize"))
4436 :filter
(lambda (&rest junk
)
4437 (let ((menu (custom-menu-create ',symbol
)))
4438 (if (consp menu
) (cdr menu
) menu
)))))
4440 ;;; Toolbar and menubar support
4443 Custom-mode-menu custom-mode-map
4444 "Menu used in customization buffers."
4445 (nconc (list "Custom"
4446 (customize-menu-create 'customize
))
4447 (mapcar (lambda (arg)
4448 (let ((tag (nth 0 arg
))
4449 (command (nth 1 arg
))
4450 (active (nth 2 arg
))
4452 (vector tag command
:active
(eval active
) :help help
)))
4455 (defvar tool-bar-map
)
4456 (defvar custom-tool-bar-map
4457 (if (display-graphic-p)
4458 (let ((map (make-sparse-keymap)))
4461 (tool-bar-local-item-from-menu
4462 (nth 1 arg
) (nth 4 arg
) map custom-mode-map
))
4466 ;;; The Custom Mode.
4468 (defun Custom-no-edit (pos &optional event
)
4469 "Invoke button at POS, or refuse to allow editing of Custom buffer."
4471 (error "You can't edit this part of the Custom buffer"))
4473 (defun Custom-newline (pos &optional event
)
4474 "Invoke button at POS, or refuse to allow editing of Custom buffer."
4476 (let ((button (get-char-property pos
'button
)))
4478 (widget-apply-action button event
)
4479 (error "You can't edit this part of the Custom buffer"))))
4481 (defvar custom-field-keymap
4482 (let ((map (copy-keymap widget-field-keymap
)))
4483 (define-key map
"\C-c\C-c" 'Custom-set
)
4484 (define-key map
"\C-x\C-s" 'Custom-save
)
4486 "Keymap used inside editable fields in customization buffers.")
4488 (widget-put (get 'editable-field
'widget-type
) :keymap custom-field-keymap
)
4490 (defun Custom-goto-parent ()
4491 "Go to the parent group listed at the top of this buffer.
4492 If several parents are listed, go to the first of them."
4495 (goto-char (point-min))
4496 (if (search-forward "\nParent groups: " nil t
)
4497 (let* ((button (get-char-property (point) 'button
))
4498 (parent (downcase (widget-get button
:tag
))))
4499 (customize-group parent
)))))
4501 (defcustom custom-mode-hook nil
4502 "Hook called when entering Custom mode."
4504 :group
'custom-buffer
)
4506 (defun custom-state-buffer-message (widget)
4507 (if (eq (widget-get (widget-get widget
:parent
) :custom-state
) 'modified
)
4508 (message "To install your edits, invoke [State] and choose the Set operation")))
4510 (defun custom-mode ()
4511 "Major mode for editing customization buffers.
4513 The following commands are available:
4516 Move to next button, link or editable field. \\[widget-forward]
4517 Move to previous button, link or editable field. \\[advertised-widget-backward]
4518 \\<custom-field-keymap>\
4519 Complete content of editable text field. \\[widget-complete]
4520 \\<custom-mode-map>\
4521 Invoke button under the mouse pointer. \\[widget-button-click]
4522 Invoke button under point. \\[widget-button-press]
4523 Set all options from current text. \\[Custom-set]
4524 Make values in current text permanent. \\[Custom-save]
4525 Make text match actual option values. \\[Custom-reset-current]
4526 Reset options to permanent settings. \\[Custom-reset-saved]
4527 Erase customizations; set options
4528 and buffer text to the standard values. \\[Custom-reset-standard]
4530 Entry to this mode calls the value of `custom-mode-hook'
4531 if that value is non-nil."
4532 (kill-all-local-variables)
4533 (setq major-mode
'custom-mode
4535 (use-local-map custom-mode-map
)
4536 (easy-menu-add Custom-mode-menu
)
4537 (set (make-local-variable 'tool-bar-map
) custom-tool-bar-map
)
4538 (make-local-variable 'custom-options
)
4539 (make-local-variable 'custom-local-buffer
)
4540 (make-local-variable 'widget-documentation-face
)
4541 (setq widget-documentation-face
'custom-documentation
)
4542 (make-local-variable 'widget-button-face
)
4543 (setq widget-button-face custom-button
)
4545 ;; We need this because of the "More" button on docstrings.
4546 ;; Otherwise clicking on "More" can push point offscreen, which
4547 ;; causes the window to recenter on point, which pushes the
4548 ;; newly-revealed docstring offscreen; which is annoying. -- cyd.
4549 (set (make-local-variable 'widget-button-click-moves-point
) t
)
4551 (set (make-local-variable 'widget-button-pressed-face
) custom-button-pressed
)
4552 (set (make-local-variable 'widget-mouse-face
) custom-button-mouse
)
4554 ;; When possible, use relief for buttons, not bracketing. This test
4555 ;; may not be optimal.
4556 (when custom-raised-buttons
4557 (set (make-local-variable 'widget-push-button-prefix
) "")
4558 (set (make-local-variable 'widget-push-button-suffix
) "")
4559 (set (make-local-variable 'widget-link-prefix
) "")
4560 (set (make-local-variable 'widget-link-suffix
) ""))
4561 (add-hook 'widget-edit-functions
'custom-state-buffer-message nil t
)
4562 (run-mode-hooks 'custom-mode-hook
))
4564 (put 'custom-mode
'mode-class
'special
)
4567 '("^No user option defaults have been changed since Emacs "
4569 "^No \\(?:customized\\|rogue\\|saved\\) user options"
4570 "^No customizable items matching "
4571 "^There are unset changes"
4572 "^Cannot set hidden variable"
4573 "^No \\(?:saved\\|backup\\) value for "
4574 "^No standard setting known for "
4575 "^No standard setting for this face"
4576 "^Saving settings from \"emacs -q\" would overwrite existing customizations"))
4577 (add-to-list 'debug-ignored-errors regexp
))
4583 ;; arch-tag: 64533aa4-1b1a-48c3-8812-f9dc718e8a6f
4584 ;;; cus-edit.el ends here