src/gnutls.c: Doc fixes. Make some functions static.
[emacs.git] / lisp / cus-edit.el
bloba333be289edac31110032864f2d41371f74323ff
1 ;;; cus-edit.el --- tools for customizing Emacs and Lisp packages
2 ;;
3 ;; Copyright (C) 1996, 1997, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
4 ;; 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
5 ;;
6 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
7 ;; Maintainer: FSF
8 ;; Keywords: help, faces
9 ;; Package: emacs
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26 ;;; Commentary:
28 ;; This file implements the code to create and edit customize buffers.
30 ;; See `custom.el'.
32 ;; No commands should have names starting with `custom-' because
33 ;; that interferes with completion. Use `customize-' for commands
34 ;; that the user will run with M-x, and `Custom-' for interactive commands.
36 ;; The identity of a customize option is represented by a Lisp symbol.
37 ;; The following values are associated with an option.
39 ;; 0. The current value.
41 ;; This is the value of the option as seen by "the rest of Emacs".
43 ;; Usually extracted by 'default-value', but can be extracted with
44 ;; different means if the option symbol has the 'custom-get'
45 ;; property. Similarly, set-default (or the 'custom-set' property)
46 ;; can set it.
48 ;; 1. The widget value.
50 ;; This is the value shown in the widget in a customize buffer.
52 ;; 2. The customized value.
54 ;; This is the last value given to the option through customize.
56 ;; It is stored in the 'customized-value' property of the option, in a
57 ;; cons-cell whose car evaluates to the customized value.
59 ;; 3. The saved value.
61 ;; This is last value saved from customize.
63 ;; It is stored in the 'saved-value' property of the option, in a
64 ;; cons-cell whose car evaluates to the saved value.
66 ;; 4. The standard value.
68 ;; This is the value given in the 'defcustom' declaration.
70 ;; It is stored in the 'standard-value' property of the option, in a
71 ;; cons-cell whose car evaluates to the standard value.
73 ;; 5. The "think" value.
75 ;; This is what customize thinks the current value should be.
77 ;; This is the customized value, if any such value exists, otherwise
78 ;; the saved value, if that exists, and as a last resort the standard
79 ;; value.
81 ;; The reason for storing values unevaluated: This is so you can have
82 ;; values that depend on the environment. For example, you can have a
83 ;; variable that has one value when Emacs is running under a window
84 ;; system, and another value on a tty. Since the evaluation is only done
85 ;; when the variable is first initialized, this is only relevant for the
86 ;; saved (and standard) values, but affect others values for
87 ;; compatibility.
89 ;; You can see (and modify and save) this unevaluated value by selecting
90 ;; "Show Saved Lisp Expression" from the Lisp interface. This will
91 ;; give you the unevaluated saved value, if any, otherwise the
92 ;; unevaluated standard value.
94 ;; The possible states for a customize widget are:
96 ;; 0. unknown
98 ;; The state has not been determined yet.
100 ;; 1. modified
102 ;; The widget value is different from the current value.
104 ;; 2. changed
106 ;; The current value is different from the "think" value.
108 ;; 3. set
110 ;; The "think" value is the customized value.
112 ;; 4. saved
114 ;; The "think" value is the saved value.
116 ;; 5. standard
118 ;; The "think" value is the standard value.
120 ;; 6. rogue
122 ;; There is no standard value. This means that the variable was
123 ;; not defined with defcustom, nor handled in cus-start.el. Most
124 ;; standard interactive Custom commands do not let you create a
125 ;; Custom buffer containing such variables. However, such Custom
126 ;; buffers can be created, for instance, by calling
127 ;; `customize-apropos' with a prefix arg or by calling
128 ;; `customize-option' non-interactively.
130 ;; 7. hidden
132 ;; There is no widget value.
134 ;; 8. mismatch
136 ;; The widget value is not valid member of the :type specified for the
137 ;; option.
139 ;;; Code:
141 (require 'cus-face)
142 (require 'wid-edit)
144 (defvar custom-versions-load-alist) ; from cus-load
145 (defvar recentf-exclude) ; from recentf.el
147 (condition-case nil
148 (require 'cus-load)
149 (error nil))
151 (condition-case nil
152 (require 'cus-start)
153 (error nil))
155 (put 'custom-define-hook 'custom-type 'hook)
156 (put 'custom-define-hook 'standard-value '(nil))
157 (custom-add-to-group 'customize 'custom-define-hook 'custom-variable)
159 ;;; Customization Groups.
161 (defgroup emacs nil
162 "Customization of the One True Editor."
163 :link '(custom-manual "(emacs)Top"))
165 ;; Most of these groups are stolen from `finder.el',
166 (defgroup editing nil
167 "Basic text editing facilities."
168 :group 'emacs)
170 (defgroup convenience nil
171 "Convenience features for faster editing."
172 :group 'emacs)
174 (defgroup files nil
175 "Support for editing files."
176 :group 'emacs)
178 (defgroup wp nil
179 "Support for editing text files."
180 :tag "Text"
181 :group 'emacs)
183 (defgroup data nil
184 "Support for editing binary data files."
185 :group 'emacs)
187 (defgroup abbrev nil
188 "Abbreviation handling, typing shortcuts, macros."
189 :tag "Abbreviations"
190 :group 'convenience)
192 (defgroup matching nil
193 "Various sorts of searching and matching."
194 :group 'editing)
196 (defgroup emulations nil
197 "Emulations of other editors."
198 :link '(custom-manual "(emacs)Emulation")
199 :group 'editing)
201 (defgroup mouse nil
202 "Mouse support."
203 :group 'editing)
205 (defgroup outlines nil
206 "Support for hierarchical outlining."
207 :group 'wp)
209 (defgroup external nil
210 "Interfacing to external utilities."
211 :group 'emacs)
213 (defgroup comm nil
214 "Communications, networking, and remote access to files."
215 :tag "Communication"
216 :group 'emacs)
218 (defgroup processes nil
219 "Process, subshell, compilation, and job control support."
220 :group 'external)
222 (defgroup programming nil
223 "Support for programming in other languages."
224 :group 'emacs)
226 (defgroup languages nil
227 "Specialized modes for editing programming languages."
228 :group 'programming)
230 (defgroup lisp nil
231 "Lisp support, including Emacs Lisp."
232 :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
233 :group 'languages
234 :group 'development)
236 (defgroup c nil
237 "Support for the C language and related languages."
238 :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
239 :link '(custom-manual "(ccmode)")
240 :group 'languages)
242 (defgroup tools nil
243 "Programming tools."
244 :group 'programming)
246 (defgroup applications nil
247 "Applications written in Emacs."
248 :group 'emacs)
250 (defgroup calendar nil
251 "Calendar and time management support."
252 :group 'applications)
254 (defgroup mail nil
255 "Modes for electronic-mail handling."
256 :group 'applications)
258 (defgroup news nil
259 "Support for netnews reading and posting."
260 :link '(custom-manual "(gnus)")
261 :group 'applications)
263 (defgroup games nil
264 "Games, jokes and amusements."
265 :group 'applications)
267 (defgroup development nil
268 "Support for further development of Emacs."
269 :group 'emacs)
271 (defgroup docs nil
272 "Support for Emacs documentation."
273 :group 'development)
275 (defgroup extensions nil
276 "Emacs Lisp language extensions."
277 :group 'development)
279 (defgroup internal nil
280 "Code for Emacs internals, build process, defaults."
281 :group 'development)
283 (defgroup maint nil
284 "Maintenance aids for the Emacs development group."
285 :tag "Maintenance"
286 :group 'development)
288 (defgroup environment nil
289 "Fitting Emacs with its environment."
290 :group 'emacs)
292 (defgroup hardware nil
293 "Support for interfacing with miscellaneous hardware."
294 :group 'environment)
296 (defgroup terminals nil
297 "Support for terminal types."
298 :group 'environment)
300 (defgroup unix nil
301 "Front-ends/assistants for, or emulators of, UNIX features."
302 :group 'environment)
304 (defgroup i18n nil
305 "Internationalization and alternate character-set support."
306 :link '(custom-manual "(emacs)International")
307 :group 'environment
308 :group 'editing)
310 (defgroup x nil
311 "The X Window system."
312 :group 'environment)
314 (defgroup frames nil
315 "Support for Emacs frames and window systems."
316 :group 'environment)
318 (defgroup tex nil
319 "Code related to the TeX formatter."
320 :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
321 :group 'wp)
323 (defgroup faces nil
324 "Support for multiple fonts."
325 :group 'emacs)
327 (defgroup help nil
328 "Support for on-line help systems."
329 :group 'emacs)
331 (defgroup multimedia nil
332 "Non-textual support, specifically images and sound."
333 :group 'emacs)
335 (defgroup local nil
336 "Code local to your site."
337 :group 'emacs)
339 (defgroup customize '((widgets custom-group))
340 "Customization of the Customization support."
341 :prefix "custom-"
342 :group 'help)
344 (defgroup custom-faces nil
345 "Faces used by customize."
346 :group 'customize
347 :group 'faces)
349 (defgroup custom-browse nil
350 "Control customize browser."
351 :prefix "custom-"
352 :group 'customize)
354 (defgroup custom-buffer nil
355 "Control customize buffers."
356 :prefix "custom-"
357 :group 'customize)
359 (defgroup custom-menu nil
360 "Control customize menus."
361 :prefix "custom-"
362 :group 'customize)
364 (defgroup alloc nil
365 "Storage allocation and gc for GNU Emacs Lisp interpreter."
366 :tag "Storage Allocation"
367 :group 'internal)
369 (defgroup undo nil
370 "Undoing changes in buffers."
371 :link '(custom-manual "(emacs)Undo")
372 :group 'editing)
374 (defgroup mode-line nil
375 "Content of the modeline."
376 :group 'environment)
378 (defgroup editing-basics nil
379 "Most basic editing facilities."
380 :group 'editing)
382 (defgroup display nil
383 "How characters are displayed in buffers."
384 :group 'environment)
386 (defgroup execute nil
387 "Executing external commands."
388 :group 'processes)
390 (defgroup installation nil
391 "The Emacs installation."
392 :group 'environment)
394 (defgroup dired nil
395 "Directory editing."
396 :group 'environment)
398 (defgroup limits nil
399 "Internal Emacs limits."
400 :group 'internal)
402 (defgroup debug nil
403 "Debugging Emacs itself."
404 :group 'development)
406 (defgroup keyboard nil
407 "Input from the keyboard."
408 :group 'environment)
410 (defgroup mouse nil
411 "Input from the mouse."
412 :group 'environment)
414 (defgroup menu nil
415 "Input from the menus."
416 :group 'environment)
418 (defgroup dnd nil
419 "Handling data from drag and drop."
420 :group 'environment)
422 (defgroup auto-save nil
423 "Preventing accidental loss of data."
424 :group 'files)
426 (defgroup processes-basics nil
427 "Basic stuff dealing with processes."
428 :group 'processes)
430 (defgroup mule nil
431 "MULE Emacs internationalization."
432 :group 'i18n)
434 (defgroup windows nil
435 "Windows within a frame."
436 :link '(custom-manual "(emacs)Windows")
437 :group 'environment)
439 ;;; Custom mode keymaps
441 (defvar custom-mode-map
442 ;; This keymap should be dense, but a dense keymap would prevent inheriting
443 ;; "\r" bindings from the parent map.
444 ;; Actually, this misfeature of dense keymaps was fixed on 2001-11-26.
445 (let ((map (make-keymap)))
446 (set-keymap-parent map widget-keymap)
447 (define-key map [remap self-insert-command] 'Custom-no-edit)
448 (define-key map "\^m" 'Custom-newline)
449 (define-key map " " 'scroll-up)
450 (define-key map "\177" 'scroll-down)
451 (define-key map "\C-c\C-c" 'Custom-set)
452 (define-key map "\C-x\C-s" 'Custom-save)
453 (define-key map "q" 'Custom-buffer-done)
454 (define-key map "u" 'Custom-goto-parent)
455 (define-key map "n" 'widget-forward)
456 (define-key map "p" 'widget-backward)
457 map)
458 "Keymap for `Custom-mode'.")
460 (defvar custom-mode-link-map
461 (let ((map (make-keymap)))
462 (set-keymap-parent map custom-mode-map)
463 (define-key map [down-mouse-2] nil)
464 (define-key map [down-mouse-1] 'mouse-drag-region)
465 (define-key map [mouse-2] 'widget-move-and-invoke)
466 map)
467 "Local keymap for links in `Custom-mode'.")
469 (defvar custom-field-keymap
470 (let ((map (copy-keymap widget-field-keymap)))
471 (define-key map "\C-c\C-c" 'Custom-set)
472 (define-key map "\C-x\C-s" 'Custom-save)
473 map)
474 "Keymap used inside editable fields in customization buffers.")
476 (widget-put (get 'editable-field 'widget-type) :keymap custom-field-keymap)
478 ;;; Utilities.
480 (defun custom-split-regexp-maybe (regexp)
481 "If REGEXP is a string, split it to a list at `\\|'.
482 You can get the original back from the result with:
483 (mapconcat 'identity result \"\\|\")
485 IF REGEXP is not a string, return it unchanged."
486 (if (stringp regexp)
487 (split-string regexp "\\\\|")
488 regexp))
490 (defun custom-variable-prompt ()
491 "Prompt for a custom variable, defaulting to the variable at point.
492 Return a list suitable for use in `interactive'."
493 (let* ((v (variable-at-point))
494 (default (and (symbolp v) (custom-variable-p v) (symbol-name v)))
495 (enable-recursive-minibuffers t)
496 val)
497 (setq val (completing-read
498 (if default (format "Customize variable (default %s): " default)
499 "Customize variable: ")
500 obarray 'custom-variable-p t nil nil default))
501 (list (if (equal val "")
502 (if (symbolp v) v nil)
503 (intern val)))))
505 (defun custom-menu-filter (menu widget)
506 "Convert MENU to the form used by `widget-choose'.
507 MENU should be in the same format as `custom-variable-menu'.
508 WIDGET is the widget to apply the filter entries of MENU on."
509 (let ((result nil)
510 current name action filter)
511 (while menu
512 (setq current (car menu)
513 name (nth 0 current)
514 action (nth 1 current)
515 filter (nth 2 current)
516 menu (cdr menu))
517 (if (or (null filter) (funcall filter widget))
518 (push (cons name action) result)
519 (push name result)))
520 (nreverse result)))
522 ;;; Unlispify.
524 (defvar custom-prefix-list nil
525 "List of prefixes that should be ignored by `custom-unlispify'.")
527 (defcustom custom-unlispify-menu-entries t
528 "Display menu entries as words instead of symbols if non-nil."
529 :group 'custom-menu
530 :type 'boolean)
532 (defcustom custom-unlispify-remove-prefixes nil
533 "Non-nil means remove group prefixes from option names in buffer."
534 :group 'custom-menu
535 :group 'custom-buffer
536 :type 'boolean)
538 (defun custom-unlispify-menu-entry (symbol &optional no-suffix)
539 "Convert SYMBOL into a menu entry."
540 (cond ((not custom-unlispify-menu-entries)
541 (symbol-name symbol))
542 ((get symbol 'custom-tag)
543 (if no-suffix
544 (get symbol 'custom-tag)
545 (concat (get symbol 'custom-tag) "...")))
547 (with-current-buffer (get-buffer-create " *Custom-Work*")
548 (erase-buffer)
549 (princ symbol (current-buffer))
550 (goto-char (point-min))
551 ;; FIXME: Boolean variables are not predicates, so they shouldn't
552 ;; end with `-p'. -stef
553 ;; (when (and (eq (get symbol 'custom-type) 'boolean)
554 ;; (re-search-forward "-p\\'" nil t))
555 ;; (replace-match "" t t)
556 ;; (goto-char (point-min)))
557 (if custom-unlispify-remove-prefixes
558 (let ((prefixes custom-prefix-list)
559 prefix)
560 (while prefixes
561 (setq prefix (car prefixes))
562 (if (search-forward prefix (+ (point) (length prefix)) t)
563 (progn
564 (setq prefixes nil)
565 (delete-region (point-min) (point)))
566 (setq prefixes (cdr prefixes))))))
567 (subst-char-in-region (point-min) (point-max) ?- ?\ t)
568 (capitalize-region (point-min) (point-max))
569 (unless no-suffix
570 (goto-char (point-max))
571 (insert "..."))
572 (buffer-string)))))
574 (defcustom custom-unlispify-tag-names t
575 "Display tag names as words instead of symbols if non-nil."
576 :group 'custom-buffer
577 :type 'boolean)
579 (defun custom-unlispify-tag-name (symbol)
580 "Convert SYMBOL into a menu entry."
581 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names))
582 (custom-unlispify-menu-entry symbol t)))
584 (defun custom-prefix-add (symbol prefixes)
585 "Add SYMBOL to list of ignored PREFIXES."
586 (cons (or (get symbol 'custom-prefix)
587 (concat (symbol-name symbol) "-"))
588 prefixes))
590 ;;; Guess.
592 (defcustom custom-guess-name-alist
593 '(("-p\\'" boolean)
594 ("-flag\\'" boolean)
595 ("-hook\\'" hook)
596 ("-face\\'" face)
597 ("-file\\'" file)
598 ("-function\\'" function)
599 ("-functions\\'" (repeat function))
600 ("-list\\'" (repeat sexp))
601 ("-alist\\'" (repeat (cons sexp sexp))))
602 "Alist of (MATCH TYPE).
604 MATCH should be a regexp matching the name of a symbol, and TYPE should
605 be a widget suitable for editing the value of that symbol. The TYPE
606 of the first entry where MATCH matches the name of the symbol will be
607 used.
609 This is used for guessing the type of variables not declared with
610 customize."
611 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
612 :group 'custom-buffer)
614 (defcustom custom-guess-doc-alist
615 '(("\\`\\*?Non-nil " boolean))
616 "Alist of (MATCH TYPE).
618 MATCH should be a regexp matching a documentation string, and TYPE
619 should be a widget suitable for editing the value of a variable with
620 that documentation string. The TYPE of the first entry where MATCH
621 matches the name of the symbol will be used.
623 This is used for guessing the type of variables not declared with
624 customize."
625 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
626 :group 'custom-buffer)
628 (defun custom-guess-type (symbol)
629 "Guess a widget suitable for editing the value of SYMBOL.
630 This is done by matching SYMBOL with `custom-guess-name-alist' and
631 if that fails, the doc string with `custom-guess-doc-alist'."
632 (let ((name (symbol-name symbol))
633 (names custom-guess-name-alist)
634 current found)
635 (while names
636 (setq current (car names)
637 names (cdr names))
638 (when (string-match (nth 0 current) name)
639 (setq found (nth 1 current)
640 names nil)))
641 (unless found
642 (let ((doc (documentation-property symbol 'variable-documentation))
643 (docs custom-guess-doc-alist))
644 (when doc
645 (while docs
646 (setq current (car docs)
647 docs (cdr docs))
648 (when (string-match (nth 0 current) doc)
649 (setq found (nth 1 current)
650 docs nil))))))
651 found))
653 ;;; Sorting.
655 ;;;###autoload
656 (defcustom custom-browse-sort-alphabetically nil
657 "If non-nil, sort customization group alphabetically in `custom-browse'."
658 :type 'boolean
659 :group 'custom-browse)
661 (defcustom custom-browse-order-groups nil
662 "If non-nil, order group members within each customization group.
663 If `first', order groups before non-groups.
664 If `last', order groups after non-groups."
665 :type '(choice (const first)
666 (const last)
667 (const :tag "none" nil))
668 :group 'custom-browse)
670 (defcustom custom-browse-only-groups nil
671 "If non-nil, show group members only within each customization group."
672 :type 'boolean
673 :group 'custom-browse)
675 ;;;###autoload
676 (defcustom custom-buffer-sort-alphabetically t
677 "Whether to sort customization groups alphabetically in Custom buffer."
678 :type 'boolean
679 :group 'custom-buffer
680 :version "24.1")
682 (defcustom custom-buffer-order-groups 'last
683 "If non-nil, order group members within each customization group.
684 If `first', order groups before non-groups.
685 If `last', order groups after non-groups."
686 :type '(choice (const first)
687 (const last)
688 (const :tag "none" nil))
689 :group 'custom-buffer)
691 ;;;###autoload
692 (defcustom custom-menu-sort-alphabetically nil
693 "If non-nil, sort each customization group alphabetically in menus."
694 :type 'boolean
695 :group 'custom-menu)
697 (defcustom custom-menu-order-groups 'first
698 "If non-nil, order group members within each customization group.
699 If `first', order groups before non-groups.
700 If `last', order groups after non-groups."
701 :type '(choice (const first)
702 (const last)
703 (const :tag "none" nil))
704 :group 'custom-menu)
706 ;;;###autoload (add-hook 'same-window-regexps (purecopy "\\`\\*Customiz.*\\*\\'"))
708 (defun custom-sort-items (items sort-alphabetically order-groups)
709 "Return a sorted copy of ITEMS.
710 ITEMS should be a `custom-group' property.
711 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
712 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
713 groups after non-groups, if nil do not order groups at all."
714 (sort (copy-sequence items)
715 (lambda (a b)
716 (let ((typea (nth 1 a)) (typeb (nth 1 b))
717 (namea (nth 0 a)) (nameb (nth 0 b)))
718 (cond ((not order-groups)
719 ;; Since we don't care about A and B order, maybe sort.
720 (when sort-alphabetically
721 (string-lessp namea nameb)))
722 ((eq typea 'custom-group)
723 ;; If B is also a group, maybe sort. Otherwise, order A and B.
724 (if (eq typeb 'custom-group)
725 (when sort-alphabetically
726 (string-lessp namea nameb))
727 (eq order-groups 'first)))
728 ((eq typeb 'custom-group)
729 ;; Since A cannot be a group, order A and B.
730 (eq order-groups 'last))
731 (sort-alphabetically
732 ;; Since A and B cannot be groups, sort.
733 (string-lessp namea nameb)))))))
735 ;;; Custom Mode Commands.
737 ;; This variable is used by `custom-tool-bar-map', or directly by
738 ;; `custom-buffer-create-internal' if `custom-buffer-verbose-help' is non-nil.
740 (defvar custom-commands
741 '(("Set for current session" Custom-set t
742 "Apply all settings in this buffer to the current session"
743 "index"
744 "Apply")
745 ("Save for future sessions" Custom-save
746 (or custom-file user-init-file)
747 "Apply all settings in this buffer and save them for future Emacs sessions."
748 "save"
749 "Save")
750 ("Undo edits" Custom-reset-current t
751 "Restore all settings in this buffer to reflect their current values."
752 "refresh"
753 "Undo")
754 ("Reset to saved" Custom-reset-saved t
755 "Restore all settings in this buffer to their saved values (if any)."
756 "undo"
757 "Reset")
758 ("Erase customizations" Custom-reset-standard
759 (or custom-file user-init-file)
760 "Un-customize all settings in this buffer and save them with standard values."
761 "delete"
762 "Uncustomize")
763 ("Help for Customize" Custom-help t
764 "Get help for using Customize."
765 "help"
766 "Help")
767 ("Exit" Custom-buffer-done t "Exit Customize." "exit" "Exit")))
769 (defun Custom-help ()
770 "Read the node on Easy Customization in the Emacs manual."
771 (interactive)
772 (info "(emacs)Easy Customization"))
774 (defvar custom-reset-menu
775 '(("Undo Edits" . Custom-reset-current)
776 ("Reset to Saved" . Custom-reset-saved)
777 ("Erase Customizations (use standard values)" . Custom-reset-standard))
778 "Alist of actions for the `Reset' button.
779 The key is a string containing the name of the action, the value is a
780 Lisp function taking the widget as an element which will be called
781 when the action is chosen.")
783 (defvar custom-options nil
784 "Customization widgets in the current buffer.")
786 (defun custom-command-apply (fun query &optional strong-query)
787 "Call function FUN on all widgets in `custom-options'.
788 If there is more than one widget, ask user for confirmation using
789 the query string QUERY, using `y-or-n-p' if STRONG-QUERY is nil,
790 and `yes-or-no-p' otherwise."
791 (if (or (and (= 1 (length custom-options))
792 (memq (widget-type (car custom-options))
793 '(custom-variable custom-face)))
794 (funcall (if strong-query 'yes-or-no-p 'y-or-n-p) query))
795 (progn (mapc fun custom-options) t)
796 (message "Aborted")
797 nil))
799 (defun Custom-set (&rest ignore)
800 "Set the current value of all edited settings in the buffer."
801 (interactive)
802 (custom-command-apply
803 (lambda (child)
804 (when (eq (widget-get child :custom-state) 'modified)
805 (widget-apply child :custom-set)))
806 "Set all values according to this buffer? "))
808 (defun Custom-save (&rest ignore)
809 "Set all edited settings, then save all settings that have been set.
810 If a setting was edited and set before, this saves it. If a
811 setting was merely edited before, this sets it then saves it."
812 (interactive)
813 (when (custom-command-apply
814 (lambda (child)
815 (when (memq (widget-get child :custom-state)
816 '(modified set changed rogue))
817 (widget-apply child :custom-mark-to-save)))
818 "Save all settings in this buffer? " t)
819 ;; Save changes to buffer and redraw.
820 (custom-save-all)
821 (dolist (child custom-options)
822 (widget-apply child :custom-state-set-and-redraw))))
824 (defun custom-reset (widget &optional event)
825 "Select item from reset menu."
826 (let* ((completion-ignore-case t)
827 (answer (widget-choose "Reset settings"
828 custom-reset-menu
829 event)))
830 (if answer
831 (funcall answer))))
833 (defun Custom-reset-current (&rest ignore)
834 "Reset all edited settings in the buffer to show their current values."
835 (interactive)
836 (custom-command-apply
837 (lambda (widget)
838 (if (memq (widget-get widget :custom-state) '(modified changed))
839 (widget-apply widget :custom-reset-current)))
840 "Reset all settings' buffer text to show current values? "))
842 (defun Custom-reset-saved (&rest ignore)
843 "Reset all edited or set settings in the buffer to their saved value.
844 This also shows the saved values in the buffer."
845 (interactive)
846 (custom-command-apply
847 (lambda (widget)
848 (if (memq (widget-get widget :custom-state) '(modified set changed rogue))
849 (widget-apply widget :custom-reset-saved)))
850 "Reset all settings (current values and buffer text) to saved values? "))
852 ;; The next two variables are bound to '(t) by `Custom-reset-standard'
853 ;; and `custom-group-reset-standard'. If these variables are nil, both
854 ;; `custom-variable-reset-standard' and `custom-face-reset-standard'
855 ;; save, reset and redraw the handled widget immediately. Otherwise,
856 ;; they add the widget to the corresponding list and leave it to
857 ;; `custom-reset-standard-save-and-update' to save, reset and redraw it.
858 (defvar custom-reset-standard-variables-list nil)
859 (defvar custom-reset-standard-faces-list nil)
861 ;; The next function was excerpted from `custom-variable-reset-standard'
862 ;; and `custom-face-reset-standard' and is used to avoid calling
863 ;; `custom-save-all' repeatedly (and thus saving settings to file one by
864 ;; one) when erasing all customizations.
865 (defun custom-reset-standard-save-and-update ()
866 "Save settings and redraw after erasing customizations."
867 (when (or (and custom-reset-standard-variables-list
868 (not (eq custom-reset-standard-variables-list '(t))))
869 (and custom-reset-standard-faces-list
870 (not (eq custom-reset-standard-faces-list '(t)))))
871 ;; Save settings to file.
872 (custom-save-all)
873 ;; Set state of and redraw variables.
874 (dolist (widget custom-reset-standard-variables-list)
875 (unless (eq widget t)
876 (widget-put widget :custom-state 'unknown)
877 (custom-redraw widget)))
878 ;; Set state of and redraw faces.
879 (dolist (widget custom-reset-standard-faces-list)
880 (unless (eq widget t)
881 (let* ((symbol (widget-value widget))
882 (child (car (widget-get widget :children)))
883 (value (get symbol 'face-defface-spec))
884 (comment-widget (widget-get widget :comment-widget)))
885 (put symbol 'face-comment nil)
886 (widget-value-set child
887 (custom-pre-filter-face-spec
888 (list (list t (custom-face-attributes-get
889 symbol nil)))))
890 ;; This call manages the comment visibility
891 (widget-value-set comment-widget "")
892 (custom-face-state-set widget)
893 (custom-redraw-magic widget))))))
895 (defun Custom-reset-standard (&rest ignore)
896 "Erase all customizations (either current or saved) in current buffer.
897 The immediate result is to restore them to their standard values.
898 This operation eliminates any saved values for the group members,
899 making them as if they had never been customized at all."
900 (interactive)
901 ;; Bind these temporarily.
902 (let ((custom-reset-standard-variables-list '(t))
903 (custom-reset-standard-faces-list '(t)))
904 (custom-command-apply
905 (lambda (widget)
906 (and (or (null (widget-get widget :custom-standard-value))
907 (widget-apply widget :custom-standard-value))
908 (memq (widget-get widget :custom-state)
909 '(modified set changed saved rogue))
910 (widget-apply widget :custom-mark-to-reset-standard)))
911 "Erase all customizations for settings in this buffer? " t)
912 (custom-reset-standard-save-and-update)))
914 ;;; The Customize Commands
916 (defun custom-prompt-variable (prompt-var prompt-val &optional comment)
917 "Prompt for a variable and a value and return them as a list.
918 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
919 prompt for the value. The %s escape in PROMPT-VAL is replaced with
920 the name of the variable.
922 If the variable has a `variable-interactive' property, that is used as if
923 it were the arg to `interactive' (which see) to interactively read the value.
925 If the variable has a `custom-type' property, it must be a widget and the
926 `:prompt-value' property of that widget will be used for reading the value.
928 If optional COMMENT argument is non-nil, also prompt for a comment and return
929 it as the third element in the list."
930 (let* ((var (read-variable prompt-var))
931 (minibuffer-help-form '(describe-variable var))
932 (val
933 (let ((prop (get var 'variable-interactive))
934 (type (get var 'custom-type))
935 (prompt (format prompt-val var)))
936 (unless (listp type)
937 (setq type (list type)))
938 (cond (prop
939 ;; Use VAR's `variable-interactive' property
940 ;; as an interactive spec for prompting.
941 (call-interactively `(lambda (arg)
942 (interactive ,prop)
943 arg)))
944 (type
945 (widget-prompt-value type
946 prompt
947 (if (boundp var)
948 (symbol-value var))
949 (not (boundp var))))
951 (eval-minibuffer prompt))))))
952 (if comment
953 (list var val
954 (read-string "Comment: " (get var 'variable-comment)))
955 (list var val))))
957 ;;;###autoload
958 (defun customize-set-value (variable value &optional comment)
959 "Set VARIABLE to VALUE, and return VALUE. VALUE is a Lisp object.
961 If VARIABLE has a `variable-interactive' property, that is used as if
962 it were the arg to `interactive' (which see) to interactively read the value.
964 If VARIABLE has a `custom-type' property, it must be a widget and the
965 `:prompt-value' property of that widget will be used for reading the value.
967 If given a prefix (or a COMMENT argument), also prompt for a comment."
968 (interactive (custom-prompt-variable "Set variable: "
969 "Set %s to value: "
970 current-prefix-arg))
972 (cond ((string= comment "")
973 (put variable 'variable-comment nil))
974 (comment
975 (put variable 'variable-comment comment)))
976 (set variable value))
978 ;;;###autoload
979 (defun customize-set-variable (variable value &optional comment)
980 "Set the default for VARIABLE to VALUE, and return VALUE.
981 VALUE is a Lisp object.
983 If VARIABLE has a `custom-set' property, that is used for setting
984 VARIABLE, otherwise `set-default' is used.
986 If VARIABLE has a `variable-interactive' property, that is used as if
987 it were the arg to `interactive' (which see) to interactively read the value.
989 If VARIABLE has a `custom-type' property, it must be a widget and the
990 `:prompt-value' property of that widget will be used for reading the value.
992 If given a prefix (or a COMMENT argument), also prompt for a comment."
993 (interactive (custom-prompt-variable "Set variable: "
994 "Set customized value for %s to: "
995 current-prefix-arg))
996 (custom-load-symbol variable)
997 (custom-push-theme 'theme-value variable 'user 'set (custom-quote value))
998 (funcall (or (get variable 'custom-set) 'set-default) variable value)
999 (put variable 'customized-value (list (custom-quote value)))
1000 (cond ((string= comment "")
1001 (put variable 'variable-comment nil)
1002 (put variable 'customized-variable-comment nil))
1003 (comment
1004 (put variable 'variable-comment comment)
1005 (put variable 'customized-variable-comment comment)))
1006 value)
1008 ;;;###autoload
1009 (defun customize-save-variable (variable value &optional comment)
1010 "Set the default for VARIABLE to VALUE, and save it for future sessions.
1011 Return VALUE.
1013 If VARIABLE has a `custom-set' property, that is used for setting
1014 VARIABLE, otherwise `set-default' is used.
1016 If VARIABLE has a `variable-interactive' property, that is used as if
1017 it were the arg to `interactive' (which see) to interactively read the value.
1019 If VARIABLE has a `custom-type' property, it must be a widget and the
1020 `:prompt-value' property of that widget will be used for reading the value.
1022 If given a prefix (or a COMMENT argument), also prompt for a comment."
1023 (interactive (custom-prompt-variable "Set and save variable: "
1024 "Set and save value for %s as: "
1025 current-prefix-arg))
1026 (funcall (or (get variable 'custom-set) 'set-default) variable value)
1027 (put variable 'saved-value (list (custom-quote value)))
1028 (custom-push-theme 'theme-value variable 'user 'set (custom-quote value))
1029 (cond ((string= comment "")
1030 (put variable 'variable-comment nil)
1031 (put variable 'saved-variable-comment nil))
1032 (comment
1033 (put variable 'variable-comment comment)
1034 (put variable 'saved-variable-comment comment)))
1035 (put variable 'customized-value nil)
1036 (put variable 'customized-variable-comment nil)
1037 (custom-save-all)
1038 value)
1040 ;;;###autoload
1041 (defun customize ()
1042 "Select a customization buffer which you can use to set user options.
1043 User options are structured into \"groups\".
1044 Initially the top-level group `Emacs' and its immediate subgroups
1045 are shown; the contents of those subgroups are initially hidden."
1046 (interactive)
1047 (customize-group 'emacs))
1049 ;;;###autoload
1050 (defun customize-mode (mode)
1051 "Customize options related to the current major mode.
1052 If a prefix \\[universal-argument] was given (or if the current major mode has no known group),
1053 then prompt for the MODE to customize."
1054 (interactive
1055 (list
1056 (let ((completion-regexp-list '("-mode\\'"))
1057 (group (custom-group-of-mode major-mode)))
1058 (if (and group (not current-prefix-arg))
1059 major-mode
1060 (intern
1061 (completing-read (if group
1062 (format "Major mode (default %s): " major-mode)
1063 "Major mode: ")
1064 obarray
1065 'custom-group-of-mode
1066 t nil nil (if group (symbol-name major-mode))))))))
1067 (customize-group (custom-group-of-mode mode)))
1069 (defun customize-read-group ()
1070 (let ((completion-ignore-case t))
1071 (completing-read "Customize group (default emacs): "
1072 obarray
1073 (lambda (symbol)
1074 (or (and (get symbol 'custom-loads)
1075 (not (get symbol 'custom-autoload)))
1076 (get symbol 'custom-group)))
1077 t)))
1079 ;;;###autoload
1080 (defun customize-group (&optional group)
1081 "Customize GROUP, which must be a customization group."
1082 (interactive (list (customize-read-group)))
1083 (when (stringp group)
1084 (if (string-equal "" group)
1085 (setq group 'emacs)
1086 (setq group (intern group))))
1087 (let ((name (format "*Customize Group: %s*"
1088 (custom-unlispify-tag-name group))))
1089 (if (get-buffer name)
1090 (pop-to-buffer name)
1091 (custom-buffer-create
1092 (list (list group 'custom-group))
1093 name
1094 (concat " for group "
1095 (custom-unlispify-tag-name group))))))
1097 ;;;###autoload
1098 (defun customize-group-other-window (&optional group)
1099 "Customize GROUP, which must be a customization group, in another window."
1100 (interactive (list (customize-read-group)))
1101 (let ((pop-up-windows t)
1102 (same-window-buffer-names nil)
1103 (same-window-regexps nil))
1104 (customize-group group)))
1106 ;;;###autoload
1107 (defalias 'customize-variable 'customize-option)
1109 ;;;###autoload
1110 (defun customize-option (symbol)
1111 "Customize SYMBOL, which must be a user option variable."
1112 (interactive (custom-variable-prompt))
1113 (unless symbol
1114 (error "No variable specified"))
1115 (let ((basevar (indirect-variable symbol)))
1116 (custom-buffer-create (list (list basevar 'custom-variable))
1117 (format "*Customize Option: %s*"
1118 (custom-unlispify-tag-name basevar)))
1119 (unless (eq symbol basevar)
1120 (message "`%s' is an alias for `%s'" symbol basevar))))
1122 ;;;###autoload
1123 (defalias 'customize-variable-other-window 'customize-option-other-window)
1125 ;;;###autoload
1126 (defun customize-option-other-window (symbol)
1127 "Customize SYMBOL, which must be a user option variable.
1128 Show the buffer in another window, but don't select it."
1129 (interactive (custom-variable-prompt))
1130 (unless symbol
1131 (error "No variable specified"))
1132 (let ((basevar (indirect-variable symbol)))
1133 (custom-buffer-create-other-window
1134 (list (list basevar 'custom-variable))
1135 (format "*Customize Option: %s*" (custom-unlispify-tag-name basevar)))
1136 (unless (eq symbol basevar)
1137 (message "`%s' is an alias for `%s'" symbol basevar))))
1139 (defvar customize-changed-options-previous-release "23.1"
1140 "Version for `customize-changed-options' to refer back to by default.")
1142 ;; Packages will update this variable, so make it available.
1143 ;;;###autoload
1144 (defvar customize-package-emacs-version-alist nil
1145 "Alist mapping versions of a package to Emacs versions.
1146 We use this for packages that have their own names, but are released
1147 as part of Emacs itself.
1149 Each elements looks like this:
1151 (PACKAGE (PVERSION . EVERSION)...)
1153 Here PACKAGE is the name of a package, as a symbol. After
1154 PACKAGE come one or more elements, each associating a
1155 package version PVERSION with the first Emacs version
1156 EVERSION in which it (or a subsequent version of PACKAGE)
1157 was first released. Both PVERSION and EVERSION are strings.
1158 PVERSION should be a string that this package used in
1159 the :package-version keyword for `defcustom', `defgroup',
1160 and `defface'.
1162 For example, the MH-E package updates this alist as follows:
1164 (add-to-list 'customize-package-emacs-version-alist
1165 '(MH-E (\"6.0\" . \"22.1\") (\"6.1\" . \"22.1\")
1166 (\"7.0\" . \"22.1\") (\"7.1\" . \"22.1\")
1167 (\"7.2\" . \"22.1\") (\"7.3\" . \"22.1\")
1168 (\"7.4\" . \"22.1\") (\"8.0\" . \"22.1\")))
1170 The value of PACKAGE needs to be unique and it needs to match the
1171 PACKAGE value appearing in the :package-version keyword. Since
1172 the user might see the value in a error message, a good choice is
1173 the official name of the package, such as MH-E or Gnus.")
1175 ;;;###autoload
1176 (defalias 'customize-changed 'customize-changed-options)
1178 ;;;###autoload
1179 (defun customize-changed-options (&optional since-version)
1180 "Customize all settings whose meanings have changed in Emacs itself.
1181 This includes new user option variables and faces, and new
1182 customization groups, as well as older options and faces whose meanings
1183 or default values have changed since the previous major Emacs release.
1185 With argument SINCE-VERSION (a string), customize all settings
1186 that were added or redefined since that version."
1188 (interactive
1189 (list
1190 (read-from-minibuffer
1191 (format "Customize options changed, since version (default %s): "
1192 customize-changed-options-previous-release))))
1193 (if (equal since-version "")
1194 (setq since-version nil)
1195 (unless (condition-case nil
1196 (numberp (read since-version))
1197 (error nil))
1198 (signal 'wrong-type-argument (list 'numberp since-version))))
1199 (unless since-version
1200 (setq since-version customize-changed-options-previous-release))
1202 ;; Load the information for versions since since-version. We use
1203 ;; custom-load-symbol for this.
1204 (put 'custom-versions-load-alist 'custom-loads nil)
1205 (dolist (elt custom-versions-load-alist)
1206 (if (customize-version-lessp since-version (car elt))
1207 (dolist (load (cdr elt))
1208 (custom-add-load 'custom-versions-load-alist load))))
1209 (custom-load-symbol 'custom-versions-load-alist)
1210 (put 'custom-versions-load-alist 'custom-loads nil)
1212 (let (found)
1213 (mapatoms
1214 (lambda (symbol)
1215 (let* ((package-version (get symbol 'custom-package-version))
1216 (version
1217 (or (and package-version
1218 (customize-package-emacs-version symbol
1219 package-version))
1220 (get symbol 'custom-version))))
1221 (if version
1222 (when (customize-version-lessp since-version version)
1223 (if (or (get symbol 'custom-group)
1224 (get symbol 'group-documentation))
1225 (push (list symbol 'custom-group) found))
1226 (if (custom-variable-p symbol)
1227 (push (list symbol 'custom-variable) found))
1228 (if (custom-facep symbol)
1229 (push (list symbol 'custom-face) found)))))))
1230 (if found
1231 (custom-buffer-create (custom-sort-items found t 'first)
1232 "*Customize Changed Options*")
1233 (error "No user option defaults have been changed since Emacs %s"
1234 since-version))))
1236 (defun customize-package-emacs-version (symbol package-version)
1237 "Return the Emacs version in which SYMBOL's meaning last changed.
1238 PACKAGE-VERSION has the form (PACKAGE . VERSION). We use
1239 `customize-package-emacs-version-alist' to find the version of
1240 Emacs that is associated with version VERSION of PACKAGE."
1241 (let (package-versions emacs-version)
1242 ;; Use message instead of error since we want user to be able to
1243 ;; see the rest of the symbols even if a package author has
1244 ;; botched things up.
1245 (cond ((not (listp package-version))
1246 (message "Invalid package-version value for %s" symbol))
1247 ((setq package-versions (assq (car package-version)
1248 customize-package-emacs-version-alist))
1249 (setq emacs-version
1250 (cdr (assoc (cdr package-version) package-versions)))
1251 (unless emacs-version
1252 (message "%s version %s not found in %s" symbol
1253 (cdr package-version)
1254 "customize-package-emacs-version-alist")))
1256 (message "Package %s version %s lists no corresponding Emacs version"
1257 (car package-version)
1258 (cdr package-version))))
1259 emacs-version))
1261 (defun customize-version-lessp (version1 version2)
1262 ;; Why are the versions strings, and given that they are, why aren't
1263 ;; they converted to numbers and compared as such here? -- fx
1265 ;; In case someone made a mistake and left out the quotes
1266 ;; in the :version value.
1267 (if (numberp version2)
1268 (setq version2 (prin1-to-string version2)))
1269 (let (major1 major2 minor1 minor2)
1270 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version1)
1271 (setq major1 (read (or (match-string 1 version1)
1272 "0")))
1273 (setq minor1 (read (or (match-string 3 version1)
1274 "0")))
1275 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version2)
1276 (setq major2 (read (or (match-string 1 version2)
1277 "0")))
1278 (setq minor2 (read (or (match-string 3 version2)
1279 "0")))
1280 (or (< major1 major2)
1281 (and (= major1 major2)
1282 (< minor1 minor2)))))
1284 ;;;###autoload
1285 (defun customize-face (&optional face)
1286 "Customize FACE, which should be a face name or nil.
1287 If FACE is nil, customize all faces. If FACE is actually a
1288 face-alias, customize the face it is aliased to.
1290 Interactively, when point is on text which has a face specified,
1291 suggest to customize that face, if it's customizable."
1292 (interactive (list (read-face-name "Customize face" "all faces" t)))
1293 (if (member face '(nil ""))
1294 (setq face (face-list)))
1295 (if (and (listp face) (null (cdr face)))
1296 (setq face (car face)))
1297 (if (listp face)
1298 (custom-buffer-create
1299 (custom-sort-items
1300 (mapcar (lambda (s) (list s 'custom-face)) face)
1301 t nil)
1302 "*Customize Faces*")
1303 ;; If FACE is actually an alias, customize the face it is aliased to.
1304 (if (get face 'face-alias)
1305 (setq face (get face 'face-alias)))
1306 (unless (facep face)
1307 (error "Invalid face %S" face))
1308 (custom-buffer-create
1309 (list (list face 'custom-face))
1310 (format "*Customize Face: %s*"
1311 (custom-unlispify-tag-name face)))))
1313 ;;;###autoload
1314 (defun customize-face-other-window (&optional face)
1315 "Show customization buffer for face FACE in other window.
1316 If FACE is actually a face-alias, customize the face it is aliased to.
1318 Interactively, when point is on text which has a face specified,
1319 suggest to customize that face, if it's customizable."
1320 (interactive (list (read-face-name "Customize face" "all faces" t)))
1321 (let ((pop-up-windows t)
1322 (same-window-buffer-names nil)
1323 (same-window-regexps nil))
1324 (customize-face face)))
1326 (defalias 'customize-customized 'customize-unsaved)
1328 ;;;###autoload
1329 (defun customize-unsaved ()
1330 "Customize all user options set in this session but not saved."
1331 (interactive)
1332 (let ((found nil))
1333 (mapatoms (lambda (symbol)
1334 (and (or (get symbol 'customized-face)
1335 (get symbol 'customized-face-comment))
1336 (custom-facep symbol)
1337 (push (list symbol 'custom-face) found))
1338 (and (or (get symbol 'customized-value)
1339 (get symbol 'customized-variable-comment))
1340 (boundp symbol)
1341 (push (list symbol 'custom-variable) found))))
1342 (if (not found)
1343 (error "No user options are set but unsaved")
1344 (custom-buffer-create (custom-sort-items found t nil)
1345 "*Customize Unsaved*"))))
1347 ;;;###autoload
1348 (defun customize-rogue ()
1349 "Customize all user variables modified outside customize."
1350 (interactive)
1351 (let ((found nil))
1352 (mapatoms (lambda (symbol)
1353 (let ((cval (or (get symbol 'customized-value)
1354 (get symbol 'saved-value)
1355 (get symbol 'standard-value))))
1356 (when (and cval ;Declared with defcustom.
1357 (default-boundp symbol) ;Has a value.
1358 (not (equal (eval (car cval))
1359 ;; Which does not match customize.
1360 (default-value symbol))))
1361 (push (list symbol 'custom-variable) found)))))
1362 (if (not found)
1363 (error "No rogue user options")
1364 (custom-buffer-create (custom-sort-items found t nil)
1365 "*Customize Rogue*"))))
1366 ;;;###autoload
1367 (defun customize-saved ()
1368 "Customize all already saved user options."
1369 (interactive)
1370 (let ((found nil))
1371 (mapatoms (lambda (symbol)
1372 (and (or (get symbol 'saved-face)
1373 (get symbol 'saved-face-comment))
1374 (custom-facep symbol)
1375 (push (list symbol 'custom-face) found))
1376 (and (or (get symbol 'saved-value)
1377 (get symbol 'saved-variable-comment))
1378 (boundp symbol)
1379 (push (list symbol 'custom-variable) found))))
1380 (if (not found )
1381 (error "No saved user options")
1382 (custom-buffer-create (custom-sort-items found t nil)
1383 "*Customize Saved*"))))
1385 (declare-function apropos-parse-pattern "apropos" (pattern))
1387 ;;;###autoload
1388 (defun customize-apropos (pattern &optional type)
1389 "Customize all loaded options, faces and groups matching PATTERN.
1390 PATTERN can be a word, a list of words (separated by spaces),
1391 or a regexp (using some regexp special characters). If it is a word,
1392 search for matches for that word as a substring. If it is a list of words,
1393 search for matches for any two (or more) of those words.
1395 If TYPE is `options', include only options.
1396 If TYPE is `faces', include only faces.
1397 If TYPE is `groups', include only groups.
1398 If TYPE is t (interactively, with prefix arg), include variables
1399 that are not customizable options, as well as faces and groups
1400 \(but we recommend using `apropos-variable' instead)."
1401 (interactive (list (apropos-read-pattern "symbol") current-prefix-arg))
1402 (require 'apropos)
1403 (apropos-parse-pattern pattern)
1404 (let (found tests)
1405 (mapatoms
1406 `(lambda (symbol)
1407 (when (string-match apropos-regexp (symbol-name symbol))
1408 ,(if (not (memq type '(faces options)))
1409 '(if (get symbol 'custom-group)
1410 (push (list symbol 'custom-group) found)))
1411 ,(if (not (memq type '(options groups)))
1412 '(if (custom-facep symbol)
1413 (push (list symbol 'custom-face) found)))
1414 ,(if (not (memq type '(groups faces)))
1415 `(if (and (boundp symbol)
1416 (eq (indirect-variable symbol) symbol)
1417 (or (get symbol 'saved-value)
1418 (custom-variable-p symbol)
1419 ,(if (not (memq type '(nil options)))
1420 '(get symbol 'variable-documentation))))
1421 (push (list symbol 'custom-variable) found))))))
1422 (if (not found)
1423 (error "No %s matching %s"
1424 (if (eq type t)
1425 "items"
1426 (format "customizable %s"
1427 (if (memq type '(options faces groups))
1428 (symbol-name type)
1429 "items")))
1430 pattern)
1431 (custom-buffer-create
1432 (custom-sort-items found t custom-buffer-order-groups)
1433 "*Customize Apropos*"))))
1435 ;;;###autoload
1436 (defun customize-apropos-options (regexp &optional arg)
1437 "Customize all loaded customizable options matching REGEXP.
1438 With prefix ARG, include variables that are not customizable options
1439 \(but it is better to use `apropos-variable' if you want to find those)."
1440 (interactive "sCustomize options (regexp): \nP")
1441 (customize-apropos regexp (or arg 'options)))
1443 ;;;###autoload
1444 (defun customize-apropos-faces (regexp)
1445 "Customize all loaded faces matching REGEXP."
1446 (interactive "sCustomize faces (regexp): \n")
1447 (customize-apropos regexp 'faces))
1449 ;;;###autoload
1450 (defun customize-apropos-groups (regexp)
1451 "Customize all loaded groups matching REGEXP."
1452 (interactive "sCustomize groups (regexp): \n")
1453 (customize-apropos regexp 'groups))
1455 ;;; Buffer.
1457 (defcustom custom-buffer-style 'links
1458 "Control the presentation style for customization buffers.
1459 The value should be a symbol, one of:
1461 brackets: groups nest within each other with big horizontal brackets.
1462 links: groups have links to subgroups."
1463 :type '(radio (const brackets)
1464 (const links))
1465 :group 'custom-buffer)
1467 (defcustom custom-buffer-done-kill nil
1468 "Non-nil means exiting a Custom buffer should kill it."
1469 :type 'boolean
1470 :version "22.1"
1471 :group 'custom-buffer)
1473 (defcustom custom-buffer-indent 3
1474 "Number of spaces to indent nested groups."
1475 :type 'integer
1476 :group 'custom-buffer)
1478 (defun custom-get-fresh-buffer (name)
1479 "Get a fresh new buffer with name NAME.
1480 If the buffer already exist, clean it up to be like new.
1481 Beware: it's not quite like new. Good enough for custom, but maybe
1482 not for everybody."
1483 ;; To be more complete, we should also kill all permanent-local variables,
1484 ;; but it's not needed for custom.
1485 (let ((buf (get-buffer name)))
1486 (when (and buf (buffer-local-value 'buffer-file-name buf))
1487 ;; This will check if the file is not saved.
1488 (kill-buffer buf)
1489 (setq buf nil))
1490 (if (null buf)
1491 (get-buffer-create name)
1492 (with-current-buffer buf
1493 (kill-all-local-variables)
1494 (run-hooks 'kill-buffer-hook)
1495 ;; Delete overlays before erasing the buffer so the overlay hooks
1496 ;; don't get run spuriously when we erase the buffer.
1497 (let ((ols (overlay-lists)))
1498 (dolist (ol (nconc (car ols) (cdr ols)))
1499 (delete-overlay ol)))
1500 (erase-buffer)
1501 buf))))
1503 ;;;###autoload
1504 (defun custom-buffer-create (options &optional name description)
1505 "Create a buffer containing OPTIONS.
1506 Optional NAME is the name of the buffer.
1507 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1508 SYMBOL is a customization option, and WIDGET is a widget for editing
1509 that option."
1510 (pop-to-buffer (custom-get-fresh-buffer (or name "*Customization*")))
1511 (custom-buffer-create-internal options description))
1513 ;;;###autoload
1514 (defun custom-buffer-create-other-window (options &optional name description)
1515 "Create a buffer containing OPTIONS, and display it in another window.
1516 The result includes selecting that window.
1517 Optional NAME is the name of the buffer.
1518 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1519 SYMBOL is a customization option, and WIDGET is a widget for editing
1520 that option."
1521 (unless name (setq name "*Customization*"))
1522 (let ((pop-up-windows t)
1523 (same-window-buffer-names nil)
1524 (same-window-regexps nil))
1525 (pop-to-buffer (custom-get-fresh-buffer name))
1526 (custom-buffer-create-internal options description)))
1528 (defcustom custom-reset-button-menu nil
1529 "If non-nil, only show a single reset button in customize buffers.
1530 This button will have a menu with all three reset operations."
1531 :type 'boolean
1532 :group 'custom-buffer)
1534 (defcustom custom-buffer-verbose-help t
1535 "If non-nil, include explanatory text in the customization buffer."
1536 :type 'boolean
1537 :group 'custom-buffer)
1539 (defun Custom-buffer-done (&rest ignore)
1540 "Exit current Custom buffer according to `custom-buffer-done-kill'."
1541 (interactive)
1542 (quit-window custom-buffer-done-kill))
1544 (defvar custom-button nil
1545 "Face used for buttons in customization buffers.")
1547 (defvar custom-button-mouse nil
1548 "Mouse face used for buttons in customization buffers.")
1550 (defvar custom-button-pressed nil
1551 "Face used for pressed buttons in customization buffers.")
1553 (defcustom custom-search-field t
1554 "If non-nil, show a search field in Custom buffers."
1555 :type 'boolean
1556 :version "24.1"
1557 :group 'custom-buffer)
1559 (defcustom custom-raised-buttons (not (equal (face-valid-attribute-values :box)
1560 '(("unspecified" . unspecified))))
1561 "If non-nil, indicate active buttons in a `raised-button' style.
1562 Otherwise use brackets."
1563 :type 'boolean
1564 :version "21.1"
1565 :group 'custom-buffer
1566 :set (lambda (variable value)
1567 (custom-set-default variable value)
1568 (setq custom-button
1569 (if value 'custom-button 'custom-button-unraised))
1570 (setq custom-button-mouse
1571 (if value 'custom-button-mouse 'highlight))
1572 (setq custom-button-pressed
1573 (if value
1574 'custom-button-pressed
1575 'custom-button-pressed-unraised))))
1577 (defun custom-buffer-create-internal (options &optional description)
1578 (Custom-mode)
1579 (let ((init-file (or custom-file user-init-file)))
1580 ;; Insert verbose help at the top of the custom buffer.
1581 (when custom-buffer-verbose-help
1582 (widget-insert (if init-file
1583 "To apply changes, use the Save or Set buttons."
1584 "Custom settings cannot be saved; maybe you started Emacs with `-q'.")
1585 "\nFor details, see ")
1586 (widget-create 'custom-manual
1587 :tag "Saving Customizations"
1588 "(emacs)Saving Customizations")
1589 (widget-insert " in the ")
1590 (widget-create 'custom-manual
1591 :tag "Emacs manual"
1592 :help-echo "Read the Emacs manual."
1593 "(emacs)Top")
1594 (widget-insert "."))
1595 (widget-insert "\n")
1597 ;; Insert the search field.
1598 (when custom-search-field
1599 (widget-insert "\n")
1600 (let* ((echo "Search for custom items")
1601 (search-widget
1602 (widget-create
1603 'editable-field
1604 :size 40 :help-echo echo
1605 :action `(lambda (widget &optional event)
1606 (customize-apropos (widget-value widget))))))
1607 (widget-insert " ")
1608 (widget-create-child-and-convert
1609 search-widget 'push-button
1610 :tag "Search"
1611 :help-echo echo :action
1612 (lambda (widget &optional event)
1613 (customize-apropos (widget-value (widget-get widget :parent)))))
1614 (widget-insert "\n")))
1616 ;; The custom command buttons are also in the toolbar, so for a
1617 ;; time they were not inserted in the buffer if the toolbar was in use.
1618 ;; But it can be a little confusing for the buffer layout to
1619 ;; change according to whether or nor the toolbar is on, not to
1620 ;; mention that a custom buffer can in theory be created in a
1621 ;; frame with a toolbar, then later viewed in one without.
1622 ;; So now the buttons are always inserted in the buffer. (Bug#1326)
1623 (if custom-buffer-verbose-help
1624 (widget-insert "
1625 Operate on all settings in this buffer:\n"))
1626 (let ((button (lambda (tag action active help icon label)
1627 (widget-insert " ")
1628 (if (eval active)
1629 (widget-create 'push-button :tag tag
1630 :help-echo help :action action))))
1631 (commands custom-commands))
1632 (apply button (pop commands)) ; Set for current session
1633 (apply button (pop commands)) ; Save for future sessions
1634 (if custom-reset-button-menu
1635 (progn
1636 (widget-insert " ")
1637 (widget-create 'push-button
1638 :tag "Reset buffer"
1639 :help-echo "Show a menu with reset operations."
1640 :mouse-down-action 'ignore
1641 :action 'custom-reset))
1642 (widget-insert "\n")
1643 (apply button (pop commands)) ; Undo edits
1644 (apply button (pop commands)) ; Reset to saved
1645 (apply button (pop commands)) ; Erase customization
1646 (widget-insert " ")
1647 (pop commands) ; Help (omitted)
1648 (apply button (pop commands)))) ; Exit
1649 (widget-insert "\n\n"))
1651 ;; Now populate the custom buffer.
1652 (message "Creating customization items...")
1653 (buffer-disable-undo)
1654 (setq custom-options
1655 (if (= (length options) 1)
1656 (mapcar (lambda (entry)
1657 (widget-create (nth 1 entry)
1658 :documentation-shown t
1659 :custom-state 'unknown
1660 :tag (custom-unlispify-tag-name
1661 (nth 0 entry))
1662 :value (nth 0 entry)))
1663 options)
1664 (let ((count 0)
1665 (length (length options)))
1666 (mapcar (lambda (entry)
1667 (prog2
1668 (message "Creating customization items ...%2d%%"
1669 (/ (* 100.0 count) length))
1670 (widget-create (nth 1 entry)
1671 :tag (custom-unlispify-tag-name
1672 (nth 0 entry))
1673 :value (nth 0 entry))
1674 (setq count (1+ count))
1675 (unless (eq (preceding-char) ?\n)
1676 (widget-insert "\n"))
1677 (widget-insert "\n")))
1678 options))))
1679 (unless (eq (preceding-char) ?\n)
1680 (widget-insert "\n"))
1681 (message "Creating customization items ...done")
1682 (message "Resetting customization items...")
1683 (unless (eq custom-buffer-style 'tree)
1684 (mapc 'custom-magic-reset custom-options))
1685 (message "Resetting customization items...done")
1686 (message "Creating customization setup...")
1687 (widget-setup)
1688 (buffer-enable-undo)
1689 (goto-char (point-min))
1690 (message "Creating customization setup...done"))
1692 ;;; The Tree Browser.
1694 ;;;###autoload
1695 (defun customize-browse (&optional group)
1696 "Create a tree browser for the customize hierarchy."
1697 (interactive)
1698 (unless group
1699 (setq group 'emacs))
1700 (let ((name "*Customize Browser*"))
1701 (pop-to-buffer (custom-get-fresh-buffer name)))
1702 (Custom-mode)
1703 (widget-insert (format "\
1704 %s buttons; type RET or click mouse-1
1705 on a button to invoke its action.
1706 Invoke [+] to expand a group, and [-] to collapse an expanded group.\n"
1707 (if custom-raised-buttons
1708 "`Raised' text indicates"
1709 "Square brackets indicate")))
1712 (if custom-browse-only-groups
1713 (widget-insert "\
1714 Invoke the [Group] button below to edit that item in another window.\n\n")
1715 (widget-insert "Invoke the ")
1716 (widget-create 'item
1717 :format "%t"
1718 :tag "[Group]"
1719 :tag-glyph "folder")
1720 (widget-insert ", ")
1721 (widget-create 'item
1722 :format "%t"
1723 :tag "[Face]"
1724 :tag-glyph "face")
1725 (widget-insert ", and ")
1726 (widget-create 'item
1727 :format "%t"
1728 :tag "[Option]"
1729 :tag-glyph "option")
1730 (widget-insert " buttons below to edit that
1731 item in another window.\n\n"))
1732 (let ((custom-buffer-style 'tree))
1733 (widget-create 'custom-group
1734 :custom-last t
1735 :custom-state 'unknown
1736 :tag (custom-unlispify-tag-name group)
1737 :value group))
1738 (widget-setup)
1739 (goto-char (point-min)))
1741 (define-widget 'custom-browse-visibility 'item
1742 "Control visibility of items in the customize tree browser."
1743 :format "%[[%t]%]"
1744 :action 'custom-browse-visibility-action)
1746 (defun custom-browse-visibility-action (widget &rest ignore)
1747 (let ((custom-buffer-style 'tree))
1748 (custom-toggle-parent widget)))
1750 (define-widget 'custom-browse-group-tag 'custom-group-link
1751 "Show parent in other window when activated."
1752 :tag "Group"
1753 :tag-glyph "folder"
1754 :action 'custom-browse-group-tag-action)
1756 (defun custom-browse-group-tag-action (widget &rest ignore)
1757 (let ((parent (widget-get widget :parent)))
1758 (customize-group-other-window (widget-value parent))))
1760 (define-widget 'custom-browse-variable-tag 'custom-group-link
1761 "Show parent in other window when activated."
1762 :tag "Option"
1763 :tag-glyph "option"
1764 :action 'custom-browse-variable-tag-action)
1766 (defun custom-browse-variable-tag-action (widget &rest ignore)
1767 (let ((parent (widget-get widget :parent)))
1768 (customize-variable-other-window (widget-value parent))))
1770 (define-widget 'custom-browse-face-tag 'custom-group-link
1771 "Show parent in other window when activated."
1772 :tag "Face"
1773 :tag-glyph "face"
1774 :action 'custom-browse-face-tag-action)
1776 (defun custom-browse-face-tag-action (widget &rest ignore)
1777 (let ((parent (widget-get widget :parent)))
1778 (customize-face-other-window (widget-value parent))))
1780 (defconst custom-browse-alist '((" " "space")
1781 (" | " "vertical")
1782 ("-\\ " "top")
1783 (" |-" "middle")
1784 (" `-" "bottom")))
1786 (defun custom-browse-insert-prefix (prefix)
1787 "Insert PREFIX. On XEmacs convert it to line graphics."
1788 ;; Fixme: do graphics.
1789 (if nil ; (featurep 'xemacs)
1790 (progn
1791 (insert "*")
1792 (while (not (string-equal prefix ""))
1793 (let ((entry (substring prefix 0 3)))
1794 (setq prefix (substring prefix 3))
1795 (let ((overlay (make-overlay (1- (point)) (point) nil t nil))
1796 (name (nth 1 (assoc entry custom-browse-alist))))
1797 (overlay-put overlay 'end-glyph (widget-glyph-find name entry))
1798 (overlay-put overlay 'start-open t)
1799 (overlay-put overlay 'end-open t)))))
1800 (insert prefix)))
1802 ;;; Modification of Basic Widgets.
1804 ;; We add extra properties to the basic widgets needed here. This is
1805 ;; fine, as long as we are careful to stay within our own namespace.
1807 ;; We want simple widgets to be displayed by default, but complex
1808 ;; widgets to be hidden.
1810 (widget-put (get 'item 'widget-type) :custom-show t)
1811 (widget-put (get 'editable-field 'widget-type)
1812 :custom-show (lambda (widget value)
1813 (let ((pp (pp-to-string value)))
1814 (cond ((string-match "\n" pp)
1815 nil)
1816 ((> (length pp) 40)
1817 nil)
1818 (t t)))))
1819 (widget-put (get 'menu-choice 'widget-type) :custom-show t)
1821 ;;; The `custom-manual' Widget.
1823 (define-widget 'custom-manual 'info-link
1824 "Link to the manual entry for this customization option."
1825 :help-echo "Read the manual entry for this option."
1826 :keymap custom-mode-link-map
1827 :follow-link 'mouse-face
1828 :button-face 'custom-link
1829 :mouse-face 'highlight
1830 :pressed-face 'highlight
1831 :tag "Manual")
1833 ;;; The `custom-magic' Widget.
1835 (defgroup custom-magic-faces nil
1836 "Faces used by the magic button."
1837 :group 'custom-faces
1838 :group 'custom-buffer)
1840 (defface custom-invalid '((((class color))
1841 (:foreground "yellow1" :background "red1"))
1843 (:weight bold :slant italic :underline t)))
1844 "Face used when the customize item is invalid."
1845 :group 'custom-magic-faces)
1846 (define-obsolete-face-alias 'custom-invalid-face 'custom-invalid "22.1")
1848 (defface custom-rogue '((((class color))
1849 (:foreground "pink" :background "black"))
1851 (:underline t)))
1852 "Face used when the customize item is not defined for customization."
1853 :group 'custom-magic-faces)
1854 (define-obsolete-face-alias 'custom-rogue-face 'custom-rogue "22.1")
1856 (defface custom-modified '((((min-colors 88) (class color))
1857 (:foreground "white" :background "blue1"))
1858 (((class color))
1859 (:foreground "white" :background "blue"))
1861 (:slant italic :bold)))
1862 "Face used when the customize item has been modified."
1863 :group 'custom-magic-faces)
1864 (define-obsolete-face-alias 'custom-modified-face 'custom-modified "22.1")
1866 (defface custom-set '((((min-colors 88) (class color))
1867 (:foreground "blue1" :background "white"))
1868 (((class color))
1869 (:foreground "blue" :background "white"))
1871 (:slant italic)))
1872 "Face used when the customize item has been set."
1873 :group 'custom-magic-faces)
1874 (define-obsolete-face-alias 'custom-set-face 'custom-set "22.1")
1876 (defface custom-changed '((((min-colors 88) (class color))
1877 (:foreground "white" :background "blue1"))
1878 (((class color))
1879 (:foreground "white" :background "blue"))
1881 (:slant italic)))
1882 "Face used when the customize item has been changed."
1883 :group 'custom-magic-faces)
1884 (define-obsolete-face-alias 'custom-changed-face 'custom-changed "22.1")
1886 (defface custom-themed '((((min-colors 88) (class color))
1887 (:foreground "white" :background "blue1"))
1888 (((class color))
1889 (:foreground "white" :background "blue"))
1891 (:slant italic)))
1892 "Face used when the customize item has been set by a theme."
1893 :group 'custom-magic-faces)
1895 (defface custom-saved '((t (:underline t)))
1896 "Face used when the customize item has been saved."
1897 :group 'custom-magic-faces)
1898 (define-obsolete-face-alias 'custom-saved-face 'custom-saved "22.1")
1900 (defconst custom-magic-alist
1901 '((nil "#" underline "\
1902 UNINITIALIZED, you should not see this.")
1903 (unknown "?" italic "\
1904 UNKNOWN, you should not see this.")
1905 (hidden "-" default "\
1906 HIDDEN, invoke \"Show\" in the previous line to show." "\
1907 group now hidden, invoke \"Show\", above, to show contents.")
1908 (invalid "x" custom-invalid "\
1909 INVALID, the displayed value cannot be set.")
1910 (modified "*" custom-modified "\
1911 EDITED, shown value does not take effect until you set or save it." "\
1912 something in this group has been edited but not set.")
1913 (set "+" custom-set "\
1914 SET for current session only." "\
1915 something in this group has been set but not saved.")
1916 (changed ":" custom-changed "\
1917 CHANGED outside Customize; operating on it here may be unreliable." "\
1918 something in this group has been changed outside customize.")
1919 (saved "!" custom-saved "\
1920 SAVED and set." "\
1921 something in this group has been set and saved.")
1922 (themed "o" custom-themed "\
1923 THEMED." "\
1924 visible group members are all at standard values.")
1925 (rogue "@" custom-rogue "\
1926 NO CUSTOMIZATION DATA; not intended to be customized." "\
1927 something in this group is not prepared for customization.")
1928 (standard " " nil "\
1929 STANDARD." "\
1930 visible group members are all at standard values."))
1931 "Alist of customize option states.
1932 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1934 STATE is one of the following symbols:
1936 `nil'
1937 For internal use, should never occur.
1938 `unknown'
1939 For internal use, should never occur.
1940 `hidden'
1941 This item is not being displayed.
1942 `invalid'
1943 This item is modified, but has an invalid form.
1944 `modified'
1945 This item is modified, and has a valid form.
1946 `set'
1947 This item has been set but not saved.
1948 `changed'
1949 The current value of this item has been changed outside Customize.
1950 `saved'
1951 This item is marked for saving.
1952 `rogue'
1953 This item has no customization information.
1954 `standard'
1955 This item is unchanged from the standard setting.
1957 MAGIC is a string used to present that state.
1959 FACE is a face used to present the state.
1961 ITEM-DESC is a string describing the state for options.
1963 GROUP-DESC is a string describing the state for groups. If this is
1964 left out, ITEM-DESC will be used.
1966 The string %c in either description will be replaced with the
1967 category of the item. These are `group'. `option', and `face'.
1969 The list should be sorted most significant first.")
1971 (defcustom custom-magic-show 'long
1972 "If non-nil, show textual description of the state.
1973 If `long', show a full-line description, not just one word."
1974 :type '(choice (const :tag "no" nil)
1975 (const long)
1976 (other :tag "short" short))
1977 :group 'custom-buffer)
1979 (defcustom custom-magic-show-hidden '(option face)
1980 "Control whether the State button is shown for hidden items.
1981 The value should be a list with the custom categories where the State
1982 button should be visible. Possible categories are `group', `option',
1983 and `face'."
1984 :type '(set (const group) (const option) (const face))
1985 :group 'custom-buffer)
1987 (defcustom custom-magic-show-button nil
1988 "Show a \"magic\" button indicating the state of each customization option."
1989 :type 'boolean
1990 :group 'custom-buffer)
1992 (define-widget 'custom-magic 'default
1993 "Show and manipulate state for a customization option."
1994 :format "%v"
1995 :action 'widget-parent-action
1996 :notify 'ignore
1997 :value-get 'ignore
1998 :value-create 'custom-magic-value-create
1999 :value-delete 'widget-children-value-delete)
2001 (defun widget-magic-mouse-down-action (widget &optional event)
2002 ;; Non-nil unless hidden.
2003 (not (eq (widget-get (widget-get (widget-get widget :parent) :parent)
2004 :custom-state)
2005 'hidden)))
2007 (defun custom-magic-value-create (widget)
2008 "Create compact status report for WIDGET."
2009 (let* ((parent (widget-get widget :parent))
2010 (state (widget-get parent :custom-state))
2011 (hidden (eq state 'hidden))
2012 (entry (assq state custom-magic-alist))
2013 (magic (nth 1 entry))
2014 (face (nth 2 entry))
2015 (category (widget-get parent :custom-category))
2016 (text (or (and (eq category 'group)
2017 (nth 4 entry))
2018 (nth 3 entry)))
2019 (form (widget-get parent :custom-form))
2020 children)
2021 (unless (eq state 'hidden)
2022 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text)
2023 (setq text (concat (match-string 1 text)
2024 (symbol-name category)
2025 (match-string 2 text))))
2026 (when (and custom-magic-show
2027 (or (not hidden)
2028 (memq category custom-magic-show-hidden)))
2029 (insert " ")
2030 (when (and (eq category 'group)
2031 (not (and (eq custom-buffer-style 'links)
2032 (> (widget-get parent :custom-level) 1))))
2033 (insert-char ?\ (* custom-buffer-indent
2034 (widget-get parent :custom-level))))
2035 (push (widget-create-child-and-convert
2036 widget 'choice-item
2037 :help-echo "Change the state of this item."
2038 :format (if hidden "%t" "%[%t%]")
2039 :button-prefix 'widget-push-button-prefix
2040 :button-suffix 'widget-push-button-suffix
2041 :mouse-down-action 'widget-magic-mouse-down-action
2042 :tag "State")
2043 children)
2044 (insert ": ")
2045 (let ((start (point)))
2046 (if (eq custom-magic-show 'long)
2047 (insert text)
2048 (insert (symbol-name state)))
2049 (cond ((eq form 'lisp)
2050 (insert " (lisp)"))
2051 ((eq form 'mismatch)
2052 (insert " (mismatch)")))
2053 (put-text-property start (point) 'face 'custom-state))
2054 (insert "\n"))
2055 (when (and (eq category 'group)
2056 (not (and (eq custom-buffer-style 'links)
2057 (> (widget-get parent :custom-level) 1))))
2058 (insert-char ?\ (* custom-buffer-indent
2059 (widget-get parent :custom-level))))
2060 (when custom-magic-show-button
2061 (when custom-magic-show
2062 (let ((indent (widget-get parent :indent)))
2063 (when indent
2064 (insert-char ? indent))))
2065 (push (widget-create-child-and-convert
2066 widget 'choice-item
2067 :mouse-down-action 'widget-magic-mouse-down-action
2068 :button-face face
2069 :button-prefix ""
2070 :button-suffix ""
2071 :help-echo "Change the state."
2072 :format (if hidden "%t" "%[%t%]")
2073 :tag (if (memq form '(lisp mismatch))
2074 (concat "(" magic ")")
2075 (concat "[" magic "]")))
2076 children)
2077 (insert " "))
2078 (widget-put widget :children children))))
2080 (defun custom-magic-reset (widget)
2081 "Redraw the :custom-magic property of WIDGET."
2082 (let ((magic (widget-get widget :custom-magic)))
2083 (widget-value-set magic (widget-value magic))))
2085 ;;; The `custom' Widget.
2087 (defface custom-button
2088 '((((type x w32 ns) (class color)) ; Like default modeline
2089 (:box (:line-width 2 :style released-button)
2090 :background "lightgrey" :foreground "black"))
2092 nil))
2093 "Face for custom buffer buttons if `custom-raised-buttons' is non-nil."
2094 :version "21.1"
2095 :group 'custom-faces)
2096 (define-obsolete-face-alias 'custom-button-face 'custom-button "22.1")
2098 (defface custom-button-mouse
2099 '((((type x w32 ns) (class color))
2100 (:box (:line-width 2 :style released-button)
2101 :background "grey90" :foreground "black"))
2103 ;; This is for text terminals that support mouse, like GPM mouse
2104 ;; or the MS-DOS terminal: inverse-video makes the button stand
2105 ;; out on mouse-over.
2106 (:inverse-video t)))
2107 "Mouse face for custom buffer buttons if `custom-raised-buttons' is non-nil."
2108 :version "22.1"
2109 :group 'custom-faces)
2111 (defface custom-button-unraised
2112 '((t :inherit underline))
2113 "Face for custom buffer buttons if `custom-raised-buttons' is nil."
2114 :version "22.1"
2115 :group 'custom-faces)
2117 (setq custom-button
2118 (if custom-raised-buttons 'custom-button 'custom-button-unraised))
2120 (setq custom-button-mouse
2121 (if custom-raised-buttons 'custom-button-mouse 'highlight))
2123 (defface custom-button-pressed
2124 '((((type x w32 ns) (class color))
2125 (:box (:line-width 2 :style pressed-button)
2126 :background "lightgrey" :foreground "black"))
2128 (:inverse-video t)))
2129 "Face for pressed custom buttons if `custom-raised-buttons' is non-nil."
2130 :version "21.1"
2131 :group 'custom-faces)
2132 (define-obsolete-face-alias 'custom-button-pressed-face
2133 'custom-button-pressed "22.1")
2135 (defface custom-button-pressed-unraised
2136 '((default :inherit custom-button-unraised)
2137 (((class color) (background light)) :foreground "magenta4")
2138 (((class color) (background dark)) :foreground "violet"))
2139 "Face for pressed custom buttons if `custom-raised-buttons' is nil."
2140 :version "22.1"
2141 :group 'custom-faces)
2143 (setq custom-button-pressed
2144 (if custom-raised-buttons
2145 'custom-button-pressed
2146 'custom-button-pressed-unraised))
2148 (defface custom-documentation '((t nil))
2149 "Face used for documentation strings in customization buffers."
2150 :group 'custom-faces)
2151 (define-obsolete-face-alias 'custom-documentation-face
2152 'custom-documentation "22.1")
2154 (defface custom-state '((((class color)
2155 (background dark))
2156 (:foreground "lime green"))
2157 (((class color)
2158 (background light))
2159 (:foreground "dark green"))
2160 (t nil))
2161 "Face used for State descriptions in the customize buffer."
2162 :group 'custom-faces)
2163 (define-obsolete-face-alias 'custom-state-face 'custom-state "22.1")
2165 (defface custom-link
2166 '((t :inherit link))
2167 "Face for links in customization buffers."
2168 :version "22.1"
2169 :group 'custom-faces)
2171 (define-widget 'custom 'default
2172 "Customize a user option."
2173 :format "%v"
2174 :convert-widget 'custom-convert-widget
2175 :notify 'custom-notify
2176 :custom-prefix ""
2177 :custom-level 1
2178 :custom-state 'hidden
2179 :documentation-property 'widget-subclass-responsibility
2180 :value-create 'widget-subclass-responsibility
2181 :value-delete 'widget-children-value-delete
2182 :value-get 'widget-value-value-get
2183 :validate 'widget-children-validate
2184 :match (lambda (widget value) (symbolp value)))
2186 (defun custom-convert-widget (widget)
2187 "Initialize :value and :tag from :args in WIDGET."
2188 (let ((args (widget-get widget :args)))
2189 (when args
2190 (widget-put widget :value (widget-apply widget
2191 :value-to-internal (car args)))
2192 (widget-put widget :tag (custom-unlispify-tag-name (car args)))
2193 (widget-put widget :args nil)))
2194 widget)
2196 (defun custom-notify (widget &rest args)
2197 "Keep track of changes."
2198 (let ((state (widget-get widget :custom-state)))
2199 (unless (eq state 'modified)
2200 (unless (memq state '(nil unknown hidden))
2201 (widget-put widget :custom-state 'modified))
2202 (custom-magic-reset widget)
2203 (apply 'widget-default-notify widget args))))
2205 (defun custom-redraw (widget)
2206 "Redraw WIDGET with current settings."
2207 (let ((line (count-lines (point-min) (point)))
2208 (column (current-column))
2209 (pos (point))
2210 (from (marker-position (widget-get widget :from)))
2211 (to (marker-position (widget-get widget :to))))
2212 (save-excursion
2213 (widget-value-set widget (widget-value widget))
2214 (custom-redraw-magic widget))
2215 (when (and (>= pos from) (<= pos to))
2216 (condition-case nil
2217 (progn
2218 (goto-char (point-min))
2219 (forward-line (if (> column 0)
2220 (1- line)
2221 line))
2222 (move-to-column column))
2223 (error nil)))))
2225 (defun custom-redraw-magic (widget)
2226 "Redraw WIDGET state with current settings."
2227 (while widget
2228 (let ((magic (widget-get widget :custom-magic)))
2229 (cond (magic
2230 (widget-value-set magic (widget-value magic))
2231 (when (setq widget (widget-get widget :group))
2232 (custom-group-state-update widget)))
2234 (setq widget nil)))))
2235 (widget-setup))
2237 (defun custom-show (widget value)
2238 "Non-nil if WIDGET should be shown with VALUE by default."
2239 (let ((show (widget-get widget :custom-show)))
2240 (if (functionp show)
2241 (funcall show widget value)
2242 show)))
2244 (defun custom-load-widget (widget)
2245 "Load all dependencies for WIDGET."
2246 (custom-load-symbol (widget-value widget)))
2248 (defun custom-unloaded-symbol-p (symbol)
2249 "Return non-nil if the dependencies of SYMBOL have not yet been loaded."
2250 (let ((found nil)
2251 (loads (get symbol 'custom-loads))
2252 load)
2253 (while loads
2254 (setq load (car loads)
2255 loads (cdr loads))
2256 (cond ((symbolp load)
2257 (unless (featurep load)
2258 (setq found t)))
2259 ((assoc load load-history))
2260 ((assoc (locate-library load) load-history)
2261 (message nil))
2263 (setq found t))))
2264 found))
2266 (defun custom-unloaded-widget-p (widget)
2267 "Return non-nil if the dependencies of WIDGET have not yet been loaded."
2268 (custom-unloaded-symbol-p (widget-value widget)))
2270 (defun custom-toggle-hide (widget)
2271 "Toggle visibility of WIDGET."
2272 (custom-load-widget widget)
2273 (let ((state (widget-get widget :custom-state)))
2274 (cond ((memq state '(invalid modified set))
2275 (error "There are unsaved changes"))
2276 ((eq state 'hidden)
2277 (widget-put widget :custom-state 'unknown))
2279 (widget-put widget :documentation-shown nil)
2280 (widget-put widget :custom-state 'hidden)))
2281 (custom-redraw widget)
2282 (widget-setup)))
2284 (defun custom-toggle-parent (widget &rest ignore)
2285 "Toggle visibility of parent of WIDGET."
2286 (custom-toggle-hide (widget-get widget :parent)))
2288 (defun custom-add-see-also (widget &optional prefix)
2289 "Add `See also ...' to WIDGET if there are any links.
2290 Insert PREFIX first if non-nil."
2291 (let* ((symbol (widget-get widget :value))
2292 (links (get symbol 'custom-links))
2293 (many (> (length links) 2))
2294 (buttons (widget-get widget :buttons))
2295 (indent (widget-get widget :indent)))
2296 (when links
2297 (when indent
2298 (insert-char ?\ indent))
2299 (when prefix
2300 (insert prefix))
2301 (insert "See also ")
2302 (while links
2303 (push (widget-create-child-and-convert
2304 widget (car links)
2305 :button-face 'custom-link
2306 :mouse-face 'highlight
2307 :pressed-face 'highlight)
2308 buttons)
2309 (setq links (cdr links))
2310 (cond ((null links)
2311 (insert ".\n"))
2312 ((null (cdr links))
2313 (if many
2314 (insert ", and ")
2315 (insert " and ")))
2317 (insert ", "))))
2318 (widget-put widget :buttons buttons))))
2320 (defun custom-add-parent-links (widget &optional initial-string doc-initial-string)
2321 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
2322 The value is non-nil if any parents were found.
2323 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
2324 (let ((name (widget-value widget))
2325 (type (widget-type widget))
2326 (buttons (widget-get widget :buttons))
2327 (start (point))
2328 (parents nil))
2329 (insert (or initial-string "Groups:"))
2330 (mapatoms (lambda (symbol)
2331 (when (member (list name type) (get symbol 'custom-group))
2332 (insert " ")
2333 (push (widget-create-child-and-convert
2334 widget 'custom-group-link
2335 :tag (custom-unlispify-tag-name symbol)
2336 symbol)
2337 buttons)
2338 (setq parents (cons symbol parents)))))
2339 (if parents
2340 (insert "\n")
2341 (delete-region start (point)))
2342 (widget-put widget :buttons buttons)
2343 parents))
2345 ;;; The `custom-comment' Widget.
2347 ;; like the editable field
2348 (defface custom-comment '((((type tty))
2349 :background "yellow3"
2350 :foreground "black")
2351 (((class grayscale color)
2352 (background light))
2353 :background "gray85")
2354 (((class grayscale color)
2355 (background dark))
2356 :background "dim gray")
2358 :slant italic))
2359 "Face used for comments on variables or faces."
2360 :version "21.1"
2361 :group 'custom-faces)
2362 (define-obsolete-face-alias 'custom-comment-face 'custom-comment "22.1")
2364 ;; like font-lock-comment-face
2365 (defface custom-comment-tag
2366 '((((class color) (background dark)) (:foreground "gray80"))
2367 (((class color) (background light)) (:foreground "blue4"))
2368 (((class grayscale) (background light))
2369 (:foreground "DimGray" :weight bold :slant italic))
2370 (((class grayscale) (background dark))
2371 (:foreground "LightGray" :weight bold :slant italic))
2372 (t (:weight bold)))
2373 "Face used for the comment tag on variables or faces."
2374 :group 'custom-faces)
2375 (define-obsolete-face-alias 'custom-comment-tag-face 'custom-comment-tag "22.1")
2377 (define-widget 'custom-comment 'string
2378 "User comment."
2379 :tag "Comment"
2380 :help-echo "Edit a comment here."
2381 :sample-face 'custom-comment-tag
2382 :value-face 'custom-comment
2383 :shown nil
2384 :create 'custom-comment-create)
2386 (defun custom-comment-create (widget)
2387 (let* ((null-comment (equal "" (widget-value widget))))
2388 (if (or (widget-get (widget-get widget :parent) :comment-shown)
2389 (not null-comment))
2390 (widget-default-create widget)
2391 ;; `widget-default-delete' expects markers in these slots --
2392 ;; maybe it shouldn't.
2393 (widget-put widget :from (point-marker))
2394 (widget-put widget :to (point-marker)))))
2396 (defun custom-comment-hide (widget)
2397 (widget-put (widget-get widget :parent) :comment-shown nil))
2399 ;; Those functions are for the menu. WIDGET is NOT the comment widget. It's
2400 ;; the global custom one
2401 (defun custom-comment-show (widget)
2402 (widget-put widget :comment-shown t)
2403 (custom-redraw widget)
2404 (widget-setup))
2406 (defun custom-comment-invisible-p (widget)
2407 (let ((val (widget-value (widget-get widget :comment-widget))))
2408 (and (equal "" val)
2409 (not (widget-get widget :comment-shown)))))
2411 ;;; The `custom-variable' Widget.
2413 (defface custom-variable-tag
2414 `((((class color)
2415 (background dark))
2416 (:foreground "light blue" :weight bold))
2417 (((min-colors 88) (class color)
2418 (background light))
2419 (:foreground "blue1" :weight bold))
2420 (((class color)
2421 (background light))
2422 (:foreground "blue" :weight bold))
2423 (t (:weight bold)))
2424 "Face used for unpushable variable tags."
2425 :group 'custom-faces)
2426 (define-obsolete-face-alias 'custom-variable-tag-face
2427 'custom-variable-tag "22.1")
2429 (defface custom-variable-button '((t (:underline t :weight bold)))
2430 "Face used for pushable variable tags."
2431 :group 'custom-faces)
2432 (define-obsolete-face-alias 'custom-variable-button-face
2433 'custom-variable-button "22.1")
2435 (defcustom custom-variable-default-form 'edit
2436 "Default form of displaying variable values."
2437 :type '(choice (const edit)
2438 (const lisp))
2439 :group 'custom-buffer
2440 :version "20.3")
2442 (defun custom-variable-documentation (variable)
2443 "Return documentation of VARIABLE for use in Custom buffer.
2444 Normally just return the docstring. But if VARIABLE automatically
2445 becomes buffer local when set, append a message to that effect."
2446 (if (and (local-variable-if-set-p variable)
2447 (or (not (local-variable-p variable))
2448 (with-temp-buffer
2449 (local-variable-if-set-p variable))))
2450 (concat (documentation-property variable 'variable-documentation)
2452 This variable automatically becomes buffer-local when set outside Custom.
2453 However, setting it through Custom sets the default value.")
2454 (documentation-property variable 'variable-documentation)))
2456 (define-widget 'custom-variable 'custom
2457 "A widget for displaying a Custom variable.
2459 The following property has a special meaning for this widget:
2460 :hidden-states - A list of widget states for which the widget's initial
2461 contents should be hidden."
2462 :format "%v"
2463 :help-echo "Set or reset this variable."
2464 :documentation-property #'custom-variable-documentation
2465 :custom-category 'option
2466 :custom-state nil
2467 :custom-menu 'custom-variable-menu-create
2468 :custom-form nil ; defaults to value of `custom-variable-default-form'
2469 :value-create 'custom-variable-value-create
2470 :action 'custom-variable-action
2471 :hidden-states '(standard)
2472 :custom-set 'custom-variable-set
2473 :custom-mark-to-save 'custom-variable-mark-to-save
2474 :custom-reset-current 'custom-redraw
2475 :custom-reset-saved 'custom-variable-reset-saved
2476 :custom-reset-standard 'custom-variable-reset-standard
2477 :custom-mark-to-reset-standard 'custom-variable-mark-to-reset-standard
2478 :custom-standard-value 'custom-variable-standard-value
2479 :custom-state-set-and-redraw 'custom-variable-state-set-and-redraw)
2481 (defun custom-variable-type (symbol)
2482 "Return a widget suitable for editing the value of SYMBOL.
2483 If SYMBOL has a `custom-type' property, use that.
2484 Otherwise, try matching SYMBOL against `custom-guess-name-alist' and
2485 try matching its doc string against `custom-guess-doc-alist'."
2486 (let* ((type (or (get symbol 'custom-type)
2487 (and (not (get symbol 'standard-value))
2488 (custom-guess-type symbol))
2489 'sexp))
2490 (options (get symbol 'custom-options))
2491 (tmp (if (listp type)
2492 (copy-sequence type)
2493 (list type))))
2494 (when options
2495 (widget-put tmp :options options))
2496 tmp))
2498 (defun custom-variable-value-create (widget)
2499 "Here is where you edit the variable's value."
2500 (custom-load-widget widget)
2501 (unless (widget-get widget :custom-form)
2502 (widget-put widget :custom-form custom-variable-default-form))
2503 (let* ((buttons (widget-get widget :buttons))
2504 (children (widget-get widget :children))
2505 (form (widget-get widget :custom-form))
2506 (symbol (widget-get widget :value))
2507 (tag (widget-get widget :tag))
2508 (type (custom-variable-type symbol))
2509 (conv (widget-convert type))
2510 (get (or (get symbol 'custom-get) 'default-value))
2511 (prefix (widget-get widget :custom-prefix))
2512 (last (widget-get widget :custom-last))
2513 (value (if (default-boundp symbol)
2514 (funcall get symbol)
2515 (widget-get conv :value)))
2516 (state (or (widget-get widget :custom-state)
2517 (if (memq (custom-variable-state symbol value)
2518 (widget-get widget :hidden-states))
2519 'hidden))))
2521 ;; If we don't know the state, see if we need to edit it in lisp form.
2522 (unless state
2523 (setq state (if (custom-show type value) 'unknown 'hidden)))
2524 (when (eq state 'unknown)
2525 (unless (widget-apply conv :match value)
2526 (setq form 'mismatch)))
2527 ;; Now we can create the child widget.
2528 (cond ((eq custom-buffer-style 'tree)
2529 (insert prefix (if last " `--- " " |--- "))
2530 (push (widget-create-child-and-convert
2531 widget 'custom-browse-variable-tag)
2532 buttons)
2533 (insert " " tag "\n")
2534 (widget-put widget :buttons buttons))
2535 ((eq state 'hidden)
2536 ;; Indicate hidden value.
2537 (push (widget-create-child-and-convert
2538 widget 'custom-visibility
2539 :help-echo "Show the value of this option."
2540 :on-image "down"
2541 :on "Hide"
2542 :off-image "right"
2543 :off "Show Value"
2544 :action 'custom-toggle-parent
2545 nil)
2546 buttons)
2547 (insert " ")
2548 (push (widget-create-child-and-convert
2549 widget 'item
2550 :format "%{%t%} "
2551 :sample-face 'custom-variable-tag
2552 :tag tag
2553 :parent widget)
2554 buttons))
2555 ((memq form '(lisp mismatch))
2556 ;; In lisp mode edit the saved value when possible.
2557 (push (widget-create-child-and-convert
2558 widget 'custom-visibility
2559 :help-echo "Hide the value of this option."
2560 :on "Hide"
2561 :off "Show"
2562 :on-image "down"
2563 :off-image "right"
2564 :action 'custom-toggle-parent
2566 buttons)
2567 (insert " ")
2568 (let* ((value (cond ((get symbol 'saved-value)
2569 (car (get symbol 'saved-value)))
2570 ((get symbol 'standard-value)
2571 (car (get symbol 'standard-value)))
2572 ((default-boundp symbol)
2573 (custom-quote (funcall get symbol)))
2575 (custom-quote (widget-get conv :value))))))
2576 (insert (symbol-name symbol) ": ")
2577 (push (widget-create-child-and-convert
2578 widget 'sexp
2579 :button-face 'custom-variable-button-face
2580 :format "%v"
2581 :tag (symbol-name symbol)
2582 :parent widget
2583 :value value)
2584 children)))
2586 ;; Edit mode.
2587 (push (widget-create-child-and-convert
2588 widget 'custom-visibility
2589 :help-echo "Hide or show this option."
2590 :on "Hide"
2591 :off "Show"
2592 :on-image "down"
2593 :off-image "right"
2594 :action 'custom-toggle-parent
2596 buttons)
2597 (insert " ")
2598 (let* ((format (widget-get type :format))
2599 tag-format value-format)
2600 (unless (string-match ":" format)
2601 (error "Bad format"))
2602 (setq tag-format (substring format 0 (match-end 0)))
2603 (setq value-format (substring format (match-end 0)))
2604 (push (widget-create-child-and-convert
2605 widget 'item
2606 :format tag-format
2607 :action 'custom-tag-action
2608 :help-echo "Change value of this option."
2609 :mouse-down-action 'custom-tag-mouse-down-action
2610 :button-face 'custom-variable-button
2611 :sample-face 'custom-variable-tag
2612 tag)
2613 buttons)
2614 (push (widget-create-child-and-convert
2615 widget type
2616 :format value-format
2617 :value value)
2618 children))))
2619 (unless (eq custom-buffer-style 'tree)
2620 (unless (eq (preceding-char) ?\n)
2621 (widget-insert "\n"))
2622 ;; Create the magic button.
2623 (let ((magic (widget-create-child-and-convert
2624 widget 'custom-magic nil)))
2625 (widget-put widget :custom-magic magic)
2626 (push magic buttons))
2627 (widget-put widget :buttons buttons)
2628 ;; Insert documentation.
2629 (widget-put widget :documentation-indent 3)
2630 (widget-add-documentation-string-button
2631 widget :visibility-widget 'custom-visibility)
2633 ;; The comment field
2634 (unless (eq state 'hidden)
2635 (let* ((comment (get symbol 'variable-comment))
2636 (comment-widget
2637 (widget-create-child-and-convert
2638 widget 'custom-comment
2639 :parent widget
2640 :value (or comment ""))))
2641 (widget-put widget :comment-widget comment-widget)
2642 ;; Don't push it !!! Custom assumes that the first child is the
2643 ;; value one.
2644 (setq children (append children (list comment-widget)))))
2645 ;; Update the rest of the properties.
2646 (widget-put widget :custom-form form)
2647 (widget-put widget :children children)
2648 ;; Now update the state.
2649 (if (eq state 'hidden)
2650 (widget-put widget :custom-state state)
2651 (custom-variable-state-set widget))
2652 ;; See also.
2653 (unless (eq state 'hidden)
2654 (when (eq (widget-get widget :custom-level) 1)
2655 (custom-add-parent-links widget))
2656 (custom-add-see-also widget)))))
2658 (defun custom-tag-action (widget &rest args)
2659 "Pass :action to first child of WIDGET's parent."
2660 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
2661 :action args))
2663 (defun custom-tag-mouse-down-action (widget &rest args)
2664 "Pass :mouse-down-action to first child of WIDGET's parent."
2665 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
2666 :mouse-down-action args))
2668 (defun custom-variable-state (symbol val)
2669 "Return the state of SYMBOL if its value is VAL.
2670 If SYMBOL has a non-nil `custom-get' property, it overrides VAL.
2671 Possible return values are `standard', `saved', `set', `themed',
2672 `changed', and `rogue'."
2673 (let* ((get (or (get symbol 'custom-get) 'default-value))
2674 (value (if (default-boundp symbol)
2675 (funcall get symbol)
2676 val))
2677 (comment (get symbol 'variable-comment))
2679 temp)
2680 (cond ((progn (setq tmp (get symbol 'customized-value))
2681 (setq temp
2682 (get symbol 'customized-variable-comment))
2683 (or tmp temp))
2684 (if (condition-case nil
2685 (and (equal value (eval (car tmp)))
2686 (equal comment temp))
2687 (error nil))
2688 'set
2689 'changed))
2690 ((progn (setq tmp (get symbol 'theme-value))
2691 (setq temp (get symbol 'saved-variable-comment))
2692 (or tmp temp))
2693 (if (condition-case nil
2694 (and (equal comment temp)
2695 (equal value
2696 (eval
2697 (car (custom-variable-theme-value
2698 symbol)))))
2699 (error nil))
2700 (cond
2701 ((eq (caar tmp) 'user) 'saved)
2702 ((eq (caar tmp) 'changed)
2703 (if (condition-case nil
2704 (and (null comment)
2705 (equal value
2706 (eval
2707 (car (get symbol 'standard-value)))))
2708 (error nil))
2709 ;; The value was originally set outside
2710 ;; custom, but it was set to the standard
2711 ;; value (probably an autoloaded defcustom).
2712 'standard
2713 'changed))
2714 (t 'themed))
2715 'changed))
2716 ((setq tmp (get symbol 'standard-value))
2717 (if (condition-case nil
2718 (and (equal value (eval (car tmp)))
2719 (equal comment nil))
2720 (error nil))
2721 'standard
2722 'changed))
2723 (t 'rogue))))
2725 (defun custom-variable-state-set (widget &optional state)
2726 "Set the state of WIDGET to STATE.
2727 If STATE is nil, the value is computed by `custom-variable-state'."
2728 (widget-put widget :custom-state
2729 (or state (custom-variable-state (widget-value widget)
2730 (widget-get widget :value)))))
2732 (defun custom-variable-standard-value (widget)
2733 (get (widget-value widget) 'standard-value))
2735 (defvar custom-variable-menu
2736 `(("Set for Current Session" custom-variable-set
2737 (lambda (widget)
2738 (eq (widget-get widget :custom-state) 'modified)))
2739 ;; Note that in all the backquoted code in this file, we test
2740 ;; init-file-user rather than user-init-file. This is in case
2741 ;; cus-edit is loaded by something in site-start.el, because
2742 ;; user-init-file is not set at that stage.
2743 ;; http://lists.gnu.org/archive/html/emacs-devel/2007-10/msg00310.html
2744 ,@(when (or custom-file init-file-user)
2745 '(("Save for Future Sessions" custom-variable-save
2746 (lambda (widget)
2747 (memq (widget-get widget :custom-state)
2748 '(modified set changed rogue))))))
2749 ("Undo Edits" custom-redraw
2750 (lambda (widget)
2751 (and (default-boundp (widget-value widget))
2752 (memq (widget-get widget :custom-state) '(modified changed)))))
2753 ("Reset to Saved" custom-variable-reset-saved
2754 (lambda (widget)
2755 (and (or (get (widget-value widget) 'saved-value)
2756 (get (widget-value widget) 'saved-variable-comment))
2757 (memq (widget-get widget :custom-state)
2758 '(modified set changed rogue)))))
2759 ,@(when (or custom-file init-file-user)
2760 '(("Erase Customization" custom-variable-reset-standard
2761 (lambda (widget)
2762 (and (get (widget-value widget) 'standard-value)
2763 (memq (widget-get widget :custom-state)
2764 '(modified set changed saved rogue)))))))
2765 ("Set to Backup Value" custom-variable-reset-backup
2766 (lambda (widget)
2767 (get (widget-value widget) 'backup-value)))
2768 ("---" ignore ignore)
2769 ("Add Comment" custom-comment-show custom-comment-invisible-p)
2770 ("---" ignore ignore)
2771 ("Show Current Value" custom-variable-edit
2772 (lambda (widget)
2773 (eq (widget-get widget :custom-form) 'lisp)))
2774 ("Show Saved Lisp Expression" custom-variable-edit-lisp
2775 (lambda (widget)
2776 (eq (widget-get widget :custom-form) 'edit))))
2777 "Alist of actions for the `custom-variable' widget.
2778 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2779 the menu entry, ACTION is the function to call on the widget when the
2780 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2781 widget as an argument, and returns non-nil if ACTION is valid on that
2782 widget. If FILTER is nil, ACTION is always valid.")
2784 (defun custom-variable-action (widget &optional event)
2785 "Show the menu for `custom-variable' WIDGET.
2786 Optional EVENT is the location for the menu."
2787 (if (eq (widget-get widget :custom-state) 'hidden)
2788 (custom-toggle-hide widget)
2789 (unless (eq (widget-get widget :custom-state) 'modified)
2790 (custom-variable-state-set widget))
2791 (custom-redraw-magic widget)
2792 (let* ((completion-ignore-case t)
2793 (answer (widget-choose (concat "Operation on "
2794 (custom-unlispify-tag-name
2795 (widget-get widget :value)))
2796 (custom-menu-filter custom-variable-menu
2797 widget)
2798 event)))
2799 (if answer
2800 (funcall answer widget)))))
2802 (defun custom-variable-edit (widget)
2803 "Edit value of WIDGET."
2804 (widget-put widget :custom-state 'unknown)
2805 (widget-put widget :custom-form 'edit)
2806 (custom-redraw widget))
2808 (defun custom-variable-edit-lisp (widget)
2809 "Edit the Lisp representation of the value of WIDGET."
2810 (widget-put widget :custom-state 'unknown)
2811 (widget-put widget :custom-form 'lisp)
2812 (custom-redraw widget))
2814 (defun custom-variable-set (widget)
2815 "Set the current value for the variable being edited by WIDGET."
2816 (let* ((form (widget-get widget :custom-form))
2817 (state (widget-get widget :custom-state))
2818 (child (car (widget-get widget :children)))
2819 (symbol (widget-value widget))
2820 (set (or (get symbol 'custom-set) 'set-default))
2821 (comment-widget (widget-get widget :comment-widget))
2822 (comment (widget-value comment-widget))
2823 val)
2824 (cond ((eq state 'hidden)
2825 (error "Cannot set hidden variable"))
2826 ((setq val (widget-apply child :validate))
2827 (goto-char (widget-get val :from))
2828 (error "%s" (widget-get val :error)))
2829 ((memq form '(lisp mismatch))
2830 (when (equal comment "")
2831 (setq comment nil)
2832 ;; Make the comment invisible by hand if it's empty
2833 (custom-comment-hide comment-widget))
2834 (custom-variable-backup-value widget)
2835 (custom-push-theme 'theme-value symbol 'user
2836 'set (custom-quote (widget-value child)))
2837 (funcall set symbol (eval (setq val (widget-value child))))
2838 (put symbol 'customized-value (list val))
2839 (put symbol 'variable-comment comment)
2840 (put symbol 'customized-variable-comment comment))
2842 (when (equal comment "")
2843 (setq comment nil)
2844 ;; Make the comment invisible by hand if it's empty
2845 (custom-comment-hide comment-widget))
2846 (custom-variable-backup-value widget)
2847 (custom-push-theme 'theme-value symbol 'user
2848 'set (custom-quote (widget-value child)))
2849 (funcall set symbol (setq val (widget-value child)))
2850 (put symbol 'customized-value (list (custom-quote val)))
2851 (put symbol 'variable-comment comment)
2852 (put symbol 'customized-variable-comment comment)))
2853 (custom-variable-state-set widget)
2854 (custom-redraw-magic widget)))
2856 (defun custom-variable-mark-to-save (widget)
2857 "Set value and mark for saving the variable edited by WIDGET."
2858 (let* ((form (widget-get widget :custom-form))
2859 (state (widget-get widget :custom-state))
2860 (child (car (widget-get widget :children)))
2861 (symbol (widget-value widget))
2862 (set (or (get symbol 'custom-set) 'set-default))
2863 (comment-widget (widget-get widget :comment-widget))
2864 (comment (widget-value comment-widget))
2865 val)
2866 (cond ((eq state 'hidden)
2867 (error "Cannot set hidden variable"))
2868 ((setq val (widget-apply child :validate))
2869 (goto-char (widget-get val :from))
2870 (error "Saving %s: %s" symbol (widget-get val :error)))
2871 ((memq form '(lisp mismatch))
2872 (when (equal comment "")
2873 (setq comment nil)
2874 ;; Make the comment invisible by hand if it's empty
2875 (custom-comment-hide comment-widget))
2876 (put symbol 'saved-value (list (widget-value child)))
2877 (custom-push-theme 'theme-value symbol 'user
2878 'set (custom-quote (widget-value child)))
2879 (funcall set symbol (eval (widget-value child)))
2880 (put symbol 'variable-comment comment)
2881 (put symbol 'saved-variable-comment comment))
2883 (when (equal comment "")
2884 (setq comment nil)
2885 ;; Make the comment invisible by hand if it's empty
2886 (custom-comment-hide comment-widget))
2887 (put symbol 'saved-value
2888 (list (custom-quote (widget-value child))))
2889 (custom-push-theme 'theme-value symbol 'user
2890 'set (custom-quote (widget-value child)))
2891 (funcall set symbol (widget-value child))
2892 (put symbol 'variable-comment comment)
2893 (put symbol 'saved-variable-comment comment)))
2894 (put symbol 'customized-value nil)
2895 (put symbol 'customized-variable-comment nil)))
2897 (defsubst custom-variable-state-set-and-redraw (widget)
2898 "Set state of variable widget WIDGET and redraw with current settings."
2899 (custom-variable-state-set widget)
2900 (custom-redraw-magic widget))
2902 (defun custom-variable-save (widget)
2903 "Save value of variable edited by widget WIDGET."
2904 (custom-variable-mark-to-save widget)
2905 (custom-save-all)
2906 (custom-variable-state-set-and-redraw widget))
2908 (defun custom-variable-reset-saved (widget)
2909 "Restore the saved value for the variable being edited by WIDGET.
2910 This also updates the buffer to show that value.
2911 The value that was current before this operation
2912 becomes the backup value, so you can get it again."
2913 (let* ((symbol (widget-value widget))
2914 (set (or (get symbol 'custom-set) 'set-default))
2915 (value (get symbol 'saved-value))
2916 (comment (get symbol 'saved-variable-comment)))
2917 (cond ((or value comment)
2918 (put symbol 'variable-comment comment)
2919 (custom-variable-backup-value widget)
2920 (custom-push-theme 'theme-value symbol 'user 'set (car-safe value))
2921 (condition-case nil
2922 (funcall set symbol (eval (car value)))
2923 (error nil)))
2925 (error "No saved value for %s" symbol)))
2926 (put symbol 'customized-value nil)
2927 (put symbol 'customized-variable-comment nil)
2928 (widget-put widget :custom-state 'unknown)
2929 ;; This call will possibly make the comment invisible
2930 (custom-redraw widget)))
2932 (defun custom-variable-mark-to-reset-standard (widget)
2933 "Mark to restore standard setting for the variable edited by widget WIDGET.
2934 If `custom-reset-standard-variables-list' is nil, save, reset and
2935 redraw the widget immediately."
2936 (let* ((symbol (widget-value widget)))
2937 (if (get symbol 'standard-value)
2938 (custom-variable-backup-value widget)
2939 (error "No standard setting known for %S" symbol))
2940 (put symbol 'variable-comment nil)
2941 (put symbol 'customized-value nil)
2942 (put symbol 'customized-variable-comment nil)
2943 (custom-push-theme 'theme-value symbol 'user 'reset)
2944 (custom-theme-recalc-variable symbol)
2945 (if (and custom-reset-standard-variables-list
2946 (or (get symbol 'saved-value) (get symbol 'saved-variable-comment)))
2947 (progn
2948 (put symbol 'saved-value nil)
2949 (put symbol 'saved-variable-comment nil)
2950 ;; Append this to `custom-reset-standard-variables-list' to
2951 ;; have `custom-reset-standard-save-and-update' save setting
2952 ;; to the file, update the widget's state, and redraw it.
2953 (setq custom-reset-standard-variables-list
2954 (cons widget custom-reset-standard-variables-list)))
2955 (when (or (get symbol 'saved-value) (get symbol 'saved-variable-comment))
2956 (put symbol 'saved-value nil)
2957 (put symbol 'saved-variable-comment nil)
2958 (custom-save-all))
2959 (widget-put widget :custom-state 'unknown)
2960 ;; This call will possibly make the comment invisible
2961 (custom-redraw widget))))
2963 (defun custom-variable-reset-standard (widget)
2964 "Restore standard setting for the variable edited by WIDGET.
2965 This operation eliminates any saved setting for the variable,
2966 restoring it to the state of a variable that has never been customized.
2967 The value that was current before this operation
2968 becomes the backup value, so you can get it again."
2969 (let (custom-reset-standard-variables-list)
2970 (custom-variable-mark-to-reset-standard widget)))
2972 (defun custom-variable-backup-value (widget)
2973 "Back up the current value for WIDGET's variable.
2974 The backup value is kept in the car of the `backup-value' property."
2975 (let* ((symbol (widget-value widget))
2976 (get (or (get symbol 'custom-get) 'default-value))
2977 (type (custom-variable-type symbol))
2978 (conv (widget-convert type))
2979 (value (if (default-boundp symbol)
2980 (funcall get symbol)
2981 (widget-get conv :value))))
2982 (put symbol 'backup-value (list value))))
2984 (defun custom-variable-reset-backup (widget)
2985 "Restore the backup value for the variable being edited by WIDGET.
2986 The value that was current before this operation
2987 becomes the backup value, so you can use this operation repeatedly
2988 to switch between two values."
2989 (let* ((symbol (widget-value widget))
2990 (set (or (get symbol 'custom-set) 'set-default))
2991 (value (get symbol 'backup-value))
2992 (comment-widget (widget-get widget :comment-widget))
2993 (comment (widget-value comment-widget)))
2994 (if value
2995 (progn
2996 (custom-variable-backup-value widget)
2997 (custom-push-theme 'theme-value symbol 'user 'set value)
2998 (condition-case nil
2999 (funcall set symbol (car value))
3000 (error nil)))
3001 (error "No backup value for %s" symbol))
3002 (put symbol 'customized-value (list (car value)))
3003 (put symbol 'variable-comment comment)
3004 (put symbol 'customized-variable-comment comment)
3005 (custom-variable-state-set widget)
3006 ;; This call will possibly make the comment invisible
3007 (custom-redraw widget)))
3009 ;;; The `custom-visibility' Widget
3011 (define-widget 'custom-visibility 'visibility
3012 "Show or hide a documentation string."
3013 :button-face 'custom-visibility
3014 :pressed-face 'custom-visibility
3015 :mouse-face 'highlight
3016 :pressed-face 'highlight
3017 :on-image nil
3018 :off-image nil)
3020 (defface custom-visibility
3021 '((t :height 0.8 :inherit link))
3022 "Face for the `custom-visibility' widget."
3023 :version "23.1"
3024 :group 'custom-faces)
3026 ;;; The `custom-face-edit' Widget.
3028 (define-widget 'custom-face-edit 'checklist
3029 "Edit face attributes."
3030 :format "%t: %v"
3031 :tag "Attributes"
3032 :extra-offset 13
3033 :button-args '(:help-echo "Control whether this attribute has any effect.")
3034 :value-to-internal 'custom-face-edit-fix-value
3035 :match (lambda (widget value)
3036 (widget-checklist-match widget
3037 (custom-face-edit-fix-value widget value)))
3038 :convert-widget 'custom-face-edit-convert-widget
3039 :args (mapcar (lambda (att)
3040 (list 'group
3041 :inline t
3042 :sibling-args (widget-get (nth 1 att) :sibling-args)
3043 (list 'const :format "" :value (nth 0 att))
3044 (nth 1 att)))
3045 custom-face-attributes))
3047 (defun custom-face-edit-fix-value (widget value)
3048 "Ignoring WIDGET, convert :bold and :italic in VALUE to new form.
3049 Also change :reverse-video to :inverse-video."
3050 (if (listp value)
3051 (let (result)
3052 (while value
3053 (let ((key (car value))
3054 (val (car (cdr value))))
3055 (cond ((eq key :italic)
3056 (push :slant result)
3057 (push (if val 'italic 'normal) result))
3058 ((eq key :bold)
3059 (push :weight result)
3060 (push (if val 'bold 'normal) result))
3061 ((eq key :reverse-video)
3062 (push :inverse-video result)
3063 (push val result))
3065 (push key result)
3066 (push val result))))
3067 (setq value (cdr (cdr value))))
3068 (setq result (nreverse result))
3069 result)
3070 value))
3072 (defun custom-face-edit-convert-widget (widget)
3073 "Convert :args as widget types in WIDGET."
3074 (widget-put
3075 widget
3076 :args (mapcar (lambda (arg)
3077 (widget-convert arg
3078 :deactivate 'custom-face-edit-deactivate
3079 :activate 'custom-face-edit-activate
3080 :delete 'custom-face-edit-delete))
3081 (widget-get widget :args)))
3082 widget)
3084 (defun custom-face-edit-deactivate (widget)
3085 "Make face widget WIDGET inactive for user modifications."
3086 (unless (widget-get widget :inactive)
3087 (let ((tag (custom-face-edit-attribute-tag widget))
3088 (from (copy-marker (widget-get widget :from)))
3089 (value (widget-value widget))
3090 (inhibit-read-only t)
3091 (inhibit-modification-hooks t))
3092 (save-excursion
3093 (goto-char from)
3094 (widget-default-delete widget)
3095 (insert tag ": *\n")
3096 (widget-put widget :inactive
3097 (cons value (cons from (- (point) from))))))))
3099 (defun custom-face-edit-activate (widget)
3100 "Make face widget WIDGET active for user modifications."
3101 (let ((inactive (widget-get widget :inactive))
3102 (inhibit-read-only t)
3103 (inhibit-modification-hooks t))
3104 (when (consp inactive)
3105 (save-excursion
3106 (goto-char (car (cdr inactive)))
3107 (delete-region (point) (+ (point) (cdr (cdr inactive))))
3108 (widget-put widget :inactive nil)
3109 (widget-apply widget :create)
3110 (widget-value-set widget (car inactive))
3111 (widget-setup)))))
3113 (defun custom-face-edit-delete (widget)
3114 "Remove WIDGET from the buffer."
3115 (let ((inactive (widget-get widget :inactive))
3116 (inhibit-read-only t)
3117 (inhibit-modification-hooks t))
3118 (if (not inactive)
3119 ;; Widget is alive, we don't have to do anything special
3120 (widget-default-delete widget)
3121 ;; WIDGET is already deleted because we did so to inactivate it;
3122 ;; now just get rid of the label we put in its place.
3123 (delete-region (car (cdr inactive))
3124 (+ (car (cdr inactive)) (cdr (cdr inactive))))
3125 (widget-put widget :inactive nil))))
3128 (defun custom-face-edit-attribute-tag (widget)
3129 "Return the first :tag property in WIDGET or one of its children."
3130 (let ((tag (widget-get widget :tag)))
3131 (or (and (not (equal tag "")) tag)
3132 (let ((children (widget-get widget :children)))
3133 (while (and (null tag) children)
3134 (setq tag (custom-face-edit-attribute-tag (pop children))))
3135 tag))))
3137 ;;; The `custom-display' Widget.
3139 (define-widget 'custom-display 'menu-choice
3140 "Select a display type."
3141 :tag "Display"
3142 :value t
3143 :help-echo "Specify frames where the face attributes should be used."
3144 :args '((const :tag "all" t)
3145 (const :tag "defaults" default)
3146 (checklist
3147 :offset 0
3148 :extra-offset 9
3149 :args ((group :sibling-args (:help-echo "\
3150 Only match the specified window systems.")
3151 (const :format "Type: "
3152 type)
3153 (checklist :inline t
3154 :offset 0
3155 (const :format "X "
3156 :sibling-args (:help-echo "\
3157 The X11 Window System.")
3159 (const :format "PM "
3160 :sibling-args (:help-echo "\
3161 OS/2 Presentation Manager.")
3163 (const :format "W32 "
3164 :sibling-args (:help-echo "\
3165 Windows NT/9X.")
3166 w32)
3167 (const :format "NS "
3168 :sibling-args (:help-echo "\
3169 GNUstep or Macintosh OS Cocoa interface.")
3171 (const :format "DOS "
3172 :sibling-args (:help-echo "\
3173 Plain MS-DOS.")
3175 (const :format "TTY%n"
3176 :sibling-args (:help-echo "\
3177 Plain text terminals.")
3178 tty)))
3179 (group :sibling-args (:help-echo "\
3180 Only match the frames with the specified color support.")
3181 (const :format "Class: "
3182 class)
3183 (checklist :inline t
3184 :offset 0
3185 (const :format "Color "
3186 :sibling-args (:help-echo "\
3187 Match color frames.")
3188 color)
3189 (const :format "Grayscale "
3190 :sibling-args (:help-echo "\
3191 Match grayscale frames.")
3192 grayscale)
3193 (const :format "Monochrome%n"
3194 :sibling-args (:help-echo "\
3195 Match frames with no color support.")
3196 mono)))
3197 (group :sibling-args (:help-echo "\
3198 The minimum number of colors the frame should support.")
3199 (const :format "" min-colors)
3200 (integer :tag "Minimum number of colors" ))
3201 (group :sibling-args (:help-echo "\
3202 Only match frames with the specified intensity.")
3203 (const :format "\
3204 Background brightness: "
3205 background)
3206 (checklist :inline t
3207 :offset 0
3208 (const :format "Light "
3209 :sibling-args (:help-echo "\
3210 Match frames with light backgrounds.")
3211 light)
3212 (const :format "Dark\n"
3213 :sibling-args (:help-echo "\
3214 Match frames with dark backgrounds.")
3215 dark)))
3216 (group :sibling-args (:help-echo "\
3217 Only match frames that support the specified face attributes.")
3218 (const :format "Supports attributes:" supports)
3219 (custom-face-edit :inline t :format "%n%v"))))))
3221 ;;; The `custom-face' Widget.
3223 (defface custom-face-tag
3224 `((t :inherit custom-variable-tag))
3225 "Face used for face tags."
3226 :group 'custom-faces)
3227 (define-obsolete-face-alias 'custom-face-tag-face 'custom-face-tag "22.1")
3229 (defcustom custom-face-default-form 'selected
3230 "Default form of displaying face definition."
3231 :type '(choice (const all)
3232 (const selected)
3233 (const lisp))
3234 :group 'custom-buffer
3235 :version "20.3")
3237 (define-widget 'custom-face 'custom
3238 "Customize face."
3239 :sample-face 'custom-face-tag
3240 :help-echo "Set or reset this face."
3241 :documentation-property #'face-doc-string
3242 :value-create 'custom-face-value-create
3243 :action 'custom-face-action
3244 :custom-category 'face
3245 :custom-form nil ; defaults to value of `custom-face-default-form'
3246 :custom-set 'custom-face-set
3247 :custom-mark-to-save 'custom-face-mark-to-save
3248 :custom-reset-current 'custom-redraw
3249 :custom-reset-saved 'custom-face-reset-saved
3250 :custom-reset-standard 'custom-face-reset-standard
3251 :custom-mark-to-reset-standard 'custom-face-mark-to-reset-standard
3252 :custom-standard-value 'custom-face-standard-value
3253 :custom-state-set-and-redraw 'custom-face-state-set-and-redraw
3254 :custom-menu 'custom-face-menu-create)
3256 (define-widget 'custom-face-all 'editable-list
3257 "An editable list of display specifications and attributes."
3258 :entry-format "%i %d %v"
3259 :insert-button-args '(:help-echo "Insert new display specification here.")
3260 :append-button-args '(:help-echo "Append new display specification here.")
3261 :delete-button-args '(:help-echo "Delete this display specification.")
3262 :args '((group :format "%v" custom-display custom-face-edit)))
3264 (defconst custom-face-all (widget-convert 'custom-face-all)
3265 "Converted version of the `custom-face-all' widget.")
3267 (define-widget 'custom-display-unselected 'item
3268 "A display specification that doesn't match the selected display."
3269 :match 'custom-display-unselected-match)
3271 (defun custom-display-unselected-match (widget value)
3272 "Non-nil if VALUE is an unselected display specification."
3273 (not (face-spec-set-match-display value (selected-frame))))
3275 (define-widget 'custom-face-selected 'group
3276 "Edit the attributes of the selected display in a face specification."
3277 :args '((choice :inline t
3278 (group :tag "With Defaults" :inline t
3279 (group (const :tag "" default)
3280 (custom-face-edit :tag " Default\n Attributes"))
3281 (repeat :format ""
3282 :inline t
3283 (group custom-display-unselected sexp))
3284 (group (sexp :format "")
3285 (custom-face-edit :tag " Overriding\n Attributes"))
3286 (repeat :format ""
3287 :inline t
3288 sexp))
3289 (group :tag "No Defaults" :inline t
3290 (repeat :format ""
3291 :inline t
3292 (group custom-display-unselected sexp))
3293 (group (sexp :format "")
3294 (custom-face-edit :tag "\n Attributes"))
3295 (repeat :format ""
3296 :inline t
3297 sexp)))))
3301 (defconst custom-face-selected (widget-convert 'custom-face-selected)
3302 "Converted version of the `custom-face-selected' widget.")
3304 (defun custom-filter-face-spec (spec filter-index &optional default-filter)
3305 "Return a canonicalized version of SPEC using.
3306 FILTER-INDEX is the index in the entry for each attribute in
3307 `custom-face-attributes' at which the appropriate filter function can be
3308 found, and DEFAULT-FILTER is the filter to apply for attributes that
3309 don't specify one."
3310 (mapcar (lambda (entry)
3311 ;; Filter a single face-spec entry
3312 (let ((tests (car entry))
3313 (unfiltered-attrs
3314 ;; Handle both old- and new-style attribute syntax
3315 (if (listp (car (cdr entry)))
3316 (car (cdr entry))
3317 (cdr entry)))
3318 (filtered-attrs nil))
3319 ;; Filter each face attribute
3320 (while unfiltered-attrs
3321 (let* ((attr (pop unfiltered-attrs))
3322 (pre-filtered-value (pop unfiltered-attrs))
3323 (filter
3324 (or (nth filter-index (assq attr custom-face-attributes))
3325 default-filter))
3326 (filtered-value
3327 (if filter
3328 (funcall filter pre-filtered-value)
3329 pre-filtered-value)))
3330 (push filtered-value filtered-attrs)
3331 (push attr filtered-attrs)))
3333 (list tests filtered-attrs)))
3334 spec))
3336 (defun custom-pre-filter-face-spec (spec)
3337 "Return SPEC changed as necessary for editing by the face customization widget.
3338 SPEC must be a full face spec."
3339 (custom-filter-face-spec spec 2))
3341 (defun custom-post-filter-face-spec (spec)
3342 "Return the customized SPEC in a form suitable for setting the face."
3343 (custom-filter-face-spec spec 3))
3345 (defun custom-face-value-create (widget)
3346 "Create a list of the display specifications for WIDGET."
3347 (let ((buttons (widget-get widget :buttons))
3348 children
3349 (symbol (widget-get widget :value))
3350 (tag (widget-get widget :tag))
3351 (state (widget-get widget :custom-state))
3352 (begin (point))
3353 (is-last (widget-get widget :custom-last))
3354 (prefix (widget-get widget :custom-prefix)))
3355 (unless tag
3356 (setq tag (prin1-to-string symbol)))
3357 (cond ((eq custom-buffer-style 'tree)
3358 (insert prefix (if is-last " `--- " " |--- "))
3359 (push (widget-create-child-and-convert
3360 widget 'custom-browse-face-tag)
3361 buttons)
3362 (insert " " tag "\n")
3363 (widget-put widget :buttons buttons))
3365 ;; Visibility.
3366 (push (widget-create-child-and-convert
3367 widget 'custom-visibility
3368 :help-echo "Hide or show this face."
3369 :on "Hide"
3370 :off "Show"
3371 :on-image "down"
3372 :off-image "right"
3373 :action 'custom-toggle-parent
3374 (not (eq state 'hidden)))
3375 buttons)
3376 (insert " ")
3377 ;; Create tag.
3378 (insert tag)
3379 (widget-specify-sample widget begin (point))
3380 (if (eq custom-buffer-style 'face)
3381 (insert " ")
3382 (if (string-match "face\\'" tag)
3383 (insert ":")
3384 (insert " face: ")))
3385 ;; Sample.
3386 (push (widget-create-child-and-convert widget 'item
3387 :format "(%{%t%})"
3388 :sample-face symbol
3389 :tag "sample")
3390 buttons)
3391 ;; Magic.
3392 (insert "\n")
3393 (let ((magic (widget-create-child-and-convert
3394 widget 'custom-magic nil)))
3395 (widget-put widget :custom-magic magic)
3396 (push magic buttons))
3397 ;; Update buttons.
3398 (widget-put widget :buttons buttons)
3399 ;; Insert documentation.
3400 (widget-put widget :documentation-indent 3)
3401 (widget-add-documentation-string-button
3402 widget :visibility-widget 'custom-visibility)
3404 ;; The comment field
3405 (unless (eq state 'hidden)
3406 (let* ((comment (get symbol 'face-comment))
3407 (comment-widget
3408 (widget-create-child-and-convert
3409 widget 'custom-comment
3410 :parent widget
3411 :value (or comment ""))))
3412 (widget-put widget :comment-widget comment-widget)
3413 (push comment-widget children)))
3414 ;; See also.
3415 (unless (eq state 'hidden)
3416 (when (eq (widget-get widget :custom-level) 1)
3417 (custom-add-parent-links widget))
3418 (custom-add-see-also widget))
3419 ;; Editor.
3420 (unless (eq (preceding-char) ?\n)
3421 (insert "\n"))
3422 (unless (eq state 'hidden)
3423 (message "Creating face editor...")
3424 (custom-load-widget widget)
3425 (unless (widget-get widget :custom-form)
3426 (widget-put widget :custom-form custom-face-default-form))
3427 (let* ((symbol (widget-value widget))
3428 (spec (or (get symbol 'customized-face)
3429 (get symbol 'saved-face)
3430 (get symbol 'face-defface-spec)
3431 ;; Attempt to construct it.
3432 (list (list t (custom-face-attributes-get
3433 symbol (selected-frame))))))
3434 (form (widget-get widget :custom-form))
3435 (indent (widget-get widget :indent))
3436 edit)
3437 ;; If the user has changed this face in some other way,
3438 ;; edit it as the user has specified it.
3439 (if (not (face-spec-match-p symbol spec (selected-frame)))
3440 (setq spec (list (list t (face-attr-construct symbol (selected-frame))))))
3441 (setq spec (custom-pre-filter-face-spec spec))
3442 (setq edit (widget-create-child-and-convert
3443 widget
3444 (cond ((and (eq form 'selected)
3445 (widget-apply custom-face-selected
3446 :match spec))
3447 (when indent (insert-char ?\ indent))
3448 'custom-face-selected)
3449 ((and (not (eq form 'lisp))
3450 (widget-apply custom-face-all
3451 :match spec))
3452 'custom-face-all)
3454 (when indent (insert-char ?\ indent))
3455 'sexp))
3456 :value spec))
3457 (custom-face-state-set widget)
3458 (push edit children)
3459 (widget-put widget :children children))
3460 (message "Creating face editor...done"))))))
3462 (defvar custom-face-menu
3463 `(("Set for Current Session" custom-face-set)
3464 ,@(when (or custom-file init-file-user)
3465 '(("Save for Future Sessions" custom-face-save)))
3466 ("Undo Edits" custom-redraw
3467 (lambda (widget)
3468 (memq (widget-get widget :custom-state) '(modified changed))))
3469 ("Reset to Saved" custom-face-reset-saved
3470 (lambda (widget)
3471 (or (get (widget-value widget) 'saved-face)
3472 (get (widget-value widget) 'saved-face-comment))))
3473 ,@(when (or custom-file init-file-user)
3474 '(("Erase Customization" custom-face-reset-standard
3475 (lambda (widget)
3476 (get (widget-value widget) 'face-defface-spec)))))
3477 ("---" ignore ignore)
3478 ("Add Comment" custom-comment-show custom-comment-invisible-p)
3479 ("---" ignore ignore)
3480 ("For Current Display" custom-face-edit-selected
3481 (lambda (widget)
3482 (not (eq (widget-get widget :custom-form) 'selected))))
3483 ("For All Kinds of Displays" custom-face-edit-all
3484 (lambda (widget)
3485 (not (eq (widget-get widget :custom-form) 'all))))
3486 ("Show Lisp Expression" custom-face-edit-lisp
3487 (lambda (widget)
3488 (not (eq (widget-get widget :custom-form) 'lisp)))))
3489 "Alist of actions for the `custom-face' widget.
3490 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3491 the menu entry, ACTION is the function to call on the widget when the
3492 menu is selected, and FILTER is a predicate which takes a `custom-face'
3493 widget as an argument, and returns non-nil if ACTION is valid on that
3494 widget. If FILTER is nil, ACTION is always valid.")
3496 (defun custom-face-edit-selected (widget)
3497 "Edit selected attributes of the value of WIDGET."
3498 (widget-put widget :custom-state 'unknown)
3499 (widget-put widget :custom-form 'selected)
3500 (custom-redraw widget))
3502 (defun custom-face-edit-all (widget)
3503 "Edit all attributes of the value of WIDGET."
3504 (widget-put widget :custom-state 'unknown)
3505 (widget-put widget :custom-form 'all)
3506 (custom-redraw widget))
3508 (defun custom-face-edit-lisp (widget)
3509 "Edit the Lisp representation of the value of WIDGET."
3510 (widget-put widget :custom-state 'unknown)
3511 (widget-put widget :custom-form 'lisp)
3512 (custom-redraw widget))
3514 (defun custom-face-state-set (widget)
3515 "Set the state of WIDGET."
3516 (let* ((symbol (widget-value widget))
3517 (comment (get symbol 'face-comment))
3518 tmp temp
3519 (state
3520 (cond ((progn
3521 (setq tmp (get symbol 'customized-face))
3522 (setq temp (get symbol 'customized-face-comment))
3523 (or tmp temp))
3524 (if (equal temp comment)
3525 'set
3526 'changed))
3527 ((progn
3528 (setq tmp (get symbol 'saved-face))
3529 (setq temp (get symbol 'saved-face-comment))
3530 (or tmp temp))
3531 (if (equal temp comment)
3532 (cond
3533 ((eq 'user (caar (get symbol 'theme-face)))
3534 'saved)
3535 ((eq 'changed (caar (get symbol 'theme-face)))
3536 'changed)
3537 (t 'themed))
3538 'changed))
3539 ((get symbol 'face-defface-spec)
3540 (if (equal comment nil)
3541 'standard
3542 'changed))
3544 'rogue))))
3545 ;; If the user called set-face-attribute to change the default
3546 ;; for new frames, this face is "set outside of Customize".
3547 (if (and (not (eq state 'rogue))
3548 (get symbol 'face-modified))
3549 (setq state 'changed))
3550 (widget-put widget :custom-state state)))
3552 (defun custom-face-action (widget &optional event)
3553 "Show the menu for `custom-face' WIDGET.
3554 Optional EVENT is the location for the menu."
3555 (if (eq (widget-get widget :custom-state) 'hidden)
3556 (custom-toggle-hide widget)
3557 (let* ((completion-ignore-case t)
3558 (symbol (widget-get widget :value))
3559 (answer (widget-choose (concat "Operation on "
3560 (custom-unlispify-tag-name symbol))
3561 (custom-menu-filter custom-face-menu
3562 widget)
3563 event)))
3564 (if answer
3565 (funcall answer widget)))))
3567 (defun custom-face-set (widget)
3568 "Make the face attributes in WIDGET take effect."
3569 (let* ((symbol (widget-value widget))
3570 (child (car (widget-get widget :children)))
3571 (value (custom-post-filter-face-spec (widget-value child)))
3572 (comment-widget (widget-get widget :comment-widget))
3573 (comment (widget-value comment-widget)))
3574 (when (equal comment "")
3575 (setq comment nil)
3576 ;; Make the comment invisible by hand if it's empty
3577 (custom-comment-hide comment-widget))
3578 (put symbol 'customized-face value)
3579 (custom-push-theme 'theme-face symbol 'user 'set value)
3580 (if (face-spec-choose value)
3581 (face-spec-set symbol value t)
3582 ;; face-set-spec ignores empty attribute lists, so just give it
3583 ;; something harmless instead.
3584 (face-spec-set symbol '((t :foreground unspecified)) t))
3585 (put symbol 'customized-face-comment comment)
3586 (put symbol 'face-comment comment)
3587 (custom-face-state-set widget)
3588 (custom-redraw-magic widget)))
3590 (defun custom-face-mark-to-save (widget)
3591 "Mark for saving the face edited by WIDGET."
3592 (let* ((symbol (widget-value widget))
3593 (child (car (widget-get widget :children)))
3594 (value (custom-post-filter-face-spec (widget-value child)))
3595 (comment-widget (widget-get widget :comment-widget))
3596 (comment (widget-value comment-widget)))
3597 (when (equal comment "")
3598 (setq comment nil)
3599 ;; Make the comment invisible by hand if it's empty
3600 (custom-comment-hide comment-widget))
3601 (custom-push-theme 'theme-face symbol 'user 'set value)
3602 (if (face-spec-choose value)
3603 (face-spec-set symbol value t)
3604 ;; face-set-spec ignores empty attribute lists, so just give it
3605 ;; something harmless instead.
3606 (face-spec-set symbol '((t :foreground unspecified)) t))
3607 (unless (eq (widget-get widget :custom-state) 'standard)
3608 (put symbol 'saved-face value))
3609 (put symbol 'customized-face nil)
3610 (put symbol 'face-comment comment)
3611 (put symbol 'customized-face-comment nil)
3612 (put symbol 'saved-face-comment comment)))
3614 (defsubst custom-face-state-set-and-redraw (widget)
3615 "Set state of face widget WIDGET and redraw with current settings."
3616 (custom-face-state-set widget)
3617 (custom-redraw-magic widget))
3619 (defun custom-face-save (widget)
3620 "Save the face edited by WIDGET."
3621 (custom-face-mark-to-save widget)
3622 (custom-save-all)
3623 (custom-face-state-set-and-redraw widget))
3625 ;; For backward compatibility.
3626 (define-obsolete-function-alias 'custom-face-save-command 'custom-face-save
3627 "22.1")
3629 (defun custom-face-reset-saved (widget)
3630 "Restore WIDGET to the face's default attributes."
3631 (let* ((symbol (widget-value widget))
3632 (child (car (widget-get widget :children)))
3633 (value (get symbol 'saved-face))
3634 (comment (get symbol 'saved-face-comment))
3635 (comment-widget (widget-get widget :comment-widget)))
3636 (unless (or value comment)
3637 (error "No saved value for this face"))
3638 (put symbol 'customized-face nil)
3639 (put symbol 'customized-face-comment nil)
3640 (custom-push-theme 'theme-face symbol 'user 'set value)
3641 (face-spec-set symbol value t)
3642 (put symbol 'face-comment comment)
3643 (widget-value-set child value)
3644 ;; This call manages the comment visibility
3645 (widget-value-set comment-widget (or comment ""))
3646 (custom-face-state-set widget)
3647 (custom-redraw-magic widget)))
3649 (defun custom-face-standard-value (widget)
3650 (get (widget-value widget) 'face-defface-spec))
3652 (defun custom-face-mark-to-reset-standard (widget)
3653 "Restore widget WIDGET to the face's standard attribute values.
3654 If `custom-reset-standard-faces-list' is nil, save, reset and
3655 redraw the widget immediately."
3656 (let* ((symbol (widget-value widget))
3657 (child (car (widget-get widget :children)))
3658 (value (get symbol 'face-defface-spec))
3659 (comment-widget (widget-get widget :comment-widget)))
3660 (unless value
3661 (error "No standard setting for this face"))
3662 (put symbol 'customized-face nil)
3663 (put symbol 'customized-face-comment nil)
3664 (custom-push-theme 'theme-face symbol 'user 'reset)
3665 (face-spec-set symbol value t)
3666 (custom-theme-recalc-face symbol)
3667 (if (and custom-reset-standard-faces-list
3668 (or (get symbol 'saved-face) (get symbol 'saved-face-comment)))
3669 ;; Do this later.
3670 (progn
3671 (put symbol 'saved-face nil)
3672 (put symbol 'saved-face-comment nil)
3673 ;; Append this to `custom-reset-standard-faces-list' and have
3674 ;; `custom-reset-standard-save-and-update' save setting to the
3675 ;; file, update the widget's state, and redraw it.
3676 (setq custom-reset-standard-faces-list
3677 (cons widget custom-reset-standard-faces-list)))
3678 (when (or (get symbol 'saved-face) (get symbol 'saved-face-comment))
3679 (put symbol 'saved-face nil)
3680 (put symbol 'saved-face-comment nil)
3681 (custom-save-all))
3682 (put symbol 'face-comment nil)
3683 (widget-value-set child
3684 (custom-pre-filter-face-spec
3685 (list (list t (custom-face-attributes-get
3686 symbol nil)))))
3687 ;; This call manages the comment visibility
3688 (widget-value-set comment-widget "")
3689 (custom-face-state-set widget)
3690 (custom-redraw-magic widget))))
3692 (defun custom-face-reset-standard (widget)
3693 "Restore WIDGET to the face's standard attribute values.
3694 This operation eliminates any saved attributes for the face,
3695 restoring it to the state of a face that has never been customized."
3696 (let (custom-reset-standard-faces-list)
3697 (custom-face-mark-to-reset-standard widget)))
3699 ;;; The `face' Widget.
3701 (defvar widget-face-prompt-value-history nil
3702 "History of input to `widget-face-prompt-value'.")
3704 (define-widget 'face 'symbol
3705 "A Lisp face name (with sample)."
3706 :format "%{%t%}: (%{sample%}) %v"
3707 :tag "Face"
3708 :value 'default
3709 :sample-face-get 'widget-face-sample-face-get
3710 :notify 'widget-face-notify
3711 :match (lambda (widget value) (facep value))
3712 :complete-function (lambda ()
3713 (interactive)
3714 (lisp-complete-symbol 'facep))
3715 :prompt-match 'facep
3716 :prompt-history 'widget-face-prompt-value-history
3717 :validate (lambda (widget)
3718 (unless (facep (widget-value widget))
3719 (widget-put widget
3720 :error (format "Invalid face: %S"
3721 (widget-value widget)))
3722 widget)))
3724 (defun widget-face-sample-face-get (widget)
3725 (let ((value (widget-value widget)))
3726 (if (facep value)
3727 value
3728 'default)))
3730 (defun widget-face-notify (widget child &optional event)
3731 "Update the sample, and notify the parent."
3732 (overlay-put (widget-get widget :sample-overlay)
3733 'face (widget-apply widget :sample-face-get))
3734 (widget-default-notify widget child event))
3737 ;;; The `hook' Widget.
3739 (define-widget 'hook 'list
3740 "An Emacs Lisp hook."
3741 :value-to-internal (lambda (widget value)
3742 (if (and value (symbolp value))
3743 (list value)
3744 value))
3745 :match (lambda (widget value)
3746 (or (symbolp value)
3747 (widget-group-match widget value)))
3748 ;; Avoid adding undefined functions to the hook, especially for
3749 ;; things like `find-file-hook' or even more basic ones, to avoid
3750 ;; chaos.
3751 :set (lambda (symbol value)
3752 (dolist (elt value)
3753 (if (fboundp elt)
3754 (add-hook symbol elt))))
3755 :convert-widget 'custom-hook-convert-widget
3756 :tag "Hook")
3758 (defun custom-hook-convert-widget (widget)
3759 ;; Handle `:options'.
3760 (let* ((options (widget-get widget :options))
3761 (other `(editable-list :inline t
3762 :entry-format "%i %d%v"
3763 (function :format " %v")))
3764 (args (if options
3765 (list `(checklist :inline t
3766 ,@(mapcar (lambda (entry)
3767 `(function-item ,entry))
3768 options))
3769 other)
3770 (list other))))
3771 (widget-put widget :args args)
3772 widget))
3774 ;;; The `custom-group-link' Widget.
3776 (define-widget 'custom-group-link 'link
3777 "Show parent in other window when activated."
3778 :button-face 'custom-link
3779 :mouse-face 'highlight
3780 :pressed-face 'highlight
3781 :help-echo "Create customization buffer for this group."
3782 :keymap custom-mode-link-map
3783 :follow-link 'mouse-face
3784 :action 'custom-group-link-action)
3786 (defun custom-group-link-action (widget &rest ignore)
3787 (customize-group (widget-value widget)))
3789 ;;; The `custom-group' Widget.
3791 (defcustom custom-group-tag-faces nil
3792 ;; In XEmacs, this ought to play games with font size.
3793 ;; Fixme: make it do so in Emacs.
3794 "Face used for group tags.
3795 The first member is used for level 1 groups, the second for level 2,
3796 and so forth. The remaining group tags are shown with `custom-group-tag'."
3797 :type '(repeat face)
3798 :group 'custom-faces)
3800 (defface custom-group-tag-1
3801 `((((class color)
3802 (background dark))
3803 (:foreground "pink" :weight bold :height 1.2 :inherit variable-pitch))
3804 (((min-colors 88) (class color)
3805 (background light))
3806 (:foreground "red1" :weight bold :height 1.2 :inherit variable-pitch))
3807 (((class color)
3808 (background light))
3809 (:foreground "red" :weight bold :height 1.2 :inherit variable-pitch))
3810 (t (:weight bold)))
3811 "Face used for group tags."
3812 :group 'custom-faces)
3813 (define-obsolete-face-alias 'custom-group-tag-face-1 'custom-group-tag-1 "22.1")
3815 (defface custom-group-tag
3816 `((((class color)
3817 (background dark))
3818 (:foreground "light blue" :weight bold :height 1.2 :inherit variable-pitch))
3819 (((min-colors 88) (class color)
3820 (background light))
3821 (:foreground "blue1" :weight bold :height 1.2 :inherit variable-pitch))
3822 (((class color)
3823 (background light))
3824 (:foreground "blue" :weight bold :height 1.2 :inherit variable-pitch))
3825 (t (:weight bold)))
3826 "Face used for low level group tags."
3827 :group 'custom-faces)
3828 (define-obsolete-face-alias 'custom-group-tag-face 'custom-group-tag "22.1")
3830 (define-widget 'custom-group 'custom
3831 "Customize group."
3832 :format "%v"
3833 :sample-face-get 'custom-group-sample-face-get
3834 :documentation-property 'group-documentation
3835 :help-echo "Set or reset all members of this group."
3836 :value-create 'custom-group-value-create
3837 :action 'custom-group-action
3838 :custom-category 'group
3839 :custom-set 'custom-group-set
3840 :custom-mark-to-save 'custom-group-mark-to-save
3841 :custom-reset-current 'custom-group-reset-current
3842 :custom-reset-saved 'custom-group-reset-saved
3843 :custom-reset-standard 'custom-group-reset-standard
3844 :custom-mark-to-reset-standard 'custom-group-mark-to-reset-standard
3845 :custom-state-set-and-redraw 'custom-group-state-set-and-redraw
3846 :custom-menu 'custom-group-menu-create)
3848 (defun custom-group-sample-face-get (widget)
3849 ;; Use :sample-face.
3850 (or (nth (1- (widget-get widget :custom-level)) custom-group-tag-faces)
3851 'custom-group-tag))
3853 (define-widget 'custom-group-visibility 'visibility
3854 "An indicator and manipulator for hidden group contents."
3855 :create 'custom-group-visibility-create)
3857 (defun custom-group-visibility-create (widget)
3858 (let ((visible (widget-value widget)))
3859 (if visible
3860 (insert "--------")))
3861 (widget-default-create widget))
3863 (defun custom-group-members (symbol groups-only)
3864 "Return SYMBOL's custom group members.
3865 If GROUPS-ONLY non-nil, return only those members that are groups."
3866 (if (not groups-only)
3867 (get symbol 'custom-group)
3868 (let (members)
3869 (dolist (entry (get symbol 'custom-group))
3870 (when (eq (nth 1 entry) 'custom-group)
3871 (push entry members)))
3872 (nreverse members))))
3874 (defun custom-group-value-create (widget)
3875 "Insert a customize group for WIDGET in the current buffer."
3876 (unless (eq (widget-get widget :custom-state) 'hidden)
3877 (custom-load-widget widget))
3878 (let* ((state (widget-get widget :custom-state))
3879 (level (widget-get widget :custom-level))
3880 ;; (indent (widget-get widget :indent))
3881 (prefix (widget-get widget :custom-prefix))
3882 (buttons (widget-get widget :buttons))
3883 (tag (widget-get widget :tag))
3884 (symbol (widget-value widget))
3885 (members (custom-group-members symbol
3886 (and (eq custom-buffer-style 'tree)
3887 custom-browse-only-groups)))
3888 (doc (widget-docstring widget)))
3889 (cond ((and (eq custom-buffer-style 'tree)
3890 (eq state 'hidden)
3891 (or members (custom-unloaded-widget-p widget)))
3892 (custom-browse-insert-prefix prefix)
3893 (push (widget-create-child-and-convert
3894 widget 'custom-browse-visibility
3895 ;; :tag-glyph "plus"
3896 :tag "+")
3897 buttons)
3898 (insert "-- ")
3899 ;; (widget-glyph-insert nil "-- " "horizontal")
3900 (push (widget-create-child-and-convert
3901 widget 'custom-browse-group-tag)
3902 buttons)
3903 (insert " " tag "\n")
3904 (widget-put widget :buttons buttons))
3905 ((and (eq custom-buffer-style 'tree)
3906 (zerop (length members)))
3907 (custom-browse-insert-prefix prefix)
3908 (insert "[ ]-- ")
3909 ;; (widget-glyph-insert nil "[ ]" "empty")
3910 ;; (widget-glyph-insert nil "-- " "horizontal")
3911 (push (widget-create-child-and-convert
3912 widget 'custom-browse-group-tag)
3913 buttons)
3914 (insert " " tag "\n")
3915 (widget-put widget :buttons buttons))
3916 ((eq custom-buffer-style 'tree)
3917 (custom-browse-insert-prefix prefix)
3918 (if (zerop (length members))
3919 (progn
3920 (custom-browse-insert-prefix prefix)
3921 (insert "[ ]-- ")
3922 ;; (widget-glyph-insert nil "[ ]" "empty")
3923 ;; (widget-glyph-insert nil "-- " "horizontal")
3924 (push (widget-create-child-and-convert
3925 widget 'custom-browse-group-tag)
3926 buttons)
3927 (insert " " tag "\n")
3928 (widget-put widget :buttons buttons))
3929 (push (widget-create-child-and-convert
3930 widget 'custom-browse-visibility
3931 ;; :tag-glyph "minus"
3932 :tag "-")
3933 buttons)
3934 (insert "-\\ ")
3935 ;; (widget-glyph-insert nil "-\\ " "top")
3936 (push (widget-create-child-and-convert
3937 widget 'custom-browse-group-tag)
3938 buttons)
3939 (insert " " tag "\n")
3940 (widget-put widget :buttons buttons)
3941 (message "Creating group...")
3942 (let* ((members (custom-sort-items
3943 members
3944 ;; Never sort the top-level custom group.
3945 (unless (eq symbol 'emacs)
3946 custom-browse-sort-alphabetically)
3947 custom-browse-order-groups))
3948 (prefixes (widget-get widget :custom-prefixes))
3949 (custom-prefix-list (custom-prefix-add symbol prefixes))
3950 (extra-prefix (if (widget-get widget :custom-last)
3952 " | "))
3953 (prefix (concat prefix extra-prefix))
3954 children entry)
3955 (while members
3956 (setq entry (car members)
3957 members (cdr members))
3958 (push (widget-create-child-and-convert
3959 widget (nth 1 entry)
3960 :group widget
3961 :tag (custom-unlispify-tag-name (nth 0 entry))
3962 :custom-prefixes custom-prefix-list
3963 :custom-level (1+ level)
3964 :custom-last (null members)
3965 :value (nth 0 entry)
3966 :custom-prefix prefix)
3967 children))
3968 (widget-put widget :children (reverse children)))
3969 (message "Creating group...done")))
3970 ;; Nested style.
3971 ((eq state 'hidden)
3972 ;; Create level indicator.
3973 ;; Create tag.
3974 (if (eq custom-buffer-style 'links)
3975 (push (widget-create-child-and-convert
3976 widget 'custom-group-link
3977 :tag tag
3978 symbol)
3979 buttons)
3980 (insert-char ?\ (* custom-buffer-indent (1- level)))
3981 (insert "-- ")
3982 (push (widget-create-child-and-convert
3983 widget 'custom-group-visibility
3984 :help-echo "Show members of this group."
3985 :action 'custom-toggle-parent
3986 (not (eq state 'hidden)))
3987 buttons))
3988 (insert " : ")
3989 ;; Create magic button.
3990 (let ((magic (widget-create-child-and-convert
3991 widget 'custom-magic nil)))
3992 (widget-put widget :custom-magic magic)
3993 (push magic buttons))
3994 ;; Update buttons.
3995 (widget-put widget :buttons buttons)
3996 ;; Insert documentation.
3997 (if (and (eq custom-buffer-style 'links) (> level 1))
3998 (widget-put widget :documentation-indent 0))
3999 (widget-add-documentation-string-button
4000 widget :visibility-widget 'custom-visibility))
4002 ;; Nested style.
4003 (t ;Visible.
4004 ;; Draw a horizontal line (this works for both graphical
4005 ;; and text displays):
4006 (let ((p (point)))
4007 (insert "\n")
4008 (put-text-property p (1+ p) 'face '(:underline t))
4009 (overlay-put (make-overlay p (1+ p))
4010 'before-string
4011 (propertize "\n" 'face '(:underline t)
4012 'display '(space :align-to 999))))
4014 ;; Add parent groups references above the group.
4015 (when (eq level 1)
4016 (if (custom-add-parent-links widget "Parent groups:")
4017 (insert "\n")))
4018 (insert-char ?\ (* custom-buffer-indent (1- level)))
4019 ;; Create tag.
4020 (let ((start (point)))
4021 (insert tag " group: ")
4022 (widget-specify-sample widget start (point)))
4023 (cond
4024 ((not doc)
4025 (insert " Group definition missing. "))
4026 ((< (length doc) 50)
4027 (insert doc)))
4028 ;; Create visibility indicator.
4029 (unless (eq custom-buffer-style 'links)
4030 (insert "--------")
4031 (push (widget-create-child-and-convert
4032 widget 'visibility
4033 :help-echo "Hide members of this group."
4034 :action 'custom-toggle-parent
4035 (not (eq state 'hidden)))
4036 buttons)
4037 (insert " "))
4038 (insert "\n")
4039 ;; Create magic button.
4040 (let ((magic (widget-create-child-and-convert
4041 widget 'custom-magic
4042 :indent 0
4043 nil)))
4044 (widget-put widget :custom-magic magic)
4045 (push magic buttons))
4046 ;; Update buttons.
4047 (widget-put widget :buttons buttons)
4048 ;; Insert documentation.
4049 (when (and doc (>= (length doc) 50))
4050 (widget-add-documentation-string-button
4051 widget :visibility-widget 'custom-visibility))
4053 ;; Parent groups.
4054 (if nil ;;; This should test that the buffer
4055 ;;; was not made to display a group.
4056 (when (eq level 1)
4057 (insert-char ?\ custom-buffer-indent)
4058 (custom-add-parent-links widget)))
4059 (custom-add-see-also widget
4060 (make-string (* custom-buffer-indent level)
4061 ?\ ))
4062 ;; Members.
4063 (message "Creating group...")
4064 (let* ((members (custom-sort-items
4065 members
4066 ;; Never sort the top-level custom group.
4067 (unless (eq symbol 'emacs)
4068 custom-buffer-sort-alphabetically)
4069 custom-buffer-order-groups))
4070 (prefixes (widget-get widget :custom-prefixes))
4071 (custom-prefix-list (custom-prefix-add symbol prefixes))
4072 (len (length members))
4073 (count 0)
4074 (reporter (make-progress-reporter
4075 "Creating group entries..." 0 len))
4076 children)
4077 (setq children
4078 (mapcar
4079 (lambda (entry)
4080 (widget-insert "\n")
4081 (progress-reporter-update reporter (setq count (1+ count)))
4082 (let ((sym (nth 0 entry))
4083 (type (nth 1 entry))
4084 hidden-p)
4085 (prog1
4086 (widget-create-child-and-convert
4087 widget type
4088 :group widget
4089 :tag (custom-unlispify-tag-name sym)
4090 :custom-prefixes custom-prefix-list
4091 :custom-level (1+ level)
4092 :value sym)
4093 (unless (eq (preceding-char) ?\n)
4094 (widget-insert "\n")))))
4095 members))
4096 (mapc 'custom-magic-reset children)
4097 (widget-put widget :children children)
4098 (custom-group-state-update widget)
4099 (progress-reporter-done reporter))
4100 ;; End line
4101 (let ((p (1+ (point))))
4102 (insert "\n\n")
4103 (put-text-property p (1+ p) 'face '(:underline t))
4104 (overlay-put (make-overlay p (1+ p))
4105 'before-string
4106 (propertize "\n" 'face '(:underline t)
4107 'display '(space :align-to 999))))))))
4109 (defvar custom-group-menu
4110 `(("Set for Current Session" custom-group-set
4111 (lambda (widget)
4112 (eq (widget-get widget :custom-state) 'modified)))
4113 ,@(when (or custom-file init-file-user)
4114 '(("Save for Future Sessions" custom-group-save
4115 (lambda (widget)
4116 (memq (widget-get widget :custom-state) '(modified set))))))
4117 ("Undo Edits" custom-group-reset-current
4118 (lambda (widget)
4119 (memq (widget-get widget :custom-state) '(modified))))
4120 ("Reset to Saved" custom-group-reset-saved
4121 (lambda (widget)
4122 (memq (widget-get widget :custom-state) '(modified set))))
4123 ,@(when (or custom-file init-file-user)
4124 '(("Erase Customization" custom-group-reset-standard
4125 (lambda (widget)
4126 (memq (widget-get widget :custom-state) '(modified set saved)))))))
4127 "Alist of actions for the `custom-group' widget.
4128 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
4129 the menu entry, ACTION is the function to call on the widget when the
4130 menu is selected, and FILTER is a predicate which takes a `custom-group'
4131 widget as an argument, and returns non-nil if ACTION is valid on that
4132 widget. If FILTER is nil, ACTION is always valid.")
4134 (defun custom-group-action (widget &optional event)
4135 "Show the menu for `custom-group' WIDGET.
4136 Optional EVENT is the location for the menu."
4137 (if (eq (widget-get widget :custom-state) 'hidden)
4138 (custom-toggle-hide widget)
4139 (let* ((completion-ignore-case t)
4140 (answer (widget-choose (concat "Operation on "
4141 (custom-unlispify-tag-name
4142 (widget-get widget :value)))
4143 (custom-menu-filter custom-group-menu
4144 widget)
4145 event)))
4146 (if answer
4147 (funcall answer widget)))))
4149 (defun custom-group-set (widget)
4150 "Set changes in all modified group members."
4151 (dolist (child (widget-get widget :children))
4152 (when (eq (widget-get child :custom-state) 'modified)
4153 (widget-apply child :custom-set))))
4155 (defun custom-group-mark-to-save (widget)
4156 "Mark all modified group members for saving."
4157 (dolist (child (widget-get widget :children))
4158 (when (memq (widget-get child :custom-state) '(modified set))
4159 (widget-apply child :custom-mark-to-save))))
4161 (defsubst custom-group-state-set-and-redraw (widget)
4162 "Set state of group widget WIDGET and redraw with current settings."
4163 (dolist (child (widget-get widget :children))
4164 (when (memq (widget-get child :custom-state) '(modified set))
4165 (widget-apply child :custom-state-set-and-redraw))))
4167 (defun custom-group-save (widget)
4168 "Save all modified group members."
4169 (custom-group-mark-to-save widget)
4170 (custom-save-all)
4171 (custom-group-state-set-and-redraw widget))
4173 (defun custom-group-reset-current (widget)
4174 "Reset all modified group members."
4175 (dolist (child (widget-get widget :children))
4176 (when (eq (widget-get child :custom-state) 'modified)
4177 (widget-apply child :custom-reset-current))))
4179 (defun custom-group-reset-saved (widget)
4180 "Reset all modified or set group members."
4181 (dolist (child (widget-get widget :children))
4182 (when (memq (widget-get child :custom-state) '(modified set))
4183 (widget-apply child :custom-reset-saved))))
4185 (defun custom-group-reset-standard (widget)
4186 "Reset all modified, set, or saved group members."
4187 (let ((custom-reset-standard-variables-list '(t))
4188 (custom-reset-standard-faces-list '(t)))
4189 (custom-group-mark-to-reset-standard widget)
4190 (custom-reset-standard-save-and-update)))
4192 (defun custom-group-mark-to-reset-standard (widget)
4193 "Mark to reset all modified, set, or saved group members."
4194 (dolist (child (widget-get widget :children))
4195 (when (memq (widget-get child :custom-state)
4196 '(modified set saved))
4197 (widget-apply child :custom-mark-to-reset-standard))))
4199 (defun custom-group-state-update (widget)
4200 "Update magic."
4201 (unless (eq (widget-get widget :custom-state) 'hidden)
4202 (let* ((children (widget-get widget :children))
4203 (states (mapcar (lambda (child)
4204 (widget-get child :custom-state))
4205 children))
4206 (magics custom-magic-alist)
4207 (found 'standard))
4208 (while magics
4209 (let ((magic (car (car magics))))
4210 (if (and (not (eq magic 'hidden))
4211 (memq magic states))
4212 (setq found magic
4213 magics nil)
4214 (setq magics (cdr magics)))))
4215 (widget-put widget :custom-state found)))
4216 (custom-magic-reset widget))
4218 ;;; Reading and writing the custom file.
4220 ;;;###autoload
4221 (defcustom custom-file nil
4222 "File used for storing customization information.
4223 The default is nil, which means to use your init file
4224 as specified by `user-init-file'. If the value is not nil,
4225 it should be an absolute file name.
4227 You can set this option through Custom, if you carefully read the
4228 last paragraph below. However, usually it is simpler to write
4229 something like the following in your init file:
4231 \(setq custom-file \"~/.emacs-custom.el\")
4232 \(load custom-file)
4234 Note that both lines are necessary: the first line tells Custom to
4235 save all customizations in this file, but does not load it.
4237 When you change this variable outside Custom, look in the
4238 previous custom file \(usually your init file) for the
4239 forms `(custom-set-variables ...)' and `(custom-set-faces ...)',
4240 and copy them (whichever ones you find) to the new custom file.
4241 This will preserve your existing customizations.
4243 If you save this option using Custom, Custom will write all
4244 currently saved customizations, including the new one for this
4245 option itself, into the file you specify, overwriting any
4246 `custom-set-variables' and `custom-set-faces' forms already
4247 present in that file. It will not delete any customizations from
4248 the old custom file. You should do that manually if that is what you
4249 want. You also have to put something like `\(load \"CUSTOM-FILE\")
4250 in your init file, where CUSTOM-FILE is the actual name of the
4251 file. Otherwise, Emacs will not load the file when it starts up,
4252 and hence will not set `custom-file' to that file either."
4253 :type '(choice (const :tag "Your Emacs init file" nil)
4254 (file :format "%t:%v%d"
4255 :doc
4256 "Please read entire docstring below before setting \
4257 this through Custom.
4258 Click on \"More\" \(or position point there and press RETURN)
4259 if only the first line of the docstring is shown."))
4260 :group 'customize)
4262 (defun custom-file ()
4263 "Return the file name for saving customizations."
4264 (file-chase-links
4265 (or custom-file
4266 (let ((user-init-file user-init-file)
4267 (default-init-file
4268 (if (eq system-type 'ms-dos) "~/_emacs" "~/.emacs")))
4269 (when (null user-init-file)
4270 (if (or (file-exists-p default-init-file)
4271 (and (eq system-type 'windows-nt)
4272 (file-exists-p "~/_emacs")))
4273 ;; Started with -q, i.e. the file containing
4274 ;; Custom settings hasn't been read. Saving
4275 ;; settings there would overwrite other settings.
4276 (error "Saving settings from \"emacs -q\" would overwrite existing customizations"))
4277 (setq user-init-file default-init-file))
4278 user-init-file))))
4280 ;; If recentf-mode is non-nil, this is defined.
4281 (declare-function recentf-expand-file-name "recentf" (name))
4283 ;;;###autoload
4284 (defun custom-save-all ()
4285 "Save all customizations in `custom-file'."
4286 (when (and (null custom-file) init-file-had-error)
4287 (error "Cannot save customizations; init file was not fully loaded"))
4288 (let* ((filename (custom-file))
4289 (recentf-exclude
4290 (if recentf-mode
4291 (cons (concat "\\`"
4292 (regexp-quote
4293 (recentf-expand-file-name (custom-file)))
4294 "\\'")
4295 recentf-exclude)))
4296 (old-buffer (find-buffer-visiting filename))
4297 old-buffer-name)
4299 (with-current-buffer (let ((find-file-visit-truename t))
4300 (or old-buffer (find-file-noselect filename)))
4301 ;; We'll save using file-precious-flag, so avoid destroying
4302 ;; symlinks. (If we're not already visiting the buffer, this is
4303 ;; handled by find-file-visit-truename, above.)
4304 (when old-buffer
4305 (setq old-buffer-name (buffer-file-name))
4306 (set-visited-file-name (file-chase-links filename)))
4308 (unless (eq major-mode 'emacs-lisp-mode)
4309 (emacs-lisp-mode))
4310 (let ((inhibit-read-only t))
4311 (custom-save-variables)
4312 (custom-save-faces))
4313 (let ((file-precious-flag t))
4314 (save-buffer))
4315 (if old-buffer
4316 (progn
4317 (set-visited-file-name old-buffer-name)
4318 (set-buffer-modified-p nil))
4319 (kill-buffer (current-buffer))))))
4321 ;;;###autoload
4322 (defun customize-save-customized ()
4323 "Save all user options which have been set in this session."
4324 (interactive)
4325 (mapatoms (lambda (symbol)
4326 (let ((face (get symbol 'customized-face))
4327 (value (get symbol 'customized-value))
4328 (face-comment (get symbol 'customized-face-comment))
4329 (variable-comment
4330 (get symbol 'customized-variable-comment)))
4331 (when face
4332 (put symbol 'saved-face face)
4333 (custom-push-theme 'theme-face symbol 'user 'set value)
4334 (put symbol 'customized-face nil))
4335 (when value
4336 (put symbol 'saved-value value)
4337 (custom-push-theme 'theme-value symbol 'user 'set value)
4338 (put symbol 'customized-value nil))
4339 (when variable-comment
4340 (put symbol 'saved-variable-comment variable-comment)
4341 (put symbol 'customized-variable-comment nil))
4342 (when face-comment
4343 (put symbol 'saved-face-comment face-comment)
4344 (put symbol 'customized-face-comment nil)))))
4345 ;; We really should update all custom buffers here.
4346 (custom-save-all))
4348 ;; Editing the custom file contents in a buffer.
4350 (defun custom-save-delete (symbol)
4351 "Delete all calls to SYMBOL from the contents of the current buffer.
4352 Leave point at the old location of the first such call,
4353 or (if there were none) at the end of the buffer.
4355 This function does not save the buffer."
4356 (goto-char (point-min))
4357 ;; Skip all whitespace and comments.
4358 (while (forward-comment 1))
4359 (or (eobp)
4360 (save-excursion (forward-sexp (buffer-size)))) ; Test for scan errors.
4361 (let (first)
4362 (catch 'found
4363 (while t ;; We exit this loop only via throw.
4364 ;; Skip all whitespace and comments.
4365 (while (forward-comment 1))
4366 (let ((start (point))
4367 (sexp (condition-case nil
4368 (read (current-buffer))
4369 (end-of-file (throw 'found nil)))))
4370 (when (and (listp sexp)
4371 (eq (car sexp) symbol))
4372 (delete-region start (point))
4373 (unless first
4374 (setq first (point)))))))
4375 (if first
4376 (goto-char first)
4377 ;; Move in front of local variables, otherwise long Custom
4378 ;; entries would make them ineffective.
4379 (let ((pos (point-max))
4380 (case-fold-search t))
4381 (save-excursion
4382 (goto-char (point-max))
4383 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
4384 'move)
4385 (when (search-forward "Local Variables:" nil t)
4386 (setq pos (line-beginning-position))))
4387 (goto-char pos)))))
4389 (defun custom-save-variables ()
4390 "Save all customized variables in `custom-file'."
4391 (save-excursion
4392 (custom-save-delete 'custom-set-variables)
4393 (let ((standard-output (current-buffer))
4394 (saved-list (make-list 1 0))
4395 sort-fold-case)
4396 ;; First create a sorted list of saved variables.
4397 (mapatoms
4398 (lambda (symbol)
4399 (if (and (get symbol 'saved-value)
4400 ;; ignore theme values
4401 (or (null (get symbol 'theme-value))
4402 (eq 'user (caar (get symbol 'theme-value)))))
4403 (nconc saved-list (list symbol)))))
4404 (setq saved-list (sort (cdr saved-list) 'string<))
4405 (unless (bolp)
4406 (princ "\n"))
4407 (princ "(custom-set-variables
4408 ;; custom-set-variables was added by Custom.
4409 ;; If you edit it by hand, you could mess it up, so be careful.
4410 ;; Your init file should contain only one such instance.
4411 ;; If there is more than one, they won't work right.\n")
4412 (dolist (symbol saved-list)
4413 (let ((spec (car-safe (get symbol 'theme-value)))
4414 (value (get symbol 'saved-value))
4415 (requests (get symbol 'custom-requests))
4416 (now (and (not (custom-variable-p symbol))
4417 (or (boundp symbol)
4418 (eq (get symbol 'force-value)
4419 'rogue))))
4420 (comment (get symbol 'saved-variable-comment)))
4421 ;; Check REQUESTS for validity.
4422 (dolist (request requests)
4423 (when (and (symbolp request) (not (featurep request)))
4424 (message "Unknown requested feature: %s" request)
4425 (setq requests (delq request requests))))
4426 ;; Is there anything customized about this variable?
4427 (when (or (and spec (eq (car spec) 'user))
4428 comment
4429 (and (null spec) (get symbol 'saved-value)))
4430 ;; Output an element for this variable.
4431 ;; It has the form (SYMBOL VALUE-FORM NOW REQUESTS COMMENT).
4432 ;; SYMBOL is the variable name.
4433 ;; VALUE-FORM is an expression to return the customized value.
4434 ;; NOW if non-nil means always set the variable immediately
4435 ;; when the customizations are reloaded. This is used
4436 ;; for rogue variables
4437 ;; REQUESTS is a list of packages to load before setting the
4438 ;; variable. Each element of it will be passed to `require'.
4439 ;; COMMENT is whatever comment the user has specified
4440 ;; with the customize facility.
4441 (unless (bolp)
4442 (princ "\n"))
4443 (princ " '(")
4444 (prin1 symbol)
4445 (princ " ")
4446 (prin1 (car value))
4447 (when (or now requests comment)
4448 (princ " ")
4449 (prin1 now)
4450 (when (or requests comment)
4451 (princ " ")
4452 (prin1 requests)
4453 (when comment
4454 (princ " ")
4455 (prin1 comment))))
4456 (princ ")"))))
4457 (if (bolp)
4458 (princ " "))
4459 (princ ")")
4460 (unless (looking-at "\n")
4461 (princ "\n")))))
4463 (defun custom-save-faces ()
4464 "Save all customized faces in `custom-file'."
4465 (save-excursion
4466 (custom-save-delete 'custom-reset-faces)
4467 (custom-save-delete 'custom-set-faces)
4468 (let ((standard-output (current-buffer))
4469 (saved-list (make-list 1 0))
4470 sort-fold-case)
4471 ;; First create a sorted list of saved faces.
4472 (mapatoms
4473 (lambda (symbol)
4474 (if (and (get symbol 'saved-face)
4475 (eq 'user (car (car-safe (get symbol 'theme-face)))))
4476 (nconc saved-list (list symbol)))))
4477 (setq saved-list (sort (cdr saved-list) 'string<))
4478 ;; The default face must be first, since it affects the others.
4479 (if (memq 'default saved-list)
4480 (setq saved-list (cons 'default (delq 'default saved-list))))
4481 (unless (bolp)
4482 (princ "\n"))
4483 (princ "(custom-set-faces
4484 ;; custom-set-faces was added by Custom.
4485 ;; If you edit it by hand, you could mess it up, so be careful.
4486 ;; Your init file should contain only one such instance.
4487 ;; If there is more than one, they won't work right.\n")
4488 (dolist (symbol saved-list)
4489 (let ((spec (car-safe (get symbol 'theme-face)))
4490 (value (get symbol 'saved-face))
4491 (now (not (or (get symbol 'face-defface-spec)
4492 (and (not (custom-facep symbol))
4493 (not (get symbol 'force-face))))))
4494 (comment (get symbol 'saved-face-comment)))
4495 (when (or (and spec (eq (nth 0 spec) 'user))
4496 comment
4497 (and (null spec) (get symbol 'saved-face)))
4498 ;; Don't print default face here.
4499 (unless (bolp)
4500 (princ "\n"))
4501 (princ " '(")
4502 (prin1 symbol)
4503 (princ " ")
4504 (prin1 value)
4505 (when (or now comment)
4506 (princ " ")
4507 (prin1 now)
4508 (when comment
4509 (princ " ")
4510 (prin1 comment)))
4511 (princ ")"))))
4512 (if (bolp)
4513 (princ " "))
4514 (princ ")")
4515 (unless (looking-at "\n")
4516 (princ "\n")))))
4518 ;;; The Customize Menu.
4520 ;;; Menu support
4522 (defcustom custom-menu-nesting 2
4523 "Maximum nesting in custom menus."
4524 :type 'integer
4525 :group 'custom-menu)
4527 (defun custom-face-menu-create (widget symbol)
4528 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
4529 (vector (custom-unlispify-menu-entry symbol)
4530 `(customize-face ',symbol)
4533 (defun custom-variable-menu-create (widget symbol)
4534 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
4535 (let ((type (get symbol 'custom-type)))
4536 (unless (listp type)
4537 (setq type (list type)))
4538 (if (and type (widget-get type :custom-menu))
4539 (widget-apply type :custom-menu symbol)
4540 (vector (custom-unlispify-menu-entry symbol)
4541 `(customize-variable ',symbol)
4542 t))))
4544 ;; Add checkboxes to boolean variable entries.
4545 (widget-put (get 'boolean 'widget-type)
4546 :custom-menu (lambda (widget symbol)
4547 (vector (custom-unlispify-menu-entry symbol)
4548 `(customize-variable ',symbol)
4549 ':style 'toggle
4550 ':selected symbol)))
4552 (defun custom-group-menu-create (widget symbol)
4553 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
4554 `( ,(custom-unlispify-menu-entry symbol t)
4555 :filter (lambda (&rest junk)
4556 (let* ((menu (custom-menu-create ',symbol)))
4557 (if (consp menu) (cdr menu) menu)))))
4559 ;;;###autoload
4560 (defun custom-menu-create (symbol)
4561 "Create menu for customization group SYMBOL.
4562 The menu is in a format applicable to `easy-menu-define'."
4563 (let* ((deactivate-mark nil)
4564 (item (vector (custom-unlispify-menu-entry symbol)
4565 `(customize-group ',symbol)
4566 t)))
4567 (if (and (or (not (boundp 'custom-menu-nesting))
4568 (>= custom-menu-nesting 0))
4569 (progn
4570 (custom-load-symbol symbol)
4571 (< (length (get symbol 'custom-group)) widget-menu-max-size)))
4572 (let ((custom-prefix-list (custom-prefix-add symbol
4573 custom-prefix-list))
4574 (members (custom-sort-items (get symbol 'custom-group)
4575 custom-menu-sort-alphabetically
4576 custom-menu-order-groups)))
4577 `(,(custom-unlispify-menu-entry symbol t)
4578 ,item
4579 "--"
4580 ,@(mapcar (lambda (entry)
4581 (widget-apply (if (listp (nth 1 entry))
4582 (nth 1 entry)
4583 (list (nth 1 entry)))
4584 :custom-menu (nth 0 entry)))
4585 members)))
4586 item)))
4588 ;;;###autoload
4589 (defun customize-menu-create (symbol &optional name)
4590 "Return a customize menu for customization group SYMBOL.
4591 If optional NAME is given, use that as the name of the menu.
4592 Otherwise the menu will be named `Customize'.
4593 The format is suitable for use with `easy-menu-define'."
4594 (unless name
4595 (setq name "Customize"))
4596 `(,name
4597 :filter (lambda (&rest junk)
4598 (let ((menu (custom-menu-create ',symbol)))
4599 (if (consp menu) (cdr menu) menu)))))
4601 ;;; Toolbar and menubar support
4603 (easy-menu-define
4604 Custom-mode-menu (list custom-mode-map custom-field-keymap)
4605 "Menu used in customization buffers."
4606 (nconc (list "Custom"
4607 (customize-menu-create 'customize))
4608 (mapcar (lambda (arg)
4609 (let ((tag (nth 0 arg))
4610 (command (nth 1 arg))
4611 (active (nth 2 arg))
4612 (help (nth 3 arg)))
4613 (vector tag command :active (eval active) :help help)))
4614 custom-commands)))
4616 (defvar tool-bar-map)
4618 ;;; `custom-tool-bar-map' used to be set up here. This will fail to
4619 ;;; DTRT when `display-graphic-p' returns nil during compilation. Hence
4620 ;;; we set this up lazily in `Custom-mode'.
4621 (defvar custom-tool-bar-map nil
4622 "Keymap for toolbar in Custom mode.")
4624 ;;; The Custom Mode.
4626 (defun Custom-no-edit (pos &optional event)
4627 "Invoke button at POS, or refuse to allow editing of Custom buffer."
4628 (interactive "@d")
4629 (error "You can't edit this part of the Custom buffer"))
4631 (defun Custom-newline (pos &optional event)
4632 "Invoke button at POS, or refuse to allow editing of Custom buffer."
4633 (interactive "@d")
4634 (let ((button (get-char-property pos 'button)))
4635 (if button
4636 (widget-apply-action button event)
4637 (error "You can't edit this part of the Custom buffer"))))
4639 (defun Custom-goto-parent ()
4640 "Go to the parent group listed at the top of this buffer.
4641 If several parents are listed, go to the first of them."
4642 (interactive)
4643 (save-excursion
4644 (goto-char (point-min))
4645 (if (search-forward "\nParent groups: " nil t)
4646 (let* ((button (get-char-property (point) 'button))
4647 (parent (downcase (widget-get button :tag))))
4648 (customize-group parent)))))
4650 (defcustom Custom-mode-hook nil
4651 "Hook called when entering Custom mode."
4652 :type 'hook
4653 :group 'custom-buffer)
4655 (defun custom-state-buffer-message (widget)
4656 (if (eq (widget-get (widget-get widget :parent) :custom-state) 'modified)
4657 (message "To install your edits, invoke [State] and choose the Set operation")))
4659 (define-derived-mode Custom-mode nil "Custom"
4660 "Major mode for editing customization buffers.
4662 The following commands are available:
4664 \\<widget-keymap>\
4665 Move to next button, link or editable field. \\[widget-forward]
4666 Move to previous button, link or editable field. \\[widget-backward]
4667 \\<custom-field-keymap>\
4668 Complete content of editable text field. \\[widget-complete]
4669 \\<custom-mode-map>\
4670 Invoke button under the mouse pointer. \\[widget-button-click]
4671 Invoke button under point. \\[widget-button-press]
4672 Set all options from current text. \\[Custom-set]
4673 Make values in current text permanent. \\[Custom-save]
4674 Make text match actual option values. \\[Custom-reset-current]
4675 Reset options to permanent settings. \\[Custom-reset-saved]
4676 Erase customizations; set options
4677 and buffer text to the standard values. \\[Custom-reset-standard]
4679 Entry to this mode calls the value of `Custom-mode-hook'
4680 if that value is non-nil."
4681 (use-local-map custom-mode-map)
4682 (easy-menu-add Custom-mode-menu)
4683 (set (make-local-variable 'tool-bar-map)
4684 (or custom-tool-bar-map
4685 ;; Set up `custom-tool-bar-map'.
4686 (let ((map (make-sparse-keymap)))
4687 (mapc
4688 (lambda (arg)
4689 (tool-bar-local-item-from-menu
4690 (nth 1 arg) (nth 4 arg) map custom-mode-map
4691 :label (nth 5 arg)))
4692 custom-commands)
4693 (setq custom-tool-bar-map map))))
4694 (make-local-variable 'custom-options)
4695 (make-local-variable 'custom-local-buffer)
4696 (make-local-variable 'widget-documentation-face)
4697 (setq widget-documentation-face 'custom-documentation)
4698 (make-local-variable 'widget-button-face)
4699 (setq widget-button-face custom-button)
4700 (setq show-trailing-whitespace nil)
4702 ;; We need this because of the "More" button on docstrings.
4703 ;; Otherwise clicking on "More" can push point offscreen, which
4704 ;; causes the window to recenter on point, which pushes the
4705 ;; newly-revealed docstring offscreen; which is annoying. -- cyd.
4706 (set (make-local-variable 'widget-button-click-moves-point) t)
4708 (set (make-local-variable 'widget-button-pressed-face) custom-button-pressed)
4709 (set (make-local-variable 'widget-mouse-face) custom-button-mouse)
4711 ;; When possible, use relief for buttons, not bracketing. This test
4712 ;; may not be optimal.
4713 (when custom-raised-buttons
4714 (set (make-local-variable 'widget-push-button-prefix) "")
4715 (set (make-local-variable 'widget-push-button-suffix) "")
4716 (set (make-local-variable 'widget-link-prefix) "")
4717 (set (make-local-variable 'widget-link-suffix) ""))
4718 (add-hook 'widget-edit-functions 'custom-state-buffer-message nil t))
4720 (put 'Custom-mode 'mode-class 'special)
4722 ;; backward-compatibility
4723 (defun custom-mode ()
4724 "Non-interactive variant of `Custom-mode'."
4725 (Custom-mode))
4726 (make-obsolete 'custom-mode 'Custom-mode "23.1")
4727 (put 'custom-mode 'mode-class 'special)
4728 (define-obsolete-variable-alias 'custom-mode-hook 'Custom-mode-hook "23.1")
4730 (dolist (regexp
4731 '("^No user option defaults have been changed since Emacs "
4732 "^Invalid face:? "
4733 "^No \\(?:customized\\|rogue\\|saved\\) user options"
4734 "^No customizable items matching "
4735 "^There are unset changes"
4736 "^Cannot set hidden variable"
4737 "^No \\(?:saved\\|backup\\) value for "
4738 "^No standard setting known for "
4739 "^No standard setting for this face"
4740 "^Saving settings from \"emacs -q\" would overwrite existing customizations"))
4741 (add-to-list 'debug-ignored-errors regexp))
4743 ;;; The End.
4745 (provide 'cus-edit)
4747 ;; arch-tag: 64533aa4-1b1a-48c3-8812-f9dc718e8a6f
4748 ;;; cus-edit.el ends here