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