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