*** empty log message ***
[emacs.git] / lisp / cus-edit.el
blobfe2780b0274c8896765bf50d2ed4689755fac0f1
1 ;;; cus-edit.el --- tools for customizing Emacs and Lisp packages
2 ;;
3 ;; Copyright (C) 1996, 1997, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005 Free Software Foundation, Inc.
5 ;;
6 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
7 ;; Maintainer: FSF
8 ;; Keywords: help, faces
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
27 ;;; Commentary:
29 ;; This file implements the code to create and edit customize buffers.
31 ;; See `custom.el'.
33 ;; No commands should have names starting with `custom-' because
34 ;; that interferes with completion. Use `customize-' for commands
35 ;; that the user will run with M-x, and `Custom-' for interactive commands.
37 ;; The identity of a customize option is represented by a Lisp symbol.
38 ;; The following values are associated with an option.
40 ;; 0. The current value.
42 ;; This is the value of the option as seen by "the rest of Emacs".
44 ;; Usually extracted by 'default-value', but can be extracted with
45 ;; different means if the option symbol has the 'custom-get'
46 ;; property. Similarly, set-default (or the 'custom-set' property)
47 ;; can set it.
49 ;; 1. The widget value.
51 ;; This is the value shown in the widget in a customize buffer.
53 ;; 2. The customized value.
55 ;; This is the last value given to the option through customize.
57 ;; It is stored in the 'customized-value' property of the option, in a
58 ;; cons-cell whose car evaluates to the customized value.
60 ;; 3. The saved value.
62 ;; This is last value saved from customize.
64 ;; It is stored in the 'saved-value' property of the option, in a
65 ;; cons-cell whose car evaluates to the saved value.
67 ;; 4. The standard value.
69 ;; This is the value given in the 'defcustom' declaration.
71 ;; It is stored in the 'standard-value' property of the option, in a
72 ;; cons-cell whose car evaluates to the standard value.
74 ;; 5. The "think" value.
76 ;; This is what customize thinks the current value should be.
78 ;; This is the customized value, if any such value exists, otherwise
79 ;; the saved value, if that exists, and as a last resort the standard
80 ;; value.
82 ;; The reason for storing values unevaluated: This is so you can have
83 ;; values that depend on the environment. For example, you can have a
84 ;; variable that has one value when Emacs is running under a window
85 ;; system, and another value on a tty. Since the evaluation is only done
86 ;; when the variable is first initialized, this is only relevant for the
87 ;; saved (and standard) values, but affect others values for
88 ;; compatibility.
90 ;; You can see (and modify and save) this unevaluated value by selecting
91 ;; "Show initial Lisp expression" from the Lisp interface. This will
92 ;; give you the unevaluated saved value, if any, otherwise the
93 ;; unevaluated standard value.
95 ;; The possible states for a customize widget are:
97 ;; 0. unknown
99 ;; The state has not been determined yet.
101 ;; 1. modified
103 ;; The widget value is different from the current value.
105 ;; 2. changed
107 ;; The current value is different from the "think" value.
109 ;; 3. set
111 ;; The "think" value is the customized value.
113 ;; 4. saved
115 ;; The "think" value is the saved value.
117 ;; 5. standard
119 ;; The "think" value is the standard value.
121 ;; 6. rogue
123 ;; There is no standard value. This means that the variable was
124 ;; not defined with defcustom, nor handled in cus-start.el. You
125 ;; can not create a Custom buffer for such variables using the
126 ;; normal interactive Custom commands. However, such Custom
127 ;; buffers can be created in other ways, for instance, 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)
143 (eval-when-compile
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 abbrev nil
171 "Abbreviation handling, typing shortcuts, macros."
172 :tag "Abbreviations"
173 :group 'editing)
175 (defgroup matching nil
176 "Various sorts of searching and matching."
177 :group 'editing)
179 (defgroup emulations nil
180 "Emulations of other editors."
181 :link '(custom-manual "(emacs)Emulation")
182 :group 'editing)
184 (defgroup mouse nil
185 "Mouse support."
186 :group 'editing)
188 (defgroup outlines nil
189 "Support for hierarchical outlining."
190 :group 'editing)
192 (defgroup external nil
193 "Interfacing to external utilities."
194 :group 'emacs)
196 (defgroup processes nil
197 "Process, subshell, compilation, and job control support."
198 :group 'external
199 :group 'development)
201 (defgroup convenience nil
202 "Convenience features for faster editing."
203 :group 'emacs)
205 (defgroup programming nil
206 "Support for programming in other languages."
207 :group 'emacs)
209 (defgroup languages nil
210 "Specialized modes for editing programming languages."
211 :group 'programming)
213 (defgroup lisp nil
214 "Lisp support, including Emacs Lisp."
215 :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
216 :group 'languages
217 :group 'development)
219 (defgroup c nil
220 "Support for the C language and related languages."
221 :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
222 :link '(custom-manual "(ccmode)")
223 :group 'languages)
225 (defgroup tools nil
226 "Programming tools."
227 :group 'programming)
229 (defgroup oop nil
230 "Support for object-oriented programming."
231 :group 'programming)
233 (defgroup applications nil
234 "Applications written in Emacs."
235 :group 'emacs)
237 (defgroup calendar nil
238 "Calendar and time management support."
239 :group 'applications)
241 (defgroup mail nil
242 "Modes for electronic-mail handling."
243 :group 'applications)
245 (defgroup news nil
246 "Support for netnews reading and posting."
247 :link '(custom-manual "(gnus)")
248 :group 'applications)
250 (defgroup games nil
251 "Games, jokes and amusements."
252 :group 'applications)
254 (defgroup development nil
255 "Support for further development of Emacs."
256 :group 'emacs)
258 (defgroup docs nil
259 "Support for Emacs documentation."
260 :group 'development)
262 (defgroup extensions nil
263 "Emacs Lisp language extensions."
264 :group 'development)
266 (defgroup internal nil
267 "Code for Emacs internals, build process, defaults."
268 :group 'development)
270 (defgroup maint nil
271 "Maintenance aids for the Emacs development group."
272 :tag "Maintenance"
273 :group 'development)
275 (defgroup environment nil
276 "Fitting Emacs with its environment."
277 :group 'emacs)
279 (defgroup comm nil
280 "Communications, networking, remote access to files."
281 :tag "Communication"
282 :group 'environment)
284 (defgroup hardware nil
285 "Support for interfacing with exotic hardware."
286 :group 'environment)
288 (defgroup terminals nil
289 "Support for terminal types."
290 :group 'environment)
292 (defgroup unix nil
293 "Front-ends/assistants for, or emulators of, UNIX features."
294 :group 'environment)
296 (defgroup vms nil
297 "Support code for vms."
298 :group 'environment)
300 (defgroup i18n nil
301 "Internationalization and alternate character-set support."
302 :link '(custom-manual "(emacs)International")
303 :group 'environment
304 :group 'editing)
306 (defgroup x nil
307 "The X Window system."
308 :group 'environment)
310 (defgroup frames nil
311 "Support for Emacs frames and window systems."
312 :group 'environment)
314 (defgroup data nil
315 "Support editing files of data."
316 :group 'emacs)
318 (defgroup files nil
319 "Support editing files."
320 :group 'emacs)
322 (defgroup wp nil
323 "Word processing."
324 :group 'emacs)
326 (defgroup tex nil
327 "Code related to the TeX formatter."
328 :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
329 :group 'wp)
331 (defgroup faces nil
332 "Support for multiple fonts."
333 :group 'emacs)
335 (defgroup hypermedia nil
336 "Support for links between text or other media types."
337 :group 'emacs)
339 (defgroup help nil
340 "Support for on-line help systems."
341 :group 'emacs)
343 (defgroup multimedia nil
344 "Non-textual support, specifically images and sound."
345 :group 'emacs)
347 (defgroup local nil
348 "Code local to your site."
349 :group 'emacs)
351 (defgroup customize '((widgets custom-group))
352 "Customization of the Customization support."
353 :prefix "custom-"
354 :group 'help)
356 (defgroup custom-faces nil
357 "Faces used by customize."
358 :group 'customize
359 :group 'faces)
361 (defgroup custom-browse nil
362 "Control customize browser."
363 :prefix "custom-"
364 :group 'customize)
366 (defgroup custom-buffer nil
367 "Control customize buffers."
368 :prefix "custom-"
369 :group 'customize)
371 (defgroup custom-menu nil
372 "Control customize menus."
373 :prefix "custom-"
374 :group 'customize)
376 (defgroup abbrev-mode nil
377 "Word abbreviations mode."
378 :link '(custom-manual "(emacs)Abbrevs")
379 :group 'abbrev)
381 (defgroup alloc nil
382 "Storage allocation and gc for GNU Emacs Lisp interpreter."
383 :tag "Storage Allocation"
384 :group 'internal)
386 (defgroup undo nil
387 "Undoing changes in buffers."
388 :link '(custom-manual "(emacs)Undo")
389 :group 'editing)
391 (defgroup modeline nil
392 "Content of the modeline."
393 :group 'environment)
395 (defgroup editing-basics nil
396 "Most basic editing facilities."
397 :group 'editing)
399 (defgroup display nil
400 "How characters are displayed in buffers."
401 :group 'environment)
403 (defgroup execute nil
404 "Executing external commands."
405 :group 'processes)
407 (defgroup installation nil
408 "The Emacs installation."
409 :group 'environment)
411 (defgroup dired nil
412 "Directory editing."
413 :group 'environment)
415 (defgroup limits nil
416 "Internal Emacs limits."
417 :group 'internal)
419 (defgroup debug nil
420 "Debugging Emacs itself."
421 :group 'development)
423 (defgroup minibuffer nil
424 "Controling the behavior of the minibuffer."
425 :link '(custom-manual "(emacs)Minibuffer")
426 :group 'environment)
428 (defgroup keyboard nil
429 "Input from the keyboard."
430 :group 'environment)
432 (defgroup mouse nil
433 "Input from the mouse."
434 :group 'environment)
436 (defgroup menu nil
437 "Input from the menus."
438 :group 'environment)
440 (defgroup dnd nil
441 "Handling data from drag and drop."
442 :group 'environment)
444 (defgroup auto-save nil
445 "Preventing accidential loss of data."
446 :group 'files)
448 (defgroup processes-basics nil
449 "Basic stuff dealing with processes."
450 :group 'processes)
452 (defgroup mule nil
453 "MULE Emacs internationalization."
454 :group 'i18n)
456 (defgroup windows nil
457 "Windows within a frame."
458 :link '(custom-manual "(emacs)Windows")
459 :group 'environment)
461 ;;; Utilities.
463 (defun custom-quote (sexp)
464 "Quote SEXP iff it is not self quoting."
465 (if (or (memq sexp '(t nil))
466 (keywordp sexp)
467 (and (listp sexp)
468 (memq (car sexp) '(lambda)))
469 (stringp sexp)
470 (numberp sexp)
471 (vectorp sexp)
472 ;;; (and (fboundp 'characterp)
473 ;;; (characterp sexp))
475 sexp
476 (list 'quote sexp)))
478 (defun custom-split-regexp-maybe (regexp)
479 "If REGEXP is a string, split it to a list at `\\|'.
480 You can get the original back with from the result with:
481 (mapconcat 'identity result \"\\|\")
483 IF REGEXP is not a string, return it unchanged."
484 (if (stringp regexp)
485 (let ((start 0)
486 all)
487 (while (string-match "\\\\|" regexp start)
488 (setq all (cons (substring regexp start (match-beginning 0)) all)
489 start (match-end 0)))
490 (nreverse (cons (substring regexp start) all)))
491 regexp))
493 (defun custom-variable-prompt ()
494 "Prompt for a custom variable, defaulting to the variable at point.
495 Return a list suitable for use in `interactive'."
496 (let* ((v (variable-at-point))
497 (default (and (symbolp v) (custom-variable-p v) (symbol-name v)))
498 (enable-recursive-minibuffers t)
499 val)
500 (setq val (completing-read
501 (if default (format "Customize option (default %s): " default)
502 "Customize option: ")
503 obarray 'custom-variable-p t nil nil default))
504 (list (if (equal val "")
505 (if (symbolp v) v nil)
506 (intern val)))))
508 (defun custom-menu-filter (menu widget)
509 "Convert MENU to the form used by `widget-choose'.
510 MENU should be in the same format as `custom-variable-menu'.
511 WIDGET is the widget to apply the filter entries of MENU on."
512 (let ((result nil)
513 current name action filter)
514 (while menu
515 (setq current (car menu)
516 name (nth 0 current)
517 action (nth 1 current)
518 filter (nth 2 current)
519 menu (cdr menu))
520 (if (or (null filter) (funcall filter widget))
521 (push (cons name action) result)
522 (push name result)))
523 (nreverse result)))
525 ;;; Unlispify.
527 (defvar custom-prefix-list nil
528 "List of prefixes that should be ignored by `custom-unlispify'.")
530 (defcustom custom-unlispify-menu-entries t
531 "Display menu entries as words instead of symbols if non nil."
532 :group 'custom-menu
533 :type 'boolean)
535 (defcustom custom-unlispify-remove-prefixes nil
536 "Non-nil means remove group prefixes from option names in buffer."
537 :group 'custom-menu
538 :group 'custom-buffer
539 :type 'boolean)
541 (defun custom-unlispify-menu-entry (symbol &optional no-suffix)
542 "Convert SYMBOL into a menu entry."
543 (cond ((not custom-unlispify-menu-entries)
544 (symbol-name symbol))
545 ((get symbol 'custom-tag)
546 (if no-suffix
547 (get symbol 'custom-tag)
548 (concat (get symbol 'custom-tag) "...")))
550 (with-current-buffer (get-buffer-create " *Custom-Work*")
551 (erase-buffer)
552 (princ symbol (current-buffer))
553 (goto-char (point-min))
554 ;; FIXME: Boolean variables are not predicates, so they shouldn't
555 ;; end with `-p'. -stef
556 ;; (when (and (eq (get symbol 'custom-type) 'boolean)
557 ;; (re-search-forward "-p\\'" nil t))
558 ;; (replace-match "" t t)
559 ;; (goto-char (point-min)))
560 (if custom-unlispify-remove-prefixes
561 (let ((prefixes custom-prefix-list)
562 prefix)
563 (while prefixes
564 (setq prefix (car prefixes))
565 (if (search-forward prefix (+ (point) (length prefix)) t)
566 (progn
567 (setq prefixes nil)
568 (delete-region (point-min) (point)))
569 (setq prefixes (cdr prefixes))))))
570 (subst-char-in-region (point-min) (point-max) ?- ?\ t)
571 (capitalize-region (point-min) (point-max))
572 (unless no-suffix
573 (goto-char (point-max))
574 (insert "..."))
575 (buffer-string)))))
577 (defcustom custom-unlispify-tag-names t
578 "Display tag names as words instead of symbols if non nil."
579 :group 'custom-buffer
580 :type 'boolean)
582 (defun custom-unlispify-tag-name (symbol)
583 "Convert SYMBOL into a menu entry."
584 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names))
585 (custom-unlispify-menu-entry symbol t)))
587 (defun custom-prefix-add (symbol prefixes)
588 "Add SYMBOL to list of ignored PREFIXES."
589 (cons (or (get symbol 'custom-prefix)
590 (concat (symbol-name symbol) "-"))
591 prefixes))
593 ;;; Guess.
595 (defcustom custom-guess-name-alist
596 '(("-p\\'" boolean)
597 ("-hook\\'" hook)
598 ("-face\\'" face)
599 ("-file\\'" file)
600 ("-function\\'" function)
601 ("-functions\\'" (repeat function))
602 ("-list\\'" (repeat sexp))
603 ("-alist\\'" (repeat (cons sexp sexp))))
604 "Alist of (MATCH TYPE).
606 MATCH should be a regexp matching the name of a symbol, and TYPE should
607 be a widget suitable for editing the value of that symbol. The TYPE
608 of the first entry where MATCH matches the name of the symbol will be
609 used.
611 This is used for guessing the type of variables not declared with
612 customize."
613 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
614 :group 'customize)
616 (defcustom custom-guess-doc-alist
617 '(("\\`\\*?Non-nil " boolean))
618 "Alist of (MATCH TYPE).
620 MATCH should be a regexp matching a documentation string, and TYPE
621 should be a widget suitable for editing the value of a variable with
622 that documentation string. The TYPE of the first entry where MATCH
623 matches the name of the symbol will be used.
625 This is used for guessing the type of variables not declared with
626 customize."
627 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
628 :group 'customize)
630 (defun custom-guess-type (symbol)
631 "Guess a widget suitable for editing the value of SYMBOL.
632 This is done by matching SYMBOL with `custom-guess-name-alist' and
633 if that fails, the doc string with `custom-guess-doc-alist'."
634 (let ((name (symbol-name symbol))
635 (names custom-guess-name-alist)
636 current found)
637 (while names
638 (setq current (car names)
639 names (cdr names))
640 (when (string-match (nth 0 current) name)
641 (setq found (nth 1 current)
642 names nil)))
643 (unless found
644 (let ((doc (documentation-property symbol 'variable-documentation))
645 (docs custom-guess-doc-alist))
646 (when doc
647 (while docs
648 (setq current (car docs)
649 docs (cdr docs))
650 (when (string-match (nth 0 current) doc)
651 (setq found (nth 1 current)
652 docs nil))))))
653 found))
655 ;;; Sorting.
657 (defcustom custom-browse-sort-alphabetically nil
658 "If non-nil, sort members of each customization group alphabetically."
659 :type 'boolean
660 :group 'custom-browse)
662 (defcustom custom-browse-order-groups nil
663 "If non-nil, order group members within each customization group.
664 If `first', order groups before non-groups.
665 If `last', order groups after non-groups."
666 :type '(choice (const first)
667 (const last)
668 (const :tag "none" nil))
669 :group 'custom-browse)
671 (defcustom custom-browse-only-groups nil
672 "If non-nil, show group members only within each customization group."
673 :type 'boolean
674 :group 'custom-browse)
676 (defcustom custom-buffer-sort-alphabetically nil
677 "If non-nil, sort members of each customization group alphabetically."
678 :type 'boolean
679 :group 'custom-buffer)
681 (defcustom custom-buffer-order-groups 'last
682 "If non-nil, order group members within each customization group.
683 If `first', order groups before non-groups.
684 If `last', order groups after non-groups."
685 :type '(choice (const first)
686 (const last)
687 (const :tag "none" nil))
688 :group 'custom-buffer)
690 (defcustom custom-menu-sort-alphabetically nil
691 "If non-nil, sort members of each customization group alphabetically."
692 :type 'boolean
693 :group 'custom-menu)
695 (defcustom custom-menu-order-groups 'first
696 "If non-nil, order group members within each customization group.
697 If `first', order groups before non-groups.
698 If `last', order groups after non-groups."
699 :type '(choice (const first)
700 (const last)
701 (const :tag "none" nil))
702 :group 'custom-menu)
704 ;;;###autoload (add-hook 'same-window-regexps "\\`\\*Customiz.*\\*\\'")
706 (defun custom-sort-items (items sort-alphabetically order-groups)
707 "Return a sorted copy of ITEMS.
708 ITEMS should be a `custom-group' property.
709 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
710 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
711 groups after non-groups, if nil do not order groups at all."
712 (sort (copy-sequence items)
713 (lambda (a b)
714 (let ((typea (nth 1 a)) (typeb (nth 1 b))
715 (namea (nth 0 a)) (nameb (nth 0 b)))
716 (cond ((not order-groups)
717 ;; Since we don't care about A and B order, maybe sort.
718 (when sort-alphabetically
719 (string-lessp namea nameb)))
720 ((eq typea 'custom-group)
721 ;; If B is also a group, maybe sort. Otherwise, order A and B.
722 (if (eq typeb 'custom-group)
723 (when sort-alphabetically
724 (string-lessp namea nameb))
725 (eq order-groups 'first)))
726 ((eq typeb 'custom-group)
727 ;; Since A cannot be a group, order A and B.
728 (eq order-groups 'last))
729 (sort-alphabetically
730 ;; Since A and B cannot be groups, sort.
731 (string-lessp namea nameb)))))))
733 ;;; Custom Mode Commands.
735 (defvar custom-options nil
736 "Customization widgets in the current buffer.")
738 (defun Custom-set ()
739 "Set changes in all modified options."
740 (interactive)
741 (let ((children custom-options))
742 (mapc (lambda (child)
743 (when (eq (widget-get child :custom-state) 'modified)
744 (widget-apply child :custom-set)))
745 children)))
747 (defun Custom-save ()
748 "Set all modified group members and save them."
749 (interactive)
750 (let ((children custom-options))
751 (mapc (lambda (child)
752 (when (memq (widget-get child :custom-state)
753 '(modified set changed rogue))
754 (widget-apply child :custom-save)))
755 children))
756 (custom-save-all))
758 (defvar custom-reset-menu
759 '(("Current" . Custom-reset-current)
760 ("Saved" . Custom-reset-saved)
761 ("Erase Customization (use standard settings)" . Custom-reset-standard))
762 "Alist of actions for the `Reset' button.
763 The key is a string containing the name of the action, the value is a
764 Lisp function taking the widget as an element which will be called
765 when the action is chosen.")
767 (defun custom-reset (event)
768 "Select item from reset menu."
769 (let* ((completion-ignore-case t)
770 (answer (widget-choose "Reset to"
771 custom-reset-menu
772 event)))
773 (if answer
774 (funcall answer))))
776 (defun Custom-reset-current (&rest ignore)
777 "Reset all modified group members to their current value."
778 (interactive)
779 (let ((children custom-options))
780 (mapc (lambda (widget)
781 (if (memq (widget-get widget :custom-state)
782 '(modified changed))
783 (widget-apply widget :custom-reset-current)))
784 children)))
786 (defun Custom-reset-saved (&rest ignore)
787 "Reset all modified or set group members to their saved value."
788 (interactive)
789 (let ((children custom-options))
790 (mapc (lambda (widget)
791 (if (memq (widget-get widget :custom-state)
792 '(modified set changed rogue))
793 (widget-apply widget :custom-reset-saved)))
794 children)))
796 (defun Custom-reset-standard (&rest ignore)
797 "Erase all customization (either current or saved) for the group members.
798 The immediate result is to restore them to their standard settings.
799 This operation eliminates any saved settings for the group members,
800 making them as if they had never been customized at all."
801 (interactive)
802 (let ((children custom-options))
803 (when (or (and (= 1 (length children))
804 (memq (widget-type (car children))
805 '(custom-variable custom-face)))
806 (yes-or-no-p "Really erase all customizations in this buffer? "))
807 (mapc (lambda (widget)
808 (and (if (widget-get widget :custom-standard-value)
809 (widget-apply widget :custom-standard-value)
811 (memq (widget-get widget :custom-state)
812 '(modified set changed saved rogue))
813 (widget-apply widget :custom-reset-standard)))
814 children))))
816 ;;; The Customize Commands
818 (defun custom-prompt-variable (prompt-var prompt-val &optional comment)
819 "Prompt for a variable and a value and return them as a list.
820 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
821 prompt for the value. The %s escape in PROMPT-VAL is replaced with
822 the name of the variable.
824 If the variable has a `variable-interactive' property, that is used as if
825 it were the arg to `interactive' (which see) to interactively read the value.
827 If the variable has a `custom-type' property, it must be a widget and the
828 `:prompt-value' property of that widget will be used for reading the value.
830 If optional COMMENT argument is non nil, also prompt for a comment and return
831 it as the third element in the list."
832 (let* ((var (read-variable prompt-var))
833 (minibuffer-help-form '(describe-variable var))
834 (val
835 (let ((prop (get var 'variable-interactive))
836 (type (get var 'custom-type))
837 (prompt (format prompt-val var)))
838 (unless (listp type)
839 (setq type (list type)))
840 (cond (prop
841 ;; Use VAR's `variable-interactive' property
842 ;; as an interactive spec for prompting.
843 (call-interactively (list 'lambda '(arg)
844 (list 'interactive prop)
845 'arg)))
846 (type
847 (widget-prompt-value type
848 prompt
849 (if (boundp var)
850 (symbol-value var))
851 (not (boundp var))))
853 (eval-minibuffer prompt))))))
854 (if comment
855 (list var val
856 (read-string "Comment: " (get var 'variable-comment)))
857 (list var val))))
859 ;;;###autoload
860 (defun customize-set-value (variable value &optional comment)
861 "Set VARIABLE to VALUE, and return VALUE. VALUE is a Lisp object.
863 If VARIABLE has a `variable-interactive' property, that is used as if
864 it were the arg to `interactive' (which see) to interactively read the value.
866 If VARIABLE has a `custom-type' property, it must be a widget and the
867 `:prompt-value' property of that widget will be used for reading the value.
869 If given a prefix (or a COMMENT argument), also prompt for a comment."
870 (interactive (custom-prompt-variable "Set variable: "
871 "Set %s to value: "
872 current-prefix-arg))
874 (cond ((string= comment "")
875 (put variable 'variable-comment nil))
876 (comment
877 (put variable 'variable-comment comment)))
878 (set variable value))
880 ;;;###autoload
881 (defun customize-set-variable (variable value &optional comment)
882 "Set the default for VARIABLE to VALUE, and return VALUE.
883 VALUE is a Lisp object.
885 If VARIABLE has a `custom-set' property, that is used for setting
886 VARIABLE, otherwise `set-default' is used.
888 The `customized-value' property of the VARIABLE will be set to a list
889 with a quoted VALUE as its sole list member.
891 If VARIABLE has a `variable-interactive' property, that is used as if
892 it were the arg to `interactive' (which see) to interactively read the value.
894 If VARIABLE has a `custom-type' property, it must be a widget and the
895 `:prompt-value' property of that widget will be used for reading the value.
897 If given a prefix (or a COMMENT argument), also prompt for a comment."
898 (interactive (custom-prompt-variable "Set variable: "
899 "Set customized value for %s to: "
900 current-prefix-arg))
901 (custom-load-symbol variable)
902 (funcall (or (get variable 'custom-set) 'set-default) variable value)
903 (put variable 'customized-value (list (custom-quote value)))
904 (cond ((string= comment "")
905 (put variable 'variable-comment nil)
906 (put variable 'customized-variable-comment nil))
907 (comment
908 (put variable 'variable-comment comment)
909 (put variable 'customized-variable-comment comment)))
910 value)
912 ;;;###autoload
913 (defun customize-save-variable (variable value &optional comment)
914 "Set the default for VARIABLE to VALUE, and save it for future sessions.
915 Return VALUE.
917 If VARIABLE has a `custom-set' property, that is used for setting
918 VARIABLE, otherwise `set-default' is used.
920 The `customized-value' property of the VARIABLE will be set to a list
921 with a quoted VALUE as its sole list member.
923 If VARIABLE has a `variable-interactive' property, that is used as if
924 it were the arg to `interactive' (which see) to interactively read the value.
926 If VARIABLE has a `custom-type' property, it must be a widget and the
927 `:prompt-value' property of that widget will be used for reading the value.
929 If given a prefix (or a COMMENT argument), also prompt for a comment."
930 (interactive (custom-prompt-variable "Set and save variable: "
931 "Set and save value for %s as: "
932 current-prefix-arg))
933 (funcall (or (get variable 'custom-set) 'set-default) variable value)
934 (put variable 'saved-value (list (custom-quote value)))
935 (custom-push-theme 'theme-value variable 'user 'set (list (custom-quote value)))
936 (cond ((string= comment "")
937 (put variable 'variable-comment nil)
938 (put variable 'saved-variable-comment nil))
939 (comment
940 (put variable 'variable-comment comment)
941 (put variable 'saved-variable-comment comment)))
942 (custom-save-all)
943 value)
945 ;;;###autoload
946 (defun customize ()
947 "Select a customization buffer which you can use to set user options.
948 User options are structured into \"groups\".
949 Initially the top-level group `Emacs' and its immediate subgroups
950 are shown; the contents of those subgroups are initially hidden."
951 (interactive)
952 (customize-group 'emacs))
954 ;;;###autoload
955 (defun customize-mode (mode)
956 "Customize options related to the current major mode.
957 If a prefix \\[universal-argument] was given (or if the current major mode has no known group),
958 then prompt for the MODE to customize."
959 (interactive
960 (list
961 (let ((completion-regexp-list '("-mode\\'"))
962 (group (custom-group-of-mode major-mode)))
963 (if (and group (not current-prefix-arg))
964 major-mode
965 (intern
966 (completing-read (if group
967 (format "Major mode (default %s): " major-mode)
968 "Major mode: ")
969 obarray
970 'custom-group-of-mode
971 t nil nil (if group (symbol-name major-mode))))))))
972 (customize-group (custom-group-of-mode mode)))
975 ;;;###autoload
976 (defun customize-group (group)
977 "Customize GROUP, which must be a customization group."
978 (interactive
979 (list (let ((completion-ignore-case t))
980 (completing-read "Customize group (default emacs): "
981 obarray
982 (lambda (symbol)
983 (or (and (get symbol 'custom-loads)
984 (not (get symbol 'custom-autoload)))
985 (get symbol 'custom-group)))
986 t))))
987 (when (stringp group)
988 (if (string-equal "" group)
989 (setq group 'emacs)
990 (setq group (intern group))))
991 (let ((name (format "*Customize Group: %s*"
992 (custom-unlispify-tag-name group))))
993 (if (get-buffer name)
994 (pop-to-buffer name)
995 (custom-buffer-create (list (list group 'custom-group))
996 name
997 (concat " for group "
998 (custom-unlispify-tag-name group))))))
1000 ;;;###autoload
1001 (defun customize-group-other-window (group)
1002 "Customize GROUP, which must be a customization group."
1003 (interactive
1004 (list (let ((completion-ignore-case t))
1005 (completing-read "Customize group (default emacs): "
1006 obarray
1007 (lambda (symbol)
1008 (or (and (get symbol 'custom-loads)
1009 (not (get symbol 'custom-autoload)))
1010 (get symbol 'custom-group)))
1011 t))))
1012 (when (stringp group)
1013 (if (string-equal "" group)
1014 (setq group 'emacs)
1015 (setq group (intern group))))
1016 (let ((name (format "*Customize Group: %s*"
1017 (custom-unlispify-tag-name group))))
1018 (if (get-buffer name)
1019 (let (
1020 ;; Copied from `custom-buffer-create-other-window'.
1021 (pop-up-windows t)
1022 (same-window-buffer-names nil)
1023 (same-window-regexps nil))
1024 (pop-to-buffer name))
1025 (custom-buffer-create-other-window
1026 (list (list group 'custom-group))
1027 name
1028 (concat " for group "
1029 (custom-unlispify-tag-name group))))))
1031 ;;;###autoload
1032 (defalias 'customize-variable 'customize-option)
1034 ;;;###autoload
1035 (defun customize-option (symbol)
1036 "Customize SYMBOL, which must be a user option variable."
1037 (interactive (custom-variable-prompt))
1038 (let ((basevar (indirect-variable symbol)))
1039 (custom-buffer-create (list (list basevar 'custom-variable))
1040 (format "*Customize Option: %s*"
1041 (custom-unlispify-tag-name basevar)))
1042 (unless (eq symbol basevar)
1043 (message "`%s' is an alias for `%s'" symbol basevar))))
1045 ;;;###autoload
1046 (defalias 'customize-variable-other-window 'customize-option-other-window)
1048 ;;;###autoload
1049 (defun customize-option-other-window (symbol)
1050 "Customize SYMBOL, which must be a user option variable.
1051 Show the buffer in another window, but don't select it."
1052 (interactive (custom-variable-prompt))
1053 (let ((basevar (indirect-variable symbol)))
1054 (custom-buffer-create-other-window
1055 (list (list basevar 'custom-variable))
1056 (format "*Customize Option: %s*" (custom-unlispify-tag-name basevar)))
1057 (unless (eq symbol basevar)
1058 (message "`%s' is an alias for `%s'" symbol basevar))))
1060 (defvar customize-changed-options-previous-release "20.2"
1061 "Version for `customize-changed-options' to refer back to by default.")
1063 ;;;###autoload
1064 (defun customize-changed-options (since-version)
1065 "Customize all user option variables changed in Emacs itself.
1066 This includes new user option variables and faces, and new
1067 customization groups, as well as older options and faces whose default
1068 values have changed since the previous major Emacs release.
1070 With argument SINCE-VERSION (a string), customize all user option
1071 variables that were added (or their meanings were changed) since that
1072 version."
1074 (interactive "sCustomize options changed, since version (default all versions): ")
1075 (if (equal since-version "")
1076 (setq since-version nil)
1077 (unless (condition-case nil
1078 (numberp (read since-version))
1079 (error nil))
1080 (signal 'wrong-type-argument (list 'numberp since-version))))
1081 (unless since-version
1082 (setq since-version customize-changed-options-previous-release))
1084 ;; Load the information for versions since since-version. We use
1085 ;; custom-load-symbol for this.
1086 (put 'custom-versions-load-alist 'custom-loads nil)
1087 (dolist (elt custom-versions-load-alist)
1088 (if (customize-version-lessp since-version (car elt))
1089 (dolist (load (cdr elt))
1090 (custom-add-load 'custom-versions-load-alist load))))
1091 (custom-load-symbol 'custom-versions-load-alist)
1092 (put 'custom-versions-load-alist 'custom-loads nil)
1094 (let (found)
1095 (mapatoms
1096 (lambda (symbol)
1097 (let ((version (get symbol 'custom-version)))
1098 (if version
1099 (when (customize-version-lessp since-version version)
1100 (if (or (get symbol 'custom-group)
1101 (get symbol 'group-documentation))
1102 (push (list symbol 'custom-group) found))
1103 (if (custom-variable-p symbol)
1104 (push (list symbol 'custom-variable) found))
1105 (if (custom-facep symbol)
1106 (push (list symbol 'custom-face) found)))))))
1107 (if found
1108 (custom-buffer-create (custom-sort-items found t 'first)
1109 "*Customize Changed Options*")
1110 (error "No user option defaults have been changed since Emacs %s"
1111 since-version))))
1113 (defun customize-version-lessp (version1 version2)
1114 ;; Why are the versions strings, and given that they are, why aren't
1115 ;; they converted to numbers and compared as such here? -- fx
1117 ;; In case someone made a mistake and left out the quotes
1118 ;; in the :version value.
1119 (if (numberp version2)
1120 (setq version2 (prin1-to-string version2)))
1121 (let (major1 major2 minor1 minor2)
1122 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version1)
1123 (setq major1 (read (or (match-string 1 version1)
1124 "0")))
1125 (setq minor1 (read (or (match-string 3 version1)
1126 "0")))
1127 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version2)
1128 (setq major2 (read (or (match-string 1 version2)
1129 "0")))
1130 (setq minor2 (read (or (match-string 3 version2)
1131 "0")))
1132 (or (< major1 major2)
1133 (and (= major1 major2)
1134 (< minor1 minor2)))))
1136 ;;;###autoload
1137 (defun customize-face (&optional face)
1138 "Customize FACE, which should be a face name or nil.
1139 If FACE is nil, customize all faces. If FACE is actually a
1140 face-alias, customize the face it is aliased to.
1142 Interactively, when point is on text which has a face specified,
1143 suggest to customize that face, if it's customizable."
1144 (interactive
1145 (list (read-face-name "Customize face" "all faces" t)))
1146 (if (member face '(nil ""))
1147 (setq face (face-list)))
1148 (if (and (listp face) (null (cdr face)))
1149 (setq face (car face)))
1150 (if (listp face)
1151 (custom-buffer-create (custom-sort-items
1152 (mapcar (lambda (s)
1153 (list s 'custom-face))
1154 face)
1155 t nil)
1156 "*Customize Faces*")
1157 ;; If FACE is actually an alias, customize the face it is aliased to.
1158 (if (get face 'face-alias)
1159 (setq face (get face 'face-alias)))
1160 (unless (facep face)
1161 (error "Invalid face %S" face))
1162 (custom-buffer-create (list (list face 'custom-face))
1163 (format "*Customize Face: %s*"
1164 (custom-unlispify-tag-name face)))))
1166 ;;;###autoload
1167 (defun customize-face-other-window (&optional face)
1168 "Show customization buffer for face FACE in other window.
1169 If FACE is actually a face-alias, customize the face it is aliased to.
1171 Interactively, when point is on text which has a face specified,
1172 suggest to customize that face, if it's customizable."
1173 (interactive
1174 (list (read-face-name "Customize face" "all faces" t)))
1175 (if (member face '(nil ""))
1176 (setq face (face-list)))
1177 (if (and (listp face) (null (cdr face)))
1178 (setq face (car face)))
1179 (if (listp face)
1180 (custom-buffer-create-other-window
1181 (custom-sort-items
1182 (mapcar (lambda (s)
1183 (list s 'custom-face))
1184 face)
1185 t nil)
1186 "*Customize Faces*")
1187 (if (get face 'face-alias)
1188 (setq face (get face 'face-alias)))
1189 (unless (facep face)
1190 (error "Invalid face %S" face))
1191 (custom-buffer-create-other-window
1192 (list (list face 'custom-face))
1193 (format "*Customize Face: %s*"
1194 (custom-unlispify-tag-name face)))))
1196 ;;;###autoload
1197 (defun customize-customized ()
1198 "Customize all user options set since the last save in this session."
1199 (interactive)
1200 (let ((found nil))
1201 (mapatoms (lambda (symbol)
1202 (and (or (get symbol 'customized-face)
1203 (get symbol 'customized-face-comment))
1204 (custom-facep symbol)
1205 (push (list symbol 'custom-face) found))
1206 (and (or (get symbol 'customized-value)
1207 (get symbol 'customized-variable-comment))
1208 (boundp symbol)
1209 (push (list symbol 'custom-variable) found))))
1210 (if (not found)
1211 (error "No customized user options")
1212 (custom-buffer-create (custom-sort-items found t nil)
1213 "*Customize Customized*"))))
1215 ;;;###autoload
1216 (defun customize-rogue ()
1217 "Customize all user variable modified outside customize."
1218 (interactive)
1219 (let ((found nil))
1220 (mapatoms (lambda (symbol)
1221 (let ((cval (or (get symbol 'customized-value)
1222 (get symbol 'saved-value)
1223 (get symbol 'standard-value))))
1224 (when (and cval ;Declared with defcustom.
1225 (default-boundp symbol) ;Has a value.
1226 (not (equal (eval (car cval))
1227 ;; Which does not match customize.
1228 (default-value symbol))))
1229 (push (list symbol 'custom-variable) found)))))
1230 (if (not found)
1231 (error "No rogue user options")
1232 (custom-buffer-create (custom-sort-items found t nil)
1233 "*Customize Rogue*"))))
1234 ;;;###autoload
1235 (defun customize-saved ()
1236 "Customize all already saved user options."
1237 (interactive)
1238 (let ((found nil))
1239 (mapatoms (lambda (symbol)
1240 (and (or (get symbol 'saved-face)
1241 (get symbol 'saved-face-comment))
1242 (custom-facep symbol)
1243 (push (list symbol 'custom-face) found))
1244 (and (or (get symbol 'saved-value)
1245 (get symbol 'saved-variable-comment))
1246 (boundp symbol)
1247 (push (list symbol 'custom-variable) found))))
1248 (if (not found )
1249 (error "No saved user options")
1250 (custom-buffer-create (custom-sort-items found t nil)
1251 "*Customize Saved*"))))
1253 ;;;###autoload
1254 (defun customize-apropos (regexp &optional all)
1255 "Customize all loaded options, faces and groups matching REGEXP.
1256 If ALL is `options', include only options.
1257 If ALL is `faces', include only faces.
1258 If ALL is `groups', include only groups.
1259 If ALL is t (interactively, with prefix arg), include variables
1260 that are not customizable options, as well as faces and groups."
1261 (interactive "sCustomize regexp: \nP")
1262 (let ((found nil))
1263 (mapatoms (lambda (symbol)
1264 (when (string-match regexp (symbol-name symbol))
1265 (when (and (not (memq all '(faces options)))
1266 (get symbol 'custom-group))
1267 (push (list symbol 'custom-group) found))
1268 (when (and (not (memq all '(options groups)))
1269 (custom-facep symbol))
1270 (push (list symbol 'custom-face) found))
1271 (when (and (not (memq all '(groups faces)))
1272 (boundp symbol)
1273 (eq (indirect-variable symbol) symbol)
1274 (or (get symbol 'saved-value)
1275 (custom-variable-p symbol)
1276 (and (not (memq all '(nil options)))
1277 (get symbol 'variable-documentation))))
1278 (push (list symbol 'custom-variable) found)))))
1279 (if (not found)
1280 (error "No matches")
1281 (custom-buffer-create (custom-sort-items found t
1282 custom-buffer-order-groups)
1283 "*Customize Apropos*"))))
1285 ;;;###autoload
1286 (defun customize-apropos-options (regexp &optional arg)
1287 "Customize all loaded customizable options matching REGEXP.
1288 With prefix arg, include variables that are not customizable options."
1289 (interactive "sCustomize regexp: \nP")
1290 (customize-apropos regexp (or arg 'options)))
1292 ;;;###autoload
1293 (defun customize-apropos-faces (regexp)
1294 "Customize all loaded faces matching REGEXP."
1295 (interactive "sCustomize regexp: \n")
1296 (customize-apropos regexp 'faces))
1298 ;;;###autoload
1299 (defun customize-apropos-groups (regexp)
1300 "Customize all loaded groups matching REGEXP."
1301 (interactive "sCustomize regexp: \n")
1302 (customize-apropos regexp 'groups))
1304 ;;; Buffer.
1306 (defcustom custom-buffer-style 'links
1307 "Control the presentation style for customization buffers.
1308 The value should be a symbol, one of:
1310 brackets: groups nest within each other with big horizontal brackets.
1311 links: groups have links to subgroups."
1312 :type '(radio (const brackets)
1313 (const links))
1314 :group 'custom-buffer)
1316 (defcustom custom-buffer-done-kill nil
1317 "*Non-nil means exiting a Custom buffer should kill it."
1318 :type 'boolean
1319 :version "22.1"
1320 :group 'custom-buffer)
1322 (defcustom custom-buffer-indent 3
1323 "Number of spaces to indent nested groups."
1324 :type 'integer
1325 :group 'custom-buffer)
1327 (defun custom-get-fresh-buffer (name)
1328 "Get a fresh new buffer with name NAME.
1329 If the buffer already exist, clean it up to be like new.
1330 Beware: it's not quite like new. Good enough for custom, but maybe
1331 not for everybody."
1332 ;; To be more complete, we should also kill all permanent-local variables,
1333 ;; but it's not needed for custom.
1334 (let ((buf (get-buffer name)))
1335 (when (and buf (buffer-local-value 'buffer-file-name buf))
1336 ;; This will check if the file is not saved.
1337 (kill-buffer buf)
1338 (setq buf nil))
1339 (if (null buf)
1340 (get-buffer-create name)
1341 (with-current-buffer buf
1342 (kill-all-local-variables)
1343 (run-hooks 'kill-buffer-hook)
1344 ;; Delete overlays before erasing the buffer so the overlay hooks
1345 ;; don't get run spuriously when we erase the buffer.
1346 (let ((ols (overlay-lists)))
1347 (dolist (ol (nconc (car ols) (cdr ols)))
1348 (delete-overlay ol)))
1349 (erase-buffer)
1350 buf))))
1352 ;;;###autoload
1353 (defun custom-buffer-create (options &optional name description)
1354 "Create a buffer containing OPTIONS.
1355 Optional NAME is the name of the buffer.
1356 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1357 SYMBOL is a customization option, and WIDGET is a widget for editing
1358 that option."
1359 (pop-to-buffer (custom-get-fresh-buffer (or name "*Customization*")))
1360 (custom-buffer-create-internal options description))
1362 ;;;###autoload
1363 (defun custom-buffer-create-other-window (options &optional name description)
1364 "Create a buffer containing OPTIONS, and display it in another window.
1365 The result includes selecting that window.
1366 Optional NAME is the name of the buffer.
1367 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1368 SYMBOL is a customization option, and WIDGET is a widget for editing
1369 that option."
1370 (unless name (setq name "*Customization*"))
1371 (let ((pop-up-windows t)
1372 (same-window-buffer-names nil)
1373 (same-window-regexps nil))
1374 (pop-to-buffer (custom-get-fresh-buffer name))
1375 (custom-buffer-create-internal options description)))
1377 (defcustom custom-reset-button-menu nil
1378 "If non-nil, only show a single reset button in customize buffers.
1379 This button will have a menu with all three reset operations."
1380 :type 'boolean
1381 :group 'custom-buffer)
1383 (defcustom custom-buffer-verbose-help t
1384 "If non-nil, include explanatory text in the customization buffer."
1385 :type 'boolean
1386 :group 'custom-buffer)
1388 (defun Custom-buffer-done (&rest ignore)
1389 "Exit current Custom buffer according to `custom-buffer-done-kill'."
1390 (interactive)
1391 (quit-window custom-buffer-done-kill))
1393 (defvar custom-button nil
1394 "Face used for buttons in customization buffers.")
1396 (defvar custom-button-pressed nil
1397 "Face used for pressed buttons in customization buffers.")
1399 (defcustom custom-raised-buttons (not (equal (face-valid-attribute-values :box)
1400 '(("unspecified" . unspecified))))
1401 "If non-nil, indicate active buttons in a `raised-button' style.
1402 Otherwise use brackets."
1403 :type 'boolean
1404 :version "21.1"
1405 :group 'custom-buffer
1406 :set (lambda (variable value)
1407 (custom-set-default variable value)
1408 (setq custom-button
1409 (if value 'custom-button 'custom-button-unraised))
1410 (setq custom-button-pressed
1411 (if value
1412 'custom-button-pressed
1413 'custom-button-pressed-unraised))))
1415 (defun custom-buffer-create-internal (options &optional description)
1416 (custom-mode)
1417 (if custom-buffer-verbose-help
1418 (progn
1419 (widget-insert "This is a customization buffer")
1420 (if description
1421 (widget-insert description))
1422 (widget-insert (format ".
1423 %s show active fields; type RET or click mouse-1
1424 on an active field to invoke its action. Editing an option value
1425 changes only the text in the buffer. Invoke the State button to set or
1426 save the option value. Saving an option normally edits your init file.
1427 Invoke "
1428 (if custom-raised-buttons
1429 "`Raised' buttons"
1430 "Square brackets")))
1431 (widget-create 'info-link
1432 :tag "Custom file"
1433 "(emacs)Saving Customizations")
1434 (widget-insert
1435 " for information on how to save in a different file.
1436 Invoke ")
1437 (widget-create 'info-link
1438 :tag "Help"
1439 :help-echo "Read the online help."
1440 "(emacs)Easy Customization")
1441 (widget-insert " for general information.\n\n")
1442 (widget-insert "Operate on everything in this buffer:\n "))
1443 (widget-insert " "))
1444 (widget-create 'push-button
1445 :tag "Set for Current Session"
1446 :help-echo "\
1447 Make your editing in this buffer take effect for this session."
1448 :action (lambda (widget &optional event)
1449 (Custom-set)))
1450 (widget-insert " ")
1451 (widget-create 'push-button
1452 :tag "Save for Future Sessions"
1453 :help-echo "\
1454 Make your editing in this buffer take effect for future Emacs sessions.
1455 This updates your Emacs initialization file or creates a new one."
1456 :action (lambda (widget &optional event)
1457 (Custom-save)))
1458 (if custom-reset-button-menu
1459 (progn
1460 (widget-insert " ")
1461 (widget-create 'push-button
1462 :tag "Reset"
1463 :help-echo "Show a menu with reset operations."
1464 :mouse-down-action (lambda (&rest junk) t)
1465 :action (lambda (widget &optional event)
1466 (custom-reset event))))
1467 (widget-insert "\n ")
1468 (widget-create 'push-button
1469 :tag "Reset to Current"
1470 :help-echo "\
1471 Reset all edited text in this buffer to reflect current values."
1472 :action 'Custom-reset-current)
1473 (widget-insert " ")
1474 (widget-create 'push-button
1475 :tag "Reset to Saved"
1476 :help-echo "\
1477 Reset all values in this buffer to their saved settings."
1478 :action 'Custom-reset-saved)
1479 (widget-insert " ")
1480 (widget-create 'push-button
1481 :tag "Erase Customization"
1482 :help-echo "\
1483 Un-customize all values in this buffer. They get their standard settings."
1484 :action 'Custom-reset-standard))
1485 (if (not custom-buffer-verbose-help)
1486 (progn
1487 (widget-insert " ")
1488 (widget-create 'info-link
1489 :tag "Help"
1490 :help-echo "Read the online help."
1491 "(emacs)Easy Customization")))
1492 (widget-insert " ")
1493 (widget-create 'push-button
1494 :tag "Finish"
1495 :help-echo
1496 (lambda (&rest ignore)
1497 (if custom-buffer-done-kill
1498 "Kill this buffer"
1499 "Bury this buffer"))
1500 :action #'Custom-buffer-done)
1501 (widget-insert "\n\n")
1502 (message "Creating customization items...")
1503 (buffer-disable-undo)
1504 (setq custom-options
1505 (if (= (length options) 1)
1506 (mapcar (lambda (entry)
1507 (widget-create (nth 1 entry)
1508 :documentation-shown t
1509 :custom-state 'unknown
1510 :tag (custom-unlispify-tag-name
1511 (nth 0 entry))
1512 :value (nth 0 entry)))
1513 options)
1514 (let ((count 0)
1515 (length (length options)))
1516 (mapcar (lambda (entry)
1517 (prog2
1518 (message "Creating customization items ...%2d%%"
1519 (/ (* 100.0 count) length))
1520 (widget-create (nth 1 entry)
1521 :tag (custom-unlispify-tag-name
1522 (nth 0 entry))
1523 :value (nth 0 entry))
1524 (setq count (1+ count))
1525 (unless (eq (preceding-char) ?\n)
1526 (widget-insert "\n"))
1527 (widget-insert "\n")))
1528 options))))
1529 (unless (eq (preceding-char) ?\n)
1530 (widget-insert "\n"))
1531 (message "Creating customization items ...done")
1532 (message "Resetting customization items...")
1533 (unless (eq custom-buffer-style 'tree)
1534 (mapc 'custom-magic-reset custom-options))
1535 (message "Resetting customization items...done")
1536 (message "Creating customization setup...")
1537 (widget-setup)
1538 (buffer-enable-undo)
1539 (goto-char (point-min))
1540 (message "Creating customization setup...done"))
1542 ;;; The Tree Browser.
1544 ;;;###autoload
1545 (defun customize-browse (&optional group)
1546 "Create a tree browser for the customize hierarchy."
1547 (interactive)
1548 (unless group
1549 (setq group 'emacs))
1550 (let ((name "*Customize Browser*"))
1551 (pop-to-buffer (custom-get-fresh-buffer name)))
1552 (custom-mode)
1553 (widget-insert "\
1554 Square brackets show active fields; type RET or click mouse-1
1555 on an active field to invoke its action.
1556 Invoke [+] below to expand a group, and [-] to collapse an expanded group.\n")
1557 (if custom-browse-only-groups
1558 (widget-insert "\
1559 Invoke the [Group] button below to edit that item in another window.\n\n")
1560 (widget-insert "Invoke the ")
1561 (widget-create 'item
1562 :format "%t"
1563 :tag "[Group]"
1564 :tag-glyph "folder")
1565 (widget-insert ", ")
1566 (widget-create 'item
1567 :format "%t"
1568 :tag "[Face]"
1569 :tag-glyph "face")
1570 (widget-insert ", and ")
1571 (widget-create 'item
1572 :format "%t"
1573 :tag "[Option]"
1574 :tag-glyph "option")
1575 (widget-insert " buttons below to edit that
1576 item in another window.\n\n"))
1577 (let ((custom-buffer-style 'tree))
1578 (widget-create 'custom-group
1579 :custom-last t
1580 :custom-state 'unknown
1581 :tag (custom-unlispify-tag-name group)
1582 :value group))
1583 (widget-setup)
1584 (goto-char (point-min)))
1586 (define-widget 'custom-browse-visibility 'item
1587 "Control visibility of items in the customize tree browser."
1588 :format "%[[%t]%]"
1589 :action 'custom-browse-visibility-action)
1591 (defun custom-browse-visibility-action (widget &rest ignore)
1592 (let ((custom-buffer-style 'tree))
1593 (custom-toggle-parent widget)))
1595 (define-widget 'custom-browse-group-tag 'push-button
1596 "Show parent in other window when activated."
1597 :tag "Group"
1598 :tag-glyph "folder"
1599 :action 'custom-browse-group-tag-action)
1601 (defun custom-browse-group-tag-action (widget &rest ignore)
1602 (let ((parent (widget-get widget :parent)))
1603 (customize-group-other-window (widget-value parent))))
1605 (define-widget 'custom-browse-variable-tag 'push-button
1606 "Show parent in other window when activated."
1607 :tag "Option"
1608 :tag-glyph "option"
1609 :action 'custom-browse-variable-tag-action)
1611 (defun custom-browse-variable-tag-action (widget &rest ignore)
1612 (let ((parent (widget-get widget :parent)))
1613 (customize-variable-other-window (widget-value parent))))
1615 (define-widget 'custom-browse-face-tag 'push-button
1616 "Show parent in other window when activated."
1617 :tag "Face"
1618 :tag-glyph "face"
1619 :action 'custom-browse-face-tag-action)
1621 (defun custom-browse-face-tag-action (widget &rest ignore)
1622 (let ((parent (widget-get widget :parent)))
1623 (customize-face-other-window (widget-value parent))))
1625 (defconst custom-browse-alist '((" " "space")
1626 (" | " "vertical")
1627 ("-\\ " "top")
1628 (" |-" "middle")
1629 (" `-" "bottom")))
1631 (defun custom-browse-insert-prefix (prefix)
1632 "Insert PREFIX. On XEmacs convert it to line graphics."
1633 ;; Fixme: do graphics.
1634 (if nil ; (string-match "XEmacs" emacs-version)
1635 (progn
1636 (insert "*")
1637 (while (not (string-equal prefix ""))
1638 (let ((entry (substring prefix 0 3)))
1639 (setq prefix (substring prefix 3))
1640 (let ((overlay (make-overlay (1- (point)) (point) nil t nil))
1641 (name (nth 1 (assoc entry custom-browse-alist))))
1642 (overlay-put overlay 'end-glyph (widget-glyph-find name entry))
1643 (overlay-put overlay 'start-open t)
1644 (overlay-put overlay 'end-open t)))))
1645 (insert prefix)))
1647 ;;; Modification of Basic Widgets.
1649 ;; We add extra properties to the basic widgets needed here. This is
1650 ;; fine, as long as we are careful to stay within out own namespace.
1652 ;; We want simple widgets to be displayed by default, but complex
1653 ;; widgets to be hidden.
1655 (widget-put (get 'item 'widget-type) :custom-show t)
1656 (widget-put (get 'editable-field 'widget-type)
1657 :custom-show (lambda (widget value)
1658 (let ((pp (pp-to-string value)))
1659 (cond ((string-match "\n" pp)
1660 nil)
1661 ((> (length pp) 40)
1662 nil)
1663 (t t)))))
1664 (widget-put (get 'menu-choice 'widget-type) :custom-show t)
1666 ;;; The `custom-manual' Widget.
1668 (define-widget 'custom-manual 'info-link
1669 "Link to the manual entry for this customization option."
1670 :help-echo "Read the manual entry for this option."
1671 :tag "Manual")
1673 ;;; The `custom-magic' Widget.
1675 (defgroup custom-magic-faces nil
1676 "Faces used by the magic button."
1677 :group 'custom-faces
1678 :group 'custom-buffer)
1680 (defface custom-invalid '((((class color))
1681 (:foreground "yellow1" :background "red1"))
1683 (:weight bold :slant italic :underline t)))
1684 "Face used when the customize item is invalid."
1685 :group 'custom-magic-faces)
1686 ;; backward-compatibility alias
1687 (put 'custom-invalid-face 'face-alias 'custom-invalid)
1689 (defface custom-rogue '((((class color))
1690 (:foreground "pink" :background "black"))
1692 (:underline t)))
1693 "Face used when the customize item is not defined for customization."
1694 :group 'custom-magic-faces)
1695 ;; backward-compatibility alias
1696 (put 'custom-rogue-face 'face-alias 'custom-rogue)
1698 (defface custom-modified '((((min-colors 88) (class color))
1699 (:foreground "white" :background "blue1"))
1700 (((class color))
1701 (:foreground "white" :background "blue"))
1703 (:slant italic :bold)))
1704 "Face used when the customize item has been modified."
1705 :group 'custom-magic-faces)
1706 ;; backward-compatibility alias
1707 (put 'custom-modified-face 'face-alias 'custom-modified)
1709 (defface custom-set '((((min-colors 88) (class color))
1710 (:foreground "blue1" :background "white"))
1711 (((class color))
1712 (:foreground "blue" :background "white"))
1714 (:slant italic)))
1715 "Face used when the customize item has been set."
1716 :group 'custom-magic-faces)
1717 ;; backward-compatibility alias
1718 (put 'custom-set-face 'face-alias 'custom-set)
1720 (defface custom-changed '((((min-colors 88) (class color))
1721 (:foreground "white" :background "blue1"))
1722 (((class color))
1723 (:foreground "white" :background "blue"))
1725 (:slant italic)))
1726 "Face used when the customize item has been changed."
1727 :group 'custom-magic-faces)
1728 ;; backward-compatibility alias
1729 (put 'custom-changed-face 'face-alias 'custom-changed)
1731 (defface custom-saved '((t (:underline t)))
1732 "Face used when the customize item has been saved."
1733 :group 'custom-magic-faces)
1734 ;; backward-compatibility alias
1735 (put 'custom-saved-face 'face-alias 'custom-saved)
1737 (defconst custom-magic-alist
1738 '((nil "#" underline "\
1739 UNINITIALIZED, you should not see this.")
1740 (unknown "?" italic "\
1741 UNKNOWN, you should not see this.")
1742 (hidden "-" default "\
1743 HIDDEN, invoke \"Show\" in the previous line to show." "\
1744 group now hidden, invoke \"Show\", above, to show contents.")
1745 (invalid "x" custom-invalid "\
1746 INVALID, the displayed value cannot be set.")
1747 (modified "*" custom-modified "\
1748 EDITED, shown value does not take effect until you set or save it." "\
1749 something in this group has been edited but not set.")
1750 (set "+" custom-set "\
1751 SET for current session only." "\
1752 something in this group has been set but not saved.")
1753 (changed ":" custom-changed "\
1754 CHANGED outside Customize; operating on it here may be unreliable." "\
1755 something in this group has been changed outside customize.")
1756 (saved "!" custom-saved "\
1757 SAVED and set." "\
1758 something in this group has been set and saved.")
1759 (rogue "@" custom-rogue "\
1760 NO CUSTOMIZATION DATA; you should not see this." "\
1761 something in this group is not prepared for customization.")
1762 (standard " " nil "\
1763 STANDARD." "\
1764 visible group members are all at standard settings."))
1765 "Alist of customize option states.
1766 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1768 STATE is one of the following symbols:
1770 `nil'
1771 For internal use, should never occur.
1772 `unknown'
1773 For internal use, should never occur.
1774 `hidden'
1775 This item is not being displayed.
1776 `invalid'
1777 This item is modified, but has an invalid form.
1778 `modified'
1779 This item is modified, and has a valid form.
1780 `set'
1781 This item has been set but not saved.
1782 `changed'
1783 The current value of this item has been changed outside Customize.
1784 `saved'
1785 This item is marked for saving.
1786 `rogue'
1787 This item has no customization information.
1788 `standard'
1789 This item is unchanged from the standard setting.
1791 MAGIC is a string used to present that state.
1793 FACE is a face used to present the state.
1795 ITEM-DESC is a string describing the state for options.
1797 GROUP-DESC is a string describing the state for groups. If this is
1798 left out, ITEM-DESC will be used.
1800 The string %c in either description will be replaced with the
1801 category of the item. These are `group'. `option', and `face'.
1803 The list should be sorted most significant first.")
1805 (defcustom custom-magic-show 'long
1806 "If non-nil, show textual description of the state.
1807 If `long', show a full-line description, not just one word."
1808 :type '(choice (const :tag "no" nil)
1809 (const long)
1810 (other :tag "short" short))
1811 :group 'custom-buffer)
1813 (defcustom custom-magic-show-hidden '(option face)
1814 "Control whether the State button is shown for hidden items.
1815 The value should be a list with the custom categories where the State
1816 button should be visible. Possible categories are `group', `option',
1817 and `face'."
1818 :type '(set (const group) (const option) (const face))
1819 :group 'custom-buffer)
1821 (defcustom custom-magic-show-button nil
1822 "Show a \"magic\" button indicating the state of each customization option."
1823 :type 'boolean
1824 :group 'custom-buffer)
1826 (define-widget 'custom-magic 'default
1827 "Show and manipulate state for a customization option."
1828 :format "%v"
1829 :action 'widget-parent-action
1830 :notify 'ignore
1831 :value-get 'ignore
1832 :value-create 'custom-magic-value-create
1833 :value-delete 'widget-children-value-delete)
1835 (defun widget-magic-mouse-down-action (widget &optional event)
1836 ;; Non-nil unless hidden.
1837 (not (eq (widget-get (widget-get (widget-get widget :parent) :parent)
1838 :custom-state)
1839 'hidden)))
1841 (defun custom-magic-value-create (widget)
1842 "Create compact status report for WIDGET."
1843 (let* ((parent (widget-get widget :parent))
1844 (state (widget-get parent :custom-state))
1845 (hidden (eq state 'hidden))
1846 (entry (assq state custom-magic-alist))
1847 (magic (nth 1 entry))
1848 (face (nth 2 entry))
1849 (category (widget-get parent :custom-category))
1850 (text (or (and (eq category 'group)
1851 (nth 4 entry))
1852 (nth 3 entry)))
1853 (form (widget-get parent :custom-form))
1854 children)
1855 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text)
1856 (setq text (concat (match-string 1 text)
1857 (symbol-name category)
1858 (match-string 2 text))))
1859 (when (and custom-magic-show
1860 (or (not hidden)
1861 (memq category custom-magic-show-hidden)))
1862 (insert " ")
1863 (when (and (eq category 'group)
1864 (not (and (eq custom-buffer-style 'links)
1865 (> (widget-get parent :custom-level) 1))))
1866 (insert-char ?\ (* custom-buffer-indent
1867 (widget-get parent :custom-level))))
1868 (push (widget-create-child-and-convert
1869 widget 'choice-item
1870 :help-echo "Change the state of this item."
1871 :format (if hidden "%t" "%[%t%]")
1872 :button-prefix 'widget-push-button-prefix
1873 :button-suffix 'widget-push-button-suffix
1874 :mouse-down-action 'widget-magic-mouse-down-action
1875 :tag "State")
1876 children)
1877 (insert ": ")
1878 (let ((start (point)))
1879 (if (eq custom-magic-show 'long)
1880 (insert text)
1881 (insert (symbol-name state)))
1882 (cond ((eq form 'lisp)
1883 (insert " (lisp)"))
1884 ((eq form 'mismatch)
1885 (insert " (mismatch)")))
1886 (put-text-property start (point) 'face 'custom-state))
1887 (insert "\n"))
1888 (when (and (eq category 'group)
1889 (not (and (eq custom-buffer-style 'links)
1890 (> (widget-get parent :custom-level) 1))))
1891 (insert-char ?\ (* custom-buffer-indent
1892 (widget-get parent :custom-level))))
1893 (when custom-magic-show-button
1894 (when custom-magic-show
1895 (let ((indent (widget-get parent :indent)))
1896 (when indent
1897 (insert-char ? indent))))
1898 (push (widget-create-child-and-convert
1899 widget 'choice-item
1900 :mouse-down-action 'widget-magic-mouse-down-action
1901 :button-face face
1902 :button-prefix ""
1903 :button-suffix ""
1904 :help-echo "Change the state."
1905 :format (if hidden "%t" "%[%t%]")
1906 :tag (if (memq form '(lisp mismatch))
1907 (concat "(" magic ")")
1908 (concat "[" magic "]")))
1909 children)
1910 (insert " "))
1911 (widget-put widget :children children)))
1913 (defun custom-magic-reset (widget)
1914 "Redraw the :custom-magic property of WIDGET."
1915 (let ((magic (widget-get widget :custom-magic)))
1916 (widget-value-set magic (widget-value magic))))
1918 ;;; The `custom' Widget.
1920 (defface custom-button
1921 '((((type x w32 mac) (class color)) ; Like default modeline
1922 (:box (:line-width 2 :style released-button)
1923 :background "lightgrey" :foreground "black"))
1925 nil))
1926 "Face for custom buffer buttons if `custom-raised-buttons' is non-nil."
1927 :version "21.1"
1928 :group 'custom-faces)
1929 ;; backward-compatibility alias
1930 (put 'custom-button-face 'face-alias 'custom-button)
1932 (defface custom-button-unraised
1933 '((((min-colors 88)
1934 (class color) (background light)) :foreground "blue1" :underline t)
1935 (((class color) (background light)) :foreground "blue" :underline t)
1936 (((min-colors 88)
1937 (class color) (background dark)) :foreground "cyan1" :underline t)
1938 (((class color) (background dark)) :foreground "cyan" :underline t)
1939 (t :underline t))
1940 "Face for custom buffer buttons if `custom-raised-buttons' is nil."
1941 :version "22.1"
1942 :group 'custom-faces)
1944 (setq custom-button
1945 (if custom-raised-buttons 'custom-button 'custom-button-unraised))
1947 (defface custom-button-pressed
1948 '((((type x w32 mac) (class color))
1949 (:box (:line-width 2 :style pressed-button)
1950 :background "lightgrey" :foreground "black"))
1952 (:inverse-video t)))
1953 "Face for pressed custom buttons if `custom-raised-buttons' is non-nil."
1954 :version "21.1"
1955 :group 'custom-faces)
1956 ;; backward-compatibility alias
1957 (put 'custom-button-pressed-face 'face-alias 'custom-button-pressed)
1959 (defface custom-button-pressed-unraised
1960 '((default :inherit custom-button-unraised)
1961 (((class color) (background light)) :foreground "magenta4")
1962 (((class color) (background dark)) :foreground "violet"))
1963 "Face for pressed custom buttons if `custom-raised-buttons' is nil."
1964 :version "22.1"
1965 :group 'custom-faces)
1967 (setq custom-button-pressed
1968 (if custom-raised-buttons
1969 'custom-button-pressed
1970 'custom-button-pressed-unraised))
1972 (defface custom-documentation nil
1973 "Face used for documentation strings in customization buffers."
1974 :group 'custom-faces)
1975 ;; backward-compatibility alias
1976 (put 'custom-documentation-face 'face-alias 'custom-documentation)
1978 (defface custom-state '((((class color)
1979 (background dark))
1980 (:foreground "lime green"))
1981 (((class color)
1982 (background light))
1983 (:foreground "dark green"))
1984 (t nil))
1985 "Face used for State descriptions in the customize buffer."
1986 :group 'custom-faces)
1987 ;; backward-compatibility alias
1988 (put 'custom-state-face 'face-alias 'custom-state)
1990 (define-widget 'custom 'default
1991 "Customize a user option."
1992 :format "%v"
1993 :convert-widget 'custom-convert-widget
1994 :notify 'custom-notify
1995 :custom-prefix ""
1996 :custom-level 1
1997 :custom-state 'hidden
1998 :documentation-property 'widget-subclass-responsibility
1999 :value-create 'widget-subclass-responsibility
2000 :value-delete 'widget-children-value-delete
2001 :value-get 'widget-value-value-get
2002 :validate 'widget-children-validate
2003 :match (lambda (widget value) (symbolp value)))
2005 (defun custom-convert-widget (widget)
2006 "Initialize :value and :tag from :args in WIDGET."
2007 (let ((args (widget-get widget :args)))
2008 (when args
2009 (widget-put widget :value (widget-apply widget
2010 :value-to-internal (car args)))
2011 (widget-put widget :tag (custom-unlispify-tag-name (car args)))
2012 (widget-put widget :args nil)))
2013 widget)
2015 (defun custom-notify (widget &rest args)
2016 "Keep track of changes."
2017 (let ((state (widget-get widget :custom-state)))
2018 (unless (eq state 'modified)
2019 (unless (memq state '(nil unknown hidden))
2020 (widget-put widget :custom-state 'modified))
2021 (custom-magic-reset widget)
2022 (apply 'widget-default-notify widget args))))
2024 (defun custom-redraw (widget)
2025 "Redraw WIDGET with current settings."
2026 (let ((line (count-lines (point-min) (point)))
2027 (column (current-column))
2028 (pos (point))
2029 (from (marker-position (widget-get widget :from)))
2030 (to (marker-position (widget-get widget :to))))
2031 (save-excursion
2032 (widget-value-set widget (widget-value widget))
2033 (custom-redraw-magic widget))
2034 (when (and (>= pos from) (<= pos to))
2035 (condition-case nil
2036 (progn
2037 (if (> column 0)
2038 (goto-line line)
2039 (goto-line (1+ line)))
2040 (move-to-column column))
2041 (error nil)))))
2043 (defun custom-redraw-magic (widget)
2044 "Redraw WIDGET state with current settings."
2045 (while widget
2046 (let ((magic (widget-get widget :custom-magic)))
2047 (cond (magic
2048 (widget-value-set magic (widget-value magic))
2049 (when (setq widget (widget-get widget :group))
2050 (custom-group-state-update widget)))
2052 (setq widget nil)))))
2053 (widget-setup))
2055 (defun custom-show (widget value)
2056 "Non-nil if WIDGET should be shown with VALUE by default."
2057 (let ((show (widget-get widget :custom-show)))
2058 (cond ((null show)
2059 nil)
2060 ((eq t show)
2063 (funcall show widget value)))))
2065 (defun custom-load-widget (widget)
2066 "Load all dependencies for WIDGET."
2067 (custom-load-symbol (widget-value widget)))
2069 (defun custom-unloaded-symbol-p (symbol)
2070 "Return non-nil if the dependencies of SYMBOL have not yet been loaded."
2071 (let ((found nil)
2072 (loads (get symbol 'custom-loads))
2073 load)
2074 (while loads
2075 (setq load (car loads)
2076 loads (cdr loads))
2077 (cond ((symbolp load)
2078 (unless (featurep load)
2079 (setq found t)))
2080 ((assoc load load-history))
2081 ((assoc (locate-library load) load-history)
2082 (message nil))
2084 (setq found t))))
2085 found))
2087 (defun custom-unloaded-widget-p (widget)
2088 "Return non-nil if the dependencies of WIDGET have not yet been loaded."
2089 (custom-unloaded-symbol-p (widget-value widget)))
2091 (defun custom-toggle-hide (widget)
2092 "Toggle visibility of WIDGET."
2093 (custom-load-widget widget)
2094 (let ((state (widget-get widget :custom-state)))
2095 (cond ((memq state '(invalid modified))
2096 (error "There are unset changes"))
2097 ((eq state 'hidden)
2098 (widget-put widget :custom-state 'unknown))
2100 (widget-put widget :documentation-shown nil)
2101 (widget-put widget :custom-state 'hidden)))
2102 (custom-redraw widget)
2103 (widget-setup)))
2105 (defun custom-toggle-parent (widget &rest ignore)
2106 "Toggle visibility of parent of WIDGET."
2107 (custom-toggle-hide (widget-get widget :parent)))
2109 (defun custom-add-see-also (widget &optional prefix)
2110 "Add `See also ...' to WIDGET if there are any links.
2111 Insert PREFIX first if non-nil."
2112 (let* ((symbol (widget-get widget :value))
2113 (links (get symbol 'custom-links))
2114 (many (> (length links) 2))
2115 (buttons (widget-get widget :buttons))
2116 (indent (widget-get widget :indent)))
2117 (when links
2118 (when indent
2119 (insert-char ?\ indent))
2120 (when prefix
2121 (insert prefix))
2122 (insert "See also ")
2123 (while links
2124 (push (widget-create-child-and-convert widget (car links))
2125 buttons)
2126 (setq links (cdr links))
2127 (cond ((null links)
2128 (insert ".\n"))
2129 ((null (cdr links))
2130 (if many
2131 (insert ", and ")
2132 (insert " and ")))
2134 (insert ", "))))
2135 (widget-put widget :buttons buttons))))
2137 (defun custom-add-parent-links (widget &optional initial-string)
2138 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
2139 The value is non-nil if any parents were found.
2140 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
2141 (let ((name (widget-value widget))
2142 (type (widget-type widget))
2143 (buttons (widget-get widget :buttons))
2144 (start (point))
2145 (parents nil))
2146 (insert (or initial-string "Parent groups:"))
2147 (mapatoms (lambda (symbol)
2148 (when (member (list name type) (get symbol 'custom-group))
2149 (insert " ")
2150 (push (widget-create-child-and-convert
2151 widget 'custom-group-link
2152 :tag (custom-unlispify-tag-name symbol)
2153 symbol)
2154 buttons)
2155 (setq parents (cons symbol parents)))))
2156 (and (null (get name 'custom-links)) ;No links of its own.
2157 (= (length parents) 1) ;A single parent.
2158 (let* ((links (delq nil (mapcar (lambda (w)
2159 (unless (eq (widget-type w)
2160 'custom-group-link)
2162 (get (car parents) 'custom-links))))
2163 (many (> (length links) 2)))
2164 (when links
2165 (insert "\nParent documentation: ")
2166 (while links
2167 (push (widget-create-child-and-convert widget (car links))
2168 buttons)
2169 (setq links (cdr links))
2170 (cond ((null links)
2171 (insert ".\n"))
2172 ((null (cdr links))
2173 (if many
2174 (insert ", and ")
2175 (insert " and ")))
2177 (insert ", ")))))))
2178 (if parents
2179 (insert "\n")
2180 (delete-region start (point)))
2181 (widget-put widget :buttons buttons)
2182 parents))
2184 ;;; The `custom-comment' Widget.
2186 ;; like the editable field
2187 (defface custom-comment '((((class grayscale color)
2188 (background light))
2189 (:background "gray85"))
2190 (((class grayscale color)
2191 (background dark))
2192 (:background "dim gray"))
2194 (:slant italic)))
2195 "Face used for comments on variables or faces"
2196 :version "21.1"
2197 :group 'custom-faces)
2198 ;; backward-compatibility alias
2199 (put 'custom-comment-face 'face-alias 'custom-comment)
2201 ;; like font-lock-comment-face
2202 (defface custom-comment-tag
2203 '((((class color) (background dark)) (:foreground "gray80"))
2204 (((class color) (background light)) (:foreground "blue4"))
2205 (((class grayscale) (background light))
2206 (:foreground "DimGray" :weight bold :slant italic))
2207 (((class grayscale) (background dark))
2208 (:foreground "LightGray" :weight bold :slant italic))
2209 (t (:weight bold)))
2210 "Face used for variables or faces comment tags"
2211 :group 'custom-faces)
2212 ;; backward-compatibility alias
2213 (put 'custom-comment-tag-face 'face-alias 'custom-comment-tag)
2215 (define-widget 'custom-comment 'string
2216 "User comment."
2217 :tag "Comment"
2218 :help-echo "Edit a comment here."
2219 :sample-face 'custom-comment-tag-face
2220 :value-face 'custom-comment-face
2221 :shown nil
2222 :create 'custom-comment-create)
2224 (defun custom-comment-create (widget)
2225 (let* ((null-comment (equal "" (widget-value widget))))
2226 (if (or (widget-get (widget-get widget :parent) :comment-shown)
2227 (not null-comment))
2228 (widget-default-create widget)
2229 ;; `widget-default-delete' expects markers in these slots --
2230 ;; maybe it shouldn't.
2231 (widget-put widget :from (point-marker))
2232 (widget-put widget :to (point-marker)))))
2234 (defun custom-comment-hide (widget)
2235 (widget-put (widget-get widget :parent) :comment-shown nil))
2237 ;; Those functions are for the menu. WIDGET is NOT the comment widget. It's
2238 ;; the global custom one
2239 (defun custom-comment-show (widget)
2240 (widget-put widget :comment-shown t)
2241 (custom-redraw widget)
2242 (widget-setup))
2244 (defun custom-comment-invisible-p (widget)
2245 (let ((val (widget-value (widget-get widget :comment-widget))))
2246 (and (equal "" val)
2247 (not (widget-get widget :comment-shown)))))
2249 ;;; The `custom-variable' Widget.
2251 ;; When this was underlined blue, users confused it with a
2252 ;; Mosaic-style hyperlink...
2253 (defface custom-variable-tag
2254 `((((class color)
2255 (background dark))
2256 (:foreground "light blue" :weight bold :height 1.2 :inherit variable-pitch))
2257 (((min-colors 88) (class color)
2258 (background light))
2259 (:foreground "blue1" :weight bold :height 1.2 :inherit variable-pitch))
2260 (((class color)
2261 (background light))
2262 (:foreground "blue" :weight bold :height 1.2 :inherit variable-pitch))
2263 (t (:weight bold)))
2264 "Face used for unpushable variable tags."
2265 :group 'custom-faces)
2266 ;; backward-compatibility alias
2267 (put 'custom-variable-tag-face 'face-alias 'custom-variable-tag)
2269 (defface custom-variable-button '((t (:underline t :weight bold)))
2270 "Face used for pushable variable tags."
2271 :group 'custom-faces)
2272 ;; backward-compatibility alias
2273 (put 'custom-variable-button-face 'face-alias 'custom-variable-button)
2275 (defcustom custom-variable-default-form 'edit
2276 "Default form of displaying variable values."
2277 :type '(choice (const edit)
2278 (const lisp))
2279 :group 'custom-buffer
2280 :version "20.3")
2282 (defun custom-variable-documentation (variable)
2283 "Return documentation of VARIABLE for use in Custom buffer.
2284 Normally just return the docstring. But if VARIABLE automatically
2285 becomes buffer local when set, append a message to that effect."
2286 (if (and (local-variable-if-set-p variable)
2287 (or (not (local-variable-p variable))
2288 (with-temp-buffer
2289 (local-variable-if-set-p variable))))
2290 (concat (documentation-property variable 'variable-documentation)
2292 This variable automatically becomes buffer-local when set outside Custom.
2293 However, setting it through Custom sets the default value.")
2294 (documentation-property variable 'variable-documentation)))
2296 (define-widget 'custom-variable 'custom
2297 "Customize variable."
2298 :format "%v"
2299 :help-echo "Set or reset this variable."
2300 :documentation-property #'custom-variable-documentation
2301 :custom-category 'option
2302 :custom-state nil
2303 :custom-menu 'custom-variable-menu-create
2304 :custom-form nil ; defaults to value of `custom-variable-default-form'
2305 :value-create 'custom-variable-value-create
2306 :action 'custom-variable-action
2307 :custom-set 'custom-variable-set
2308 :custom-save 'custom-variable-save
2309 :custom-reset-current 'custom-redraw
2310 :custom-reset-saved 'custom-variable-reset-saved
2311 :custom-reset-standard 'custom-variable-reset-standard
2312 :custom-standard-value 'custom-variable-standard-value)
2314 (defun custom-variable-type (symbol)
2315 "Return a widget suitable for editing the value of SYMBOL.
2316 If SYMBOL has a `custom-type' property, use that.
2317 Otherwise, look up symbol in `custom-guess-type-alist'."
2318 (let* ((type (or (get symbol 'custom-type)
2319 (and (not (get symbol 'standard-value))
2320 (custom-guess-type symbol))
2321 'sexp))
2322 (options (get symbol 'custom-options))
2323 (tmp (if (listp type)
2324 (copy-sequence type)
2325 (list type))))
2326 (when options
2327 (widget-put tmp :options options))
2328 tmp))
2330 (defun custom-variable-value-create (widget)
2331 "Here is where you edit the variable's value."
2332 (custom-load-widget widget)
2333 (unless (widget-get widget :custom-form)
2334 (widget-put widget :custom-form custom-variable-default-form))
2335 (let* ((buttons (widget-get widget :buttons))
2336 (children (widget-get widget :children))
2337 (form (widget-get widget :custom-form))
2338 (state (widget-get widget :custom-state))
2339 (symbol (widget-get widget :value))
2340 (tag (widget-get widget :tag))
2341 (type (custom-variable-type symbol))
2342 (conv (widget-convert type))
2343 (get (or (get symbol 'custom-get) 'default-value))
2344 (prefix (widget-get widget :custom-prefix))
2345 (last (widget-get widget :custom-last))
2346 (value (if (default-boundp symbol)
2347 (funcall get symbol)
2348 (widget-get conv :value))))
2349 ;; If the widget is new, the child determines whether it is hidden.
2350 (cond (state)
2351 ((custom-show type value)
2352 (setq state 'unknown))
2354 (setq state 'hidden)))
2355 ;; If we don't know the state, see if we need to edit it in lisp form.
2356 (when (eq state 'unknown)
2357 (unless (widget-apply conv :match value)
2358 ;; (widget-apply (widget-convert type) :match value)
2359 (setq form 'mismatch)))
2360 ;; Now we can create the child widget.
2361 (cond ((eq custom-buffer-style 'tree)
2362 (insert prefix (if last " `--- " " |--- "))
2363 (push (widget-create-child-and-convert
2364 widget 'custom-browse-variable-tag)
2365 buttons)
2366 (insert " " tag "\n")
2367 (widget-put widget :buttons buttons))
2368 ((eq state 'hidden)
2369 ;; Indicate hidden value.
2370 (push (widget-create-child-and-convert
2371 widget 'item
2372 :format "%{%t%}: "
2373 :sample-face 'custom-variable-tag-face
2374 :tag tag
2375 :parent widget)
2376 buttons)
2377 (push (widget-create-child-and-convert
2378 widget 'visibility
2379 :help-echo "Show the value of this option."
2380 :off "Show Value"
2381 :action 'custom-toggle-parent
2382 nil)
2383 buttons))
2384 ((memq form '(lisp mismatch))
2385 ;; In lisp mode edit the saved value when possible.
2386 (let* ((value (cond ((get symbol 'saved-value)
2387 (car (get symbol 'saved-value)))
2388 ((get symbol 'standard-value)
2389 (car (get symbol 'standard-value)))
2390 ((default-boundp symbol)
2391 (custom-quote (funcall get symbol)))
2393 (custom-quote (widget-get conv :value))))))
2394 (insert (symbol-name symbol) ": ")
2395 (push (widget-create-child-and-convert
2396 widget 'visibility
2397 :help-echo "Hide the value of this option."
2398 :on "Hide Value"
2399 :off "Show Value"
2400 :action 'custom-toggle-parent
2402 buttons)
2403 (insert " ")
2404 (push (widget-create-child-and-convert
2405 widget 'sexp
2406 :button-face 'custom-variable-button-face
2407 :format "%v"
2408 :tag (symbol-name symbol)
2409 :parent widget
2410 :value value)
2411 children)))
2413 ;; Edit mode.
2414 (let* ((format (widget-get type :format))
2415 tag-format value-format)
2416 (unless (string-match ":" format)
2417 (error "Bad format"))
2418 (setq tag-format (substring format 0 (match-end 0)))
2419 (setq value-format (substring format (match-end 0)))
2420 (push (widget-create-child-and-convert
2421 widget 'item
2422 :format tag-format
2423 :action 'custom-tag-action
2424 :help-echo "Change value of this option."
2425 :mouse-down-action 'custom-tag-mouse-down-action
2426 :button-face 'custom-variable-button-face
2427 :sample-face 'custom-variable-tag-face
2428 tag)
2429 buttons)
2430 (insert " ")
2431 (push (widget-create-child-and-convert
2432 widget 'visibility
2433 :help-echo "Hide the value of this option."
2434 :on "Hide Value"
2435 :off "Show Value"
2436 :action 'custom-toggle-parent
2438 buttons)
2439 (push (widget-create-child-and-convert
2440 widget type
2441 :format value-format
2442 :value value)
2443 children))))
2444 (unless (eq custom-buffer-style 'tree)
2445 (unless (eq (preceding-char) ?\n)
2446 (widget-insert "\n"))
2447 ;; Create the magic button.
2448 (let ((magic (widget-create-child-and-convert
2449 widget 'custom-magic nil)))
2450 (widget-put widget :custom-magic magic)
2451 (push magic buttons))
2452 ;; ### NOTE: this is ugly!!!! I need to update the :buttons property
2453 ;; before the call to `widget-default-format-handler'. Otherwise, I
2454 ;; loose my current `buttons'. This function shouldn't be called like
2455 ;; this anyway. The doc string widget should be added like the others.
2456 ;; --dv
2457 (widget-put widget :buttons buttons)
2458 (insert "\n")
2459 ;; Insert documentation.
2460 (widget-default-format-handler widget ?h)
2462 ;; The comment field
2463 (unless (eq state 'hidden)
2464 (let* ((comment (get symbol 'variable-comment))
2465 (comment-widget
2466 (widget-create-child-and-convert
2467 widget 'custom-comment
2468 :parent widget
2469 :value (or comment ""))))
2470 (widget-put widget :comment-widget comment-widget)
2471 ;; Don't push it !!! Custom assumes that the first child is the
2472 ;; value one.
2473 (setq children (append children (list comment-widget)))))
2474 ;; Update the rest of the properties properties.
2475 (widget-put widget :custom-form form)
2476 (widget-put widget :children children)
2477 ;; Now update the state.
2478 (if (eq state 'hidden)
2479 (widget-put widget :custom-state state)
2480 (custom-variable-state-set widget))
2481 ;; See also.
2482 (unless (eq state 'hidden)
2483 (when (eq (widget-get widget :custom-level) 1)
2484 (custom-add-parent-links widget))
2485 (custom-add-see-also widget)))))
2487 (defun custom-tag-action (widget &rest args)
2488 "Pass :action to first child of WIDGET's parent."
2489 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
2490 :action args))
2492 (defun custom-tag-mouse-down-action (widget &rest args)
2493 "Pass :mouse-down-action to first child of WIDGET's parent."
2494 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
2495 :mouse-down-action args))
2497 (defun custom-variable-state-set (widget)
2498 "Set the state of WIDGET."
2499 (let* ((symbol (widget-value widget))
2500 (get (or (get symbol 'custom-get) 'default-value))
2501 (value (if (default-boundp symbol)
2502 (funcall get symbol)
2503 (widget-get widget :value)))
2504 (comment (get symbol 'variable-comment))
2506 temp
2507 (state (cond ((progn (setq tmp (get symbol 'customized-value))
2508 (setq temp
2509 (get symbol 'customized-variable-comment))
2510 (or tmp temp))
2511 (if (condition-case nil
2512 (and (equal value (eval (car tmp)))
2513 (equal comment temp))
2514 (error nil))
2515 'set
2516 'changed))
2517 ((progn (setq tmp (get symbol 'saved-value))
2518 (setq temp (get symbol 'saved-variable-comment))
2519 (or tmp temp))
2520 (if (condition-case nil
2521 (and (equal value (eval (car tmp)))
2522 (equal comment temp))
2523 (error nil))
2524 'saved
2525 'changed))
2526 ((setq tmp (get symbol 'standard-value))
2527 (if (condition-case nil
2528 (and (equal value (eval (car tmp)))
2529 (equal comment nil))
2530 (error nil))
2531 'standard
2532 'changed))
2533 (t 'rogue))))
2534 (widget-put widget :custom-state state)))
2536 (defun custom-variable-standard-value (widget)
2537 (get (widget-value widget) 'standard-value))
2539 (defvar custom-variable-menu
2540 '(("Set for Current Session" custom-variable-set
2541 (lambda (widget)
2542 (eq (widget-get widget :custom-state) 'modified)))
2543 ("Save for Future Sessions" custom-variable-save
2544 (lambda (widget)
2545 (memq (widget-get widget :custom-state) '(modified set changed rogue))))
2546 ("Reset to Current" custom-redraw
2547 (lambda (widget)
2548 (and (default-boundp (widget-value widget))
2549 (memq (widget-get widget :custom-state) '(modified changed)))))
2550 ("Reset to Saved" custom-variable-reset-saved
2551 (lambda (widget)
2552 (and (or (get (widget-value widget) 'saved-value)
2553 (get (widget-value widget) 'saved-variable-comment))
2554 (memq (widget-get widget :custom-state)
2555 '(modified set changed rogue)))))
2556 ("Erase Customization" custom-variable-reset-standard
2557 (lambda (widget)
2558 (and (get (widget-value widget) 'standard-value)
2559 (memq (widget-get widget :custom-state)
2560 '(modified set changed saved rogue)))))
2561 ("Use Backup Value" custom-variable-reset-backup
2562 (lambda (widget)
2563 (get (widget-value widget) 'backup-value)))
2564 ("---" ignore ignore)
2565 ("Add Comment" custom-comment-show custom-comment-invisible-p)
2566 ("---" ignore ignore)
2567 ("Don't show as Lisp expression" custom-variable-edit
2568 (lambda (widget)
2569 (eq (widget-get widget :custom-form) 'lisp)))
2570 ("Show initial Lisp expression" custom-variable-edit-lisp
2571 (lambda (widget)
2572 (eq (widget-get widget :custom-form) 'edit))))
2573 "Alist of actions for the `custom-variable' widget.
2574 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2575 the menu entry, ACTION is the function to call on the widget when the
2576 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2577 widget as an argument, and returns non-nil if ACTION is valid on that
2578 widget. If FILTER is nil, ACTION is always valid.")
2580 (defun custom-variable-action (widget &optional event)
2581 "Show the menu for `custom-variable' WIDGET.
2582 Optional EVENT is the location for the menu."
2583 (if (eq (widget-get widget :custom-state) 'hidden)
2584 (custom-toggle-hide widget)
2585 (unless (eq (widget-get widget :custom-state) 'modified)
2586 (custom-variable-state-set widget))
2587 (custom-redraw-magic widget)
2588 (let* ((completion-ignore-case t)
2589 (answer (widget-choose (concat "Operation on "
2590 (custom-unlispify-tag-name
2591 (widget-get widget :value)))
2592 (custom-menu-filter custom-variable-menu
2593 widget)
2594 event)))
2595 (if answer
2596 (funcall answer widget)))))
2598 (defun custom-variable-edit (widget)
2599 "Edit value of WIDGET."
2600 (widget-put widget :custom-state 'unknown)
2601 (widget-put widget :custom-form 'edit)
2602 (custom-redraw widget))
2604 (defun custom-variable-edit-lisp (widget)
2605 "Edit the Lisp representation of the value of WIDGET."
2606 (widget-put widget :custom-state 'unknown)
2607 (widget-put widget :custom-form 'lisp)
2608 (custom-redraw widget))
2610 (defun custom-variable-set (widget)
2611 "Set the current value for the variable being edited by WIDGET."
2612 (let* ((form (widget-get widget :custom-form))
2613 (state (widget-get widget :custom-state))
2614 (child (car (widget-get widget :children)))
2615 (symbol (widget-value widget))
2616 (set (or (get symbol 'custom-set) 'set-default))
2617 (comment-widget (widget-get widget :comment-widget))
2618 (comment (widget-value comment-widget))
2619 val)
2620 (cond ((eq state 'hidden)
2621 (error "Cannot set hidden variable"))
2622 ((setq val (widget-apply child :validate))
2623 (goto-char (widget-get val :from))
2624 (error "%s" (widget-get val :error)))
2625 ((memq form '(lisp mismatch))
2626 (when (equal comment "")
2627 (setq comment nil)
2628 ;; Make the comment invisible by hand if it's empty
2629 (custom-comment-hide comment-widget))
2630 (custom-variable-backup-value widget)
2631 (funcall set symbol (eval (setq val (widget-value child))))
2632 (put symbol 'customized-value (list val))
2633 (put symbol 'variable-comment comment)
2634 (put symbol 'customized-variable-comment comment))
2636 (when (equal comment "")
2637 (setq comment nil)
2638 ;; Make the comment invisible by hand if it's empty
2639 (custom-comment-hide comment-widget))
2640 (custom-variable-backup-value widget)
2641 (funcall set symbol (setq val (widget-value child)))
2642 (put symbol 'customized-value (list (custom-quote val)))
2643 (put symbol 'variable-comment comment)
2644 (put symbol 'customized-variable-comment comment)))
2645 (custom-variable-state-set widget)
2646 (custom-redraw-magic widget)))
2648 (defun custom-variable-save (widget)
2649 "Set and save the value for the variable being edited by WIDGET."
2650 (let* ((form (widget-get widget :custom-form))
2651 (state (widget-get widget :custom-state))
2652 (child (car (widget-get widget :children)))
2653 (symbol (widget-value widget))
2654 (set (or (get symbol 'custom-set) 'set-default))
2655 (comment-widget (widget-get widget :comment-widget))
2656 (comment (widget-value comment-widget))
2657 val)
2658 (cond ((eq state 'hidden)
2659 (error "Cannot set hidden variable"))
2660 ((setq val (widget-apply child :validate))
2661 (goto-char (widget-get val :from))
2662 (error "Saving %s: %s" symbol (widget-get val :error)))
2663 ((memq form '(lisp mismatch))
2664 (when (equal comment "")
2665 (setq comment nil)
2666 ;; Make the comment invisible by hand if it's empty
2667 (custom-comment-hide comment-widget))
2668 (put symbol 'saved-value (list (widget-value child)))
2669 (custom-push-theme 'theme-value symbol 'user
2670 'set (list (widget-value child)))
2671 (funcall set symbol (eval (widget-value child)))
2672 (put symbol 'variable-comment comment)
2673 (put symbol 'saved-variable-comment comment))
2675 (when (equal comment "")
2676 (setq comment nil)
2677 ;; Make the comment invisible by hand if it's empty
2678 (custom-comment-hide comment-widget))
2679 (put symbol 'saved-value
2680 (list (custom-quote (widget-value child))))
2681 (custom-push-theme 'theme-value symbol 'user
2682 'set (list (custom-quote (widget-value
2683 child))))
2684 (funcall set symbol (widget-value child))
2685 (put symbol 'variable-comment comment)
2686 (put symbol 'saved-variable-comment comment)))
2687 (put symbol 'customized-value nil)
2688 (put symbol 'customized-variable-comment nil)
2689 (custom-save-all)
2690 (custom-variable-state-set widget)
2691 (custom-redraw-magic widget)))
2693 (defun custom-variable-reset-saved (widget)
2694 "Restore the saved value for the variable being edited by WIDGET.
2695 The value that was current before this operation
2696 becomes the backup value, so you can get it again."
2697 (let* ((symbol (widget-value widget))
2698 (set (or (get symbol 'custom-set) 'set-default))
2699 (value (get symbol 'saved-value))
2700 (comment (get symbol 'saved-variable-comment)))
2701 (cond ((or value comment)
2702 (put symbol 'variable-comment comment)
2703 (custom-variable-backup-value widget)
2704 (condition-case nil
2705 (funcall set symbol (eval (car value)))
2706 (error nil)))
2708 (error "No saved value for %s" symbol)))
2709 (put symbol 'customized-value nil)
2710 (put symbol 'customized-variable-comment nil)
2711 (widget-put widget :custom-state 'unknown)
2712 ;; This call will possibly make the comment invisible
2713 (custom-redraw widget)))
2715 (defun custom-variable-reset-standard (widget)
2716 "Restore the standard setting for the variable being edited by WIDGET.
2717 This operation eliminates any saved setting for the variable,
2718 restoring it to the state of a variable that has never been customized.
2719 The value that was current before this operation
2720 becomes the backup value, so you can get it again."
2721 (let* ((symbol (widget-value widget))
2722 (set (or (get symbol 'custom-set) 'set-default)))
2723 (if (get symbol 'standard-value)
2724 (progn
2725 (custom-variable-backup-value widget)
2726 (funcall set symbol (eval (car (get symbol 'standard-value)))))
2727 (error "No standard setting known for %S" symbol))
2728 (put symbol 'variable-comment nil)
2729 (put symbol 'customized-value nil)
2730 (put symbol 'customized-variable-comment nil)
2731 (when (or (get symbol 'saved-value) (get symbol 'saved-variable-comment))
2732 (put symbol 'saved-value nil)
2733 (custom-push-theme 'theme-value symbol 'user 'reset 'standard)
2734 ;; As a special optimizations we do not (explictly)
2735 ;; save resets to standard when no theme set the value.
2736 (if (null (cdr (get symbol 'theme-value)))
2737 (put symbol 'theme-value nil))
2738 (put symbol 'saved-variable-comment nil)
2739 (custom-save-all))
2740 (widget-put widget :custom-state 'unknown)
2741 ;; This call will possibly make the comment invisible
2742 (custom-redraw widget)))
2744 (defun custom-variable-backup-value (widget)
2745 "Back up the current value for WIDGET's variable.
2746 The backup value is kept in the car of the `backup-value' property."
2747 (let* ((symbol (widget-value widget))
2748 (get (or (get symbol 'custom-get) 'default-value))
2749 (type (custom-variable-type symbol))
2750 (conv (widget-convert type))
2751 (value (if (default-boundp symbol)
2752 (funcall get symbol)
2753 (widget-get conv :value))))
2754 (put symbol 'backup-value (list value))))
2756 (defun custom-variable-reset-backup (widget)
2757 "Restore the backup value for the variable being edited by WIDGET.
2758 The value that was current before this operation
2759 becomes the backup value, so you can use this operation repeatedly
2760 to switch between two values."
2761 (let* ((symbol (widget-value widget))
2762 (set (or (get symbol 'custom-set) 'set-default))
2763 (value (get symbol 'backup-value))
2764 (comment-widget (widget-get widget :comment-widget))
2765 (comment (widget-value comment-widget)))
2766 (if value
2767 (progn
2768 (custom-variable-backup-value widget)
2769 (condition-case nil
2770 (funcall set symbol (car value))
2771 (error nil)))
2772 (error "No backup value for %s" symbol))
2773 (put symbol 'customized-value (list (car value)))
2774 (put symbol 'variable-comment comment)
2775 (put symbol 'customized-variable-comment comment)
2776 (custom-variable-state-set widget)
2777 ;; This call will possibly make the comment invisible
2778 (custom-redraw widget)))
2780 ;;; The `custom-face-edit' Widget.
2782 (define-widget 'custom-face-edit 'checklist
2783 "Edit face attributes."
2784 :format "%t: %v"
2785 :tag "Attributes"
2786 :extra-offset 13
2787 :button-args '(:help-echo "Control whether this attribute has any effect.")
2788 :value-to-internal 'custom-face-edit-fix-value
2789 :match (lambda (widget value)
2790 (widget-checklist-match widget
2791 (custom-face-edit-fix-value widget value)))
2792 :convert-widget 'custom-face-edit-convert-widget
2793 :args (mapcar (lambda (att)
2794 (list 'group
2795 :inline t
2796 :sibling-args (widget-get (nth 1 att) :sibling-args)
2797 (list 'const :format "" :value (nth 0 att))
2798 (nth 1 att)))
2799 custom-face-attributes))
2801 (defun custom-face-edit-fix-value (widget value)
2802 "Ignoring WIDGET, convert :bold and :italic in VALUE to new form.
2803 Also change :reverse-video to :inverse-video."
2804 (if (listp value)
2805 (let (result)
2806 (while value
2807 (let ((key (car value))
2808 (val (car (cdr value))))
2809 (cond ((eq key :italic)
2810 (push :slant result)
2811 (push (if val 'italic 'normal) result))
2812 ((eq key :bold)
2813 (push :weight result)
2814 (push (if val 'bold 'normal) result))
2815 ((eq key :reverse-video)
2816 (push :inverse-video result)
2817 (push val result))
2819 (push key result)
2820 (push val result))))
2821 (setq value (cdr (cdr value))))
2822 (setq result (nreverse result))
2823 result)
2824 value))
2826 (defun custom-face-edit-convert-widget (widget)
2827 "Convert :args as widget types in WIDGET."
2828 (widget-put
2829 widget
2830 :args (mapcar (lambda (arg)
2831 (widget-convert arg
2832 :deactivate 'custom-face-edit-deactivate
2833 :activate 'custom-face-edit-activate
2834 :delete 'custom-face-edit-delete))
2835 (widget-get widget :args)))
2836 widget)
2838 (defun custom-face-edit-deactivate (widget)
2839 "Make face widget WIDGET inactive for user modifications."
2840 (unless (widget-get widget :inactive)
2841 (let ((tag (custom-face-edit-attribute-tag widget))
2842 (from (copy-marker (widget-get widget :from)))
2843 (value (widget-value widget))
2844 (inhibit-read-only t)
2845 (inhibit-modification-hooks t))
2846 (save-excursion
2847 (goto-char from)
2848 (widget-default-delete widget)
2849 (insert tag ": *\n")
2850 (widget-put widget :inactive
2851 (cons value (cons from (- (point) from))))))))
2853 (defun custom-face-edit-activate (widget)
2854 "Make face widget WIDGET inactive for user modifications."
2855 (let ((inactive (widget-get widget :inactive))
2856 (inhibit-read-only t)
2857 (inhibit-modification-hooks t))
2858 (when (consp inactive)
2859 (save-excursion
2860 (goto-char (car (cdr inactive)))
2861 (delete-region (point) (+ (point) (cdr (cdr inactive))))
2862 (widget-put widget :inactive nil)
2863 (widget-apply widget :create)
2864 (widget-value-set widget (car inactive))
2865 (widget-setup)))))
2867 (defun custom-face-edit-delete (widget)
2868 "Remove WIDGET from the buffer."
2869 (let ((inactive (widget-get widget :inactive))
2870 (inhibit-read-only t)
2871 (inhibit-modification-hooks t))
2872 (if (not inactive)
2873 ;; Widget is alive, we don't have to do anything special
2874 (widget-default-delete widget)
2875 ;; WIDGET is already deleted because we did so to inactivate it;
2876 ;; now just get rid of the label we put in its place.
2877 (delete-region (car (cdr inactive))
2878 (+ (car (cdr inactive)) (cdr (cdr inactive))))
2879 (widget-put widget :inactive nil))))
2882 (defun custom-face-edit-attribute-tag (widget)
2883 "Returns the first :tag property in WIDGET or one of its children."
2884 (let ((tag (widget-get widget :tag)))
2885 (or (and (not (equal tag "")) tag)
2886 (let ((children (widget-get widget :children)))
2887 (while (and (null tag) children)
2888 (setq tag (custom-face-edit-attribute-tag (pop children))))
2889 tag))))
2891 ;;; The `custom-display' Widget.
2893 (define-widget 'custom-display 'menu-choice
2894 "Select a display type."
2895 :tag "Display"
2896 :value t
2897 :help-echo "Specify frames where the face attributes should be used."
2898 :args '((const :tag "all" t)
2899 (const :tag "defaults" default)
2900 (checklist
2901 :offset 0
2902 :extra-offset 9
2903 :args ((group :sibling-args (:help-echo "\
2904 Only match the specified window systems.")
2905 (const :format "Type: "
2906 type)
2907 (checklist :inline t
2908 :offset 0
2909 (const :format "X "
2910 :sibling-args (:help-echo "\
2911 The X11 Window System.")
2913 (const :format "PM "
2914 :sibling-args (:help-echo "\
2915 OS/2 Presentation Manager.")
2917 (const :format "W32 "
2918 :sibling-args (:help-echo "\
2919 Windows NT/9X.")
2920 w32)
2921 (const :format "MAC "
2922 :sibling-args (:help-echo "\
2923 Macintosh OS.")
2924 mac)
2925 (const :format "DOS "
2926 :sibling-args (:help-echo "\
2927 Plain MS-DOS.")
2929 (const :format "TTY%n"
2930 :sibling-args (:help-echo "\
2931 Plain text terminals.")
2932 tty)))
2933 (group :sibling-args (:help-echo "\
2934 Only match the frames with the specified color support.")
2935 (const :format "Class: "
2936 class)
2937 (checklist :inline t
2938 :offset 0
2939 (const :format "Color "
2940 :sibling-args (:help-echo "\
2941 Match color frames.")
2942 color)
2943 (const :format "Grayscale "
2944 :sibling-args (:help-echo "\
2945 Match grayscale frames.")
2946 grayscale)
2947 (const :format "Monochrome%n"
2948 :sibling-args (:help-echo "\
2949 Match frames with no color support.")
2950 mono)))
2951 (group :sibling-args (:help-echo "\
2952 The minimum number of colors the frame should support.")
2953 (const :format "" min-colors)
2954 (integer :tag "Minimum number of colors" ))
2955 (group :sibling-args (:help-echo "\
2956 Only match frames with the specified intensity.")
2957 (const :format "\
2958 Background brightness: "
2959 background)
2960 (checklist :inline t
2961 :offset 0
2962 (const :format "Light "
2963 :sibling-args (:help-echo "\
2964 Match frames with light backgrounds.")
2965 light)
2966 (const :format "Dark\n"
2967 :sibling-args (:help-echo "\
2968 Match frames with dark backgrounds.")
2969 dark)))
2970 (group :sibling-args (:help-echo "\
2971 Only match frames that support the specified face attributes.")
2972 (const :format "Supports attributes:" supports)
2973 (custom-face-edit :inline t :format "%n%v"))))))
2975 ;;; The `custom-face' Widget.
2977 (defface custom-face-tag
2978 `((t (:weight bold :height 1.2 :inherit variable-pitch)))
2979 "Face used for face tags."
2980 :group 'custom-faces)
2981 ;; backward-compatibility alias
2982 (put 'custom-face-tag-face 'face-alias 'custom-face-tag)
2984 (defcustom custom-face-default-form 'selected
2985 "Default form of displaying face definition."
2986 :type '(choice (const all)
2987 (const selected)
2988 (const lisp))
2989 :group 'custom-buffer
2990 :version "20.3")
2992 (define-widget 'custom-face 'custom
2993 "Customize face."
2994 :sample-face 'custom-face-tag-face
2995 :help-echo "Set or reset this face."
2996 :documentation-property #'face-doc-string
2997 :value-create 'custom-face-value-create
2998 :action 'custom-face-action
2999 :custom-category 'face
3000 :custom-form nil ; defaults to value of `custom-face-default-form'
3001 :custom-set 'custom-face-set
3002 :custom-save 'custom-face-save
3003 :custom-reset-current 'custom-redraw
3004 :custom-reset-saved 'custom-face-reset-saved
3005 :custom-reset-standard 'custom-face-reset-standard
3006 :custom-standard-value 'custom-face-standard-value
3007 :custom-menu 'custom-face-menu-create)
3009 (define-widget 'custom-face-all 'editable-list
3010 "An editable list of display specifications and attributes."
3011 :entry-format "%i %d %v"
3012 :insert-button-args '(:help-echo "Insert new display specification here.")
3013 :append-button-args '(:help-echo "Append new display specification here.")
3014 :delete-button-args '(:help-echo "Delete this display specification.")
3015 :args '((group :format "%v" custom-display custom-face-edit)))
3017 (defconst custom-face-all (widget-convert 'custom-face-all)
3018 "Converted version of the `custom-face-all' widget.")
3020 (define-widget 'custom-display-unselected 'item
3021 "A display specification that doesn't match the selected display."
3022 :match 'custom-display-unselected-match)
3024 (defun custom-display-unselected-match (widget value)
3025 "Non-nil if VALUE is an unselected display specification."
3026 (not (face-spec-set-match-display value (selected-frame))))
3028 (define-widget 'custom-face-selected 'group
3029 "Edit the attributes of the selected display in a face specification."
3030 :args '((choice :inline t
3031 (group :tag "With Defaults" :inline t
3032 (group (const :tag "" default)
3033 (custom-face-edit :tag " Default\n Attributes"))
3034 (repeat :format ""
3035 :inline t
3036 (group custom-display-unselected sexp))
3037 (group (sexp :format "")
3038 (custom-face-edit :tag " Overriding\n Attributes"))
3039 (repeat :format ""
3040 :inline t
3041 sexp))
3042 (group :tag "No Defaults" :inline t
3043 (repeat :format ""
3044 :inline t
3045 (group custom-display-unselected sexp))
3046 (group (sexp :format "")
3047 (custom-face-edit :tag "\n Attributes"))
3048 (repeat :format ""
3049 :inline t
3050 sexp)))))
3054 (defconst custom-face-selected (widget-convert 'custom-face-selected)
3055 "Converted version of the `custom-face-selected' widget.")
3057 (defun custom-filter-face-spec (spec filter-index &optional default-filter)
3058 "Return a canonicalized version of SPEC using.
3059 FILTER-INDEX is the index in the entry for each attribute in
3060 `custom-face-attributes' at which the appropriate filter function can be
3061 found, and DEFAULT-FILTER is the filter to apply for attributes that
3062 don't specify one."
3063 (mapcar (lambda (entry)
3064 ;; Filter a single face-spec entry
3065 (let ((tests (car entry))
3066 (unfiltered-attrs
3067 ;; Handle both old- and new-style attribute syntax
3068 (if (listp (car (cdr entry)))
3069 (car (cdr entry))
3070 (cdr entry)))
3071 (filtered-attrs nil))
3072 ;; Filter each face attribute
3073 (while unfiltered-attrs
3074 (let* ((attr (pop unfiltered-attrs))
3075 (pre-filtered-value (pop unfiltered-attrs))
3076 (filter
3077 (or (nth filter-index (assq attr custom-face-attributes))
3078 default-filter))
3079 (filtered-value
3080 (if filter
3081 (funcall filter pre-filtered-value)
3082 pre-filtered-value)))
3083 (push filtered-value filtered-attrs)
3084 (push attr filtered-attrs)))
3086 (list tests filtered-attrs)))
3087 spec))
3089 (defun custom-pre-filter-face-spec (spec)
3090 "Return SPEC changed as necessary for editing by the face customization widget.
3091 SPEC must be a full face spec."
3092 (custom-filter-face-spec spec 2))
3094 (defun custom-post-filter-face-spec (spec)
3095 "Return the customized SPEC in a form suitable for setting the face."
3096 (custom-filter-face-spec spec 3))
3098 (defun custom-face-value-create (widget)
3099 "Create a list of the display specifications for WIDGET."
3100 (let ((buttons (widget-get widget :buttons))
3101 children
3102 (symbol (widget-get widget :value))
3103 (tag (widget-get widget :tag))
3104 (state (widget-get widget :custom-state))
3105 (begin (point))
3106 (is-last (widget-get widget :custom-last))
3107 (prefix (widget-get widget :custom-prefix)))
3108 (unless tag
3109 (setq tag (prin1-to-string symbol)))
3110 (cond ((eq custom-buffer-style 'tree)
3111 (insert prefix (if is-last " `--- " " |--- "))
3112 (push (widget-create-child-and-convert
3113 widget 'custom-browse-face-tag)
3114 buttons)
3115 (insert " " tag "\n")
3116 (widget-put widget :buttons buttons))
3118 ;; Create tag.
3119 (insert tag)
3120 (widget-specify-sample widget begin (point))
3121 (if (eq custom-buffer-style 'face)
3122 (insert " ")
3123 (if (string-match "face\\'" tag)
3124 (insert ":")
3125 (insert " face: ")))
3126 ;; Sample.
3127 (push (widget-create-child-and-convert widget 'item
3128 :format "(%{%t%})"
3129 :sample-face symbol
3130 :tag "sample")
3131 buttons)
3132 ;; Visibility.
3133 (insert " ")
3134 (push (widget-create-child-and-convert
3135 widget 'visibility
3136 :help-echo "Hide or show this face."
3137 :on "Hide Face"
3138 :off "Show Face"
3139 :action 'custom-toggle-parent
3140 (not (eq state 'hidden)))
3141 buttons)
3142 ;; Magic.
3143 (insert "\n")
3144 (let ((magic (widget-create-child-and-convert
3145 widget 'custom-magic nil)))
3146 (widget-put widget :custom-magic magic)
3147 (push magic buttons))
3148 ;; Update buttons.
3149 (widget-put widget :buttons buttons)
3150 ;; Insert documentation.
3151 (widget-default-format-handler widget ?h)
3152 ;; The comment field
3153 (unless (eq state 'hidden)
3154 (let* ((comment (get symbol 'face-comment))
3155 (comment-widget
3156 (widget-create-child-and-convert
3157 widget 'custom-comment
3158 :parent widget
3159 :value (or comment ""))))
3160 (widget-put widget :comment-widget comment-widget)
3161 (push comment-widget children)))
3162 ;; See also.
3163 (unless (eq state 'hidden)
3164 (when (eq (widget-get widget :custom-level) 1)
3165 (custom-add-parent-links widget))
3166 (custom-add-see-also widget))
3167 ;; Editor.
3168 (unless (eq (preceding-char) ?\n)
3169 (insert "\n"))
3170 (unless (eq state 'hidden)
3171 (message "Creating face editor...")
3172 (custom-load-widget widget)
3173 (unless (widget-get widget :custom-form)
3174 (widget-put widget :custom-form custom-face-default-form))
3175 (let* ((symbol (widget-value widget))
3176 (spec (or (get symbol 'customized-face)
3177 (get symbol 'saved-face)
3178 (get symbol 'face-defface-spec)
3179 ;; Attempt to construct it.
3180 (list (list t (custom-face-attributes-get
3181 symbol (selected-frame))))))
3182 (form (widget-get widget :custom-form))
3183 (indent (widget-get widget :indent))
3184 edit)
3185 ;; If the user has changed this face in some other way,
3186 ;; edit it as the user has specified it.
3187 (if (not (face-spec-match-p symbol spec (selected-frame)))
3188 (setq spec (list (list t (face-attr-construct symbol (selected-frame))))))
3189 (setq spec (custom-pre-filter-face-spec spec))
3190 (setq edit (widget-create-child-and-convert
3191 widget
3192 (cond ((and (eq form 'selected)
3193 (widget-apply custom-face-selected
3194 :match spec))
3195 (when indent (insert-char ?\ indent))
3196 'custom-face-selected)
3197 ((and (not (eq form 'lisp))
3198 (widget-apply custom-face-all
3199 :match spec))
3200 'custom-face-all)
3202 (when indent (insert-char ?\ indent))
3203 'sexp))
3204 :value spec))
3205 (custom-face-state-set widget)
3206 (push edit children)
3207 (widget-put widget :children children))
3208 (message "Creating face editor...done"))))))
3210 (defvar custom-face-menu
3211 '(("Set for Current Session" custom-face-set)
3212 ("Save for Future Sessions" custom-face-save-command)
3213 ("Reset to Saved" custom-face-reset-saved
3214 (lambda (widget)
3215 (or (get (widget-value widget) 'saved-face)
3216 (get (widget-value widget) 'saved-face-comment))))
3217 ("Erase Customization" custom-face-reset-standard
3218 (lambda (widget)
3219 (get (widget-value widget) 'face-defface-spec)))
3220 ("---" ignore ignore)
3221 ("Add Comment" custom-comment-show custom-comment-invisible-p)
3222 ("---" ignore ignore)
3223 ("Show all display specs" custom-face-edit-all
3224 (lambda (widget)
3225 (not (eq (widget-get widget :custom-form) 'all))))
3226 ("Just current attributes" custom-face-edit-selected
3227 (lambda (widget)
3228 (not (eq (widget-get widget :custom-form) 'selected))))
3229 ("Show as Lisp expression" custom-face-edit-lisp
3230 (lambda (widget)
3231 (not (eq (widget-get widget :custom-form) 'lisp)))))
3232 "Alist of actions for the `custom-face' widget.
3233 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3234 the menu entry, ACTION is the function to call on the widget when the
3235 menu is selected, and FILTER is a predicate which takes a `custom-face'
3236 widget as an argument, and returns non-nil if ACTION is valid on that
3237 widget. If FILTER is nil, ACTION is always valid.")
3239 (defun custom-face-edit-selected (widget)
3240 "Edit selected attributes of the value of WIDGET."
3241 (widget-put widget :custom-state 'unknown)
3242 (widget-put widget :custom-form 'selected)
3243 (custom-redraw widget))
3245 (defun custom-face-edit-all (widget)
3246 "Edit all attributes of the value of WIDGET."
3247 (widget-put widget :custom-state 'unknown)
3248 (widget-put widget :custom-form 'all)
3249 (custom-redraw widget))
3251 (defun custom-face-edit-lisp (widget)
3252 "Edit the Lisp representation of the value of WIDGET."
3253 (widget-put widget :custom-state 'unknown)
3254 (widget-put widget :custom-form 'lisp)
3255 (custom-redraw widget))
3257 (defun custom-face-state-set (widget)
3258 "Set the state of WIDGET."
3259 (let* ((symbol (widget-value widget))
3260 (comment (get symbol 'face-comment))
3261 tmp temp
3262 (state
3263 (cond ((progn
3264 (setq tmp (get symbol 'customized-face))
3265 (setq temp (get symbol 'customized-face-comment))
3266 (or tmp temp))
3267 (if (equal temp comment)
3268 'set
3269 'changed))
3270 ((progn
3271 (setq tmp (get symbol 'saved-face))
3272 (setq temp (get symbol 'saved-face-comment))
3273 (or tmp temp))
3274 (if (equal temp comment)
3275 'saved
3276 'changed))
3277 ((get symbol 'face-defface-spec)
3278 (if (equal comment nil)
3279 'standard
3280 'changed))
3282 'rogue))))
3283 ;; If the user called set-face-attribute to change the default
3284 ;; for new frames, this face is "set outside of Customize".
3285 (if (and (not (eq state 'rogue))
3286 (get symbol 'face-modified))
3287 (setq state 'changed))
3288 (widget-put widget :custom-state state)))
3290 (defun custom-face-action (widget &optional event)
3291 "Show the menu for `custom-face' WIDGET.
3292 Optional EVENT is the location for the menu."
3293 (if (eq (widget-get widget :custom-state) 'hidden)
3294 (custom-toggle-hide widget)
3295 (let* ((completion-ignore-case t)
3296 (symbol (widget-get widget :value))
3297 (answer (widget-choose (concat "Operation on "
3298 (custom-unlispify-tag-name symbol))
3299 (custom-menu-filter custom-face-menu
3300 widget)
3301 event)))
3302 (if answer
3303 (funcall answer widget)))))
3305 (defun custom-face-set (widget)
3306 "Make the face attributes in WIDGET take effect."
3307 (let* ((symbol (widget-value widget))
3308 (child (car (widget-get widget :children)))
3309 (value (custom-post-filter-face-spec (widget-value child)))
3310 (comment-widget (widget-get widget :comment-widget))
3311 (comment (widget-value comment-widget)))
3312 (when (equal comment "")
3313 (setq comment nil)
3314 ;; Make the comment invisible by hand if it's empty
3315 (custom-comment-hide comment-widget))
3316 (put symbol 'customized-face value)
3317 (if (face-spec-choose value)
3318 (face-spec-set symbol value)
3319 ;; face-set-spec ignores empty attribute lists, so just give it
3320 ;; something harmless instead.
3321 (face-spec-set symbol '((t :foreground unspecified))))
3322 (put symbol 'customized-face-comment comment)
3323 (put symbol 'face-comment comment)
3324 (custom-face-state-set widget)
3325 (custom-redraw-magic widget)))
3327 (defun custom-face-save-command (widget)
3328 "Save in `.emacs' the face attributes in WIDGET."
3329 (custom-face-save widget)
3330 (custom-save-all))
3332 (defun custom-face-save (widget)
3333 "Prepare for saving WIDGET's face attributes, but don't write `.emacs'."
3334 (let* ((symbol (widget-value widget))
3335 (child (car (widget-get widget :children)))
3336 (value (custom-post-filter-face-spec (widget-value child)))
3337 (comment-widget (widget-get widget :comment-widget))
3338 (comment (widget-value comment-widget)))
3339 (when (equal comment "")
3340 (setq comment nil)
3341 ;; Make the comment invisible by hand if it's empty
3342 (custom-comment-hide comment-widget))
3343 (if (face-spec-choose value)
3344 (face-spec-set symbol value)
3345 ;; face-set-spec ignores empty attribute lists, so just give it
3346 ;; something harmless instead.
3347 (face-spec-set symbol '((t :foreground unspecified))))
3348 (unless (eq (widget-get widget :custom-state) 'standard)
3349 (put symbol 'saved-face value))
3350 (custom-push-theme 'theme-face symbol 'user 'set value)
3351 (put symbol 'customized-face nil)
3352 (put symbol 'face-comment comment)
3353 (put symbol 'customized-face-comment nil)
3354 (put symbol 'saved-face-comment comment)
3355 (custom-save-all)
3356 (custom-face-state-set widget)
3357 (custom-redraw-magic widget)))
3359 (defun custom-face-reset-saved (widget)
3360 "Restore WIDGET to the face's default attributes."
3361 (let* ((symbol (widget-value widget))
3362 (child (car (widget-get widget :children)))
3363 (value (get symbol 'saved-face))
3364 (comment (get symbol 'saved-face-comment))
3365 (comment-widget (widget-get widget :comment-widget)))
3366 (unless (or value comment)
3367 (error "No saved value for this face"))
3368 (put symbol 'customized-face nil)
3369 (put symbol 'customized-face-comment nil)
3370 (face-spec-set symbol value)
3371 (put symbol 'face-comment comment)
3372 (widget-value-set child value)
3373 ;; This call manages the comment visibility
3374 (widget-value-set comment-widget (or comment ""))
3375 (custom-face-state-set widget)
3376 (custom-redraw-magic widget)))
3378 (defun custom-face-standard-value (widget)
3379 (get (widget-value widget) 'face-defface-spec))
3381 (defun custom-face-reset-standard (widget)
3382 "Restore WIDGET to the face's standard settings.
3383 This operation eliminates any saved setting for the face,
3384 restoring it to the state of a face that has never been customized."
3385 (let* ((symbol (widget-value widget))
3386 (child (car (widget-get widget :children)))
3387 (value (get symbol 'face-defface-spec))
3388 (comment-widget (widget-get widget :comment-widget)))
3389 (unless value
3390 (error "No standard setting for this face"))
3391 (put symbol 'customized-face nil)
3392 (put symbol 'customized-face-comment nil)
3393 (when (or (get symbol 'saved-face) (get symbol 'saved-face-comment))
3394 (put symbol 'saved-face nil)
3395 (custom-push-theme 'theme-face symbol 'user 'reset 'standard)
3396 ;; Do not explictly save resets to standards without themes.
3397 (if (null (cdr (get symbol 'theme-face)))
3398 (put symbol 'theme-face nil))
3399 (put symbol 'saved-face-comment nil)
3400 (custom-save-all))
3401 (face-spec-set symbol value)
3402 (put symbol 'face-comment nil)
3403 (widget-value-set child value)
3404 ;; This call manages the comment visibility
3405 (widget-value-set comment-widget "")
3406 (custom-face-state-set widget)
3407 (custom-redraw-magic widget)))
3409 ;;; The `face' Widget.
3411 (defvar widget-face-prompt-value-history nil
3412 "History of input to `widget-face-prompt-value'.")
3414 (define-widget 'face 'symbol
3415 "A Lisp face name (with sample)."
3416 :format "%{%t%}: (%{sample%}) %v"
3417 :tag "Face"
3418 :value 'default
3419 :sample-face-get 'widget-face-sample-face-get
3420 :notify 'widget-face-notify
3421 :match (lambda (widget value) (facep value))
3422 :complete-function (lambda ()
3423 (interactive)
3424 (lisp-complete-symbol 'facep))
3425 :prompt-match 'facep
3426 :prompt-history 'widget-face-prompt-value-history
3427 :validate (lambda (widget)
3428 (unless (facep (widget-value widget))
3429 (widget-put widget
3430 :error (format "Invalid face: %S"
3431 (widget-value widget)))
3432 widget)))
3434 (defun widget-face-sample-face-get (widget)
3435 (let ((value (widget-value widget)))
3436 (if (facep value)
3437 value
3438 'default)))
3440 (defun widget-face-notify (widget child &optional event)
3441 "Update the sample, and notify the parent."
3442 (overlay-put (widget-get widget :sample-overlay)
3443 'face (widget-apply widget :sample-face-get))
3444 (widget-default-notify widget child event))
3447 ;;; The `hook' Widget.
3449 (define-widget 'hook 'list
3450 "A emacs lisp hook"
3451 :value-to-internal (lambda (widget value)
3452 (if (and value (symbolp value))
3453 (list value)
3454 value))
3455 :match (lambda (widget value)
3456 (or (symbolp value)
3457 (widget-group-match widget value)))
3458 ;; Avoid adding undefined functions to the hook, especially for
3459 ;; things like `find-file-hook' or even more basic ones, to avoid
3460 ;; chaos.
3461 :set (lambda (symbol value)
3462 (dolist (elt value)
3463 (if (fboundp elt)
3464 (add-hook symbol elt))))
3465 :convert-widget 'custom-hook-convert-widget
3466 :tag "Hook")
3468 (defun custom-hook-convert-widget (widget)
3469 ;; Handle `:options'.
3470 (let* ((options (widget-get widget :options))
3471 (other `(editable-list :inline t
3472 :entry-format "%i %d%v"
3473 (function :format " %v")))
3474 (args (if options
3475 (list `(checklist :inline t
3476 ,@(mapcar (lambda (entry)
3477 `(function-item ,entry))
3478 options))
3479 other)
3480 (list other))))
3481 (widget-put widget :args args)
3482 widget))
3484 ;;; The `custom-group-link' Widget.
3486 (define-widget 'custom-group-link 'link
3487 "Show parent in other window when activated."
3488 :help-echo "Create customization buffer for this group."
3489 :action 'custom-group-link-action)
3491 (defun custom-group-link-action (widget &rest ignore)
3492 (customize-group (widget-value widget)))
3494 ;;; The `custom-group' Widget.
3496 (defcustom custom-group-tag-faces nil
3497 ;; In XEmacs, this ought to play games with font size.
3498 ;; Fixme: make it do so in Emacs.
3499 "Face used for group tags.
3500 The first member is used for level 1 groups, the second for level 2,
3501 and so forth. The remaining group tags are shown with `custom-group-tag'."
3502 :type '(repeat face)
3503 :group 'custom-faces)
3505 (defface custom-group-tag-1
3506 `((((class color)
3507 (background dark))
3508 (:foreground "pink" :weight bold :height 1.2 :inherit variable-pitch))
3509 (((min-colors 88) (class color)
3510 (background light))
3511 (:foreground "red1" :weight bold :height 1.2 :inherit variable-pitch))
3512 (((class color)
3513 (background light))
3514 (:foreground "red" :weight bold :height 1.2 :inherit variable-pitch))
3515 (t (:weight bold)))
3516 "Face used for group tags."
3517 :group 'custom-faces)
3518 ;; backward-compatibility alias
3519 (put 'custom-group-tag-face-1 'face-alias 'custom-group-tag-1)
3521 (defface custom-group-tag
3522 `((((class color)
3523 (background dark))
3524 (:foreground "light blue" :weight bold :height 1.2))
3525 (((min-colors 88) (class color)
3526 (background light))
3527 (:foreground "blue1" :weight bold :height 1.2))
3528 (((class color)
3529 (background light))
3530 (:foreground "blue" :weight bold :height 1.2))
3531 (t (:weight bold)))
3532 "Face used for low level group tags."
3533 :group 'custom-faces)
3534 ;; backward-compatibility alias
3535 (put 'custom-group-tag-face 'face-alias 'custom-group-tag)
3537 (define-widget 'custom-group 'custom
3538 "Customize group."
3539 :format "%v"
3540 :sample-face-get 'custom-group-sample-face-get
3541 :documentation-property 'group-documentation
3542 :help-echo "Set or reset all members of this group."
3543 :value-create 'custom-group-value-create
3544 :action 'custom-group-action
3545 :custom-category 'group
3546 :custom-set 'custom-group-set
3547 :custom-save 'custom-group-save
3548 :custom-reset-current 'custom-group-reset-current
3549 :custom-reset-saved 'custom-group-reset-saved
3550 :custom-reset-standard 'custom-group-reset-standard
3551 :custom-menu 'custom-group-menu-create)
3553 (defun custom-group-sample-face-get (widget)
3554 ;; Use :sample-face.
3555 (or (nth (1- (widget-get widget :custom-level)) custom-group-tag-faces)
3556 'custom-group-tag))
3558 (define-widget 'custom-group-visibility 'visibility
3559 "An indicator and manipulator for hidden group contents."
3560 :create 'custom-group-visibility-create)
3562 (defun custom-group-visibility-create (widget)
3563 (let ((visible (widget-value widget)))
3564 (if visible
3565 (insert "--------")))
3566 (widget-default-create widget))
3568 (defun custom-group-members (symbol groups-only)
3569 "Return SYMBOL's custom group members.
3570 If GROUPS-ONLY non-nil, return only those members that are groups."
3571 (if (not groups-only)
3572 (get symbol 'custom-group)
3573 (let (members)
3574 (dolist (entry (get symbol 'custom-group))
3575 (when (eq (nth 1 entry) 'custom-group)
3576 (push entry members)))
3577 (nreverse members))))
3579 (defun custom-group-value-create (widget)
3580 "Insert a customize group for WIDGET in the current buffer."
3581 (unless (eq (widget-get widget :custom-state) 'hidden)
3582 (custom-load-widget widget))
3583 (let* ((state (widget-get widget :custom-state))
3584 (level (widget-get widget :custom-level))
3585 ;; (indent (widget-get widget :indent))
3586 (prefix (widget-get widget :custom-prefix))
3587 (buttons (widget-get widget :buttons))
3588 (tag (widget-get widget :tag))
3589 (symbol (widget-value widget))
3590 (members (custom-group-members symbol
3591 (and (eq custom-buffer-style 'tree)
3592 custom-browse-only-groups))))
3593 (cond ((and (eq custom-buffer-style 'tree)
3594 (eq state 'hidden)
3595 (or members (custom-unloaded-widget-p widget)))
3596 (custom-browse-insert-prefix prefix)
3597 (push (widget-create-child-and-convert
3598 widget 'custom-browse-visibility
3599 ;; :tag-glyph "plus"
3600 :tag "+")
3601 buttons)
3602 (insert "-- ")
3603 ;; (widget-glyph-insert nil "-- " "horizontal")
3604 (push (widget-create-child-and-convert
3605 widget 'custom-browse-group-tag)
3606 buttons)
3607 (insert " " tag "\n")
3608 (widget-put widget :buttons buttons))
3609 ((and (eq custom-buffer-style 'tree)
3610 (zerop (length members)))
3611 (custom-browse-insert-prefix prefix)
3612 (insert "[ ]-- ")
3613 ;; (widget-glyph-insert nil "[ ]" "empty")
3614 ;; (widget-glyph-insert nil "-- " "horizontal")
3615 (push (widget-create-child-and-convert
3616 widget 'custom-browse-group-tag)
3617 buttons)
3618 (insert " " tag "\n")
3619 (widget-put widget :buttons buttons))
3620 ((eq custom-buffer-style 'tree)
3621 (custom-browse-insert-prefix prefix)
3622 (if (zerop (length members))
3623 (progn
3624 (custom-browse-insert-prefix prefix)
3625 (insert "[ ]-- ")
3626 ;; (widget-glyph-insert nil "[ ]" "empty")
3627 ;; (widget-glyph-insert nil "-- " "horizontal")
3628 (push (widget-create-child-and-convert
3629 widget 'custom-browse-group-tag)
3630 buttons)
3631 (insert " " tag "\n")
3632 (widget-put widget :buttons buttons))
3633 (push (widget-create-child-and-convert
3634 widget 'custom-browse-visibility
3635 ;; :tag-glyph "minus"
3636 :tag "-")
3637 buttons)
3638 (insert "-\\ ")
3639 ;; (widget-glyph-insert nil "-\\ " "top")
3640 (push (widget-create-child-and-convert
3641 widget 'custom-browse-group-tag)
3642 buttons)
3643 (insert " " tag "\n")
3644 (widget-put widget :buttons buttons)
3645 (message "Creating group...")
3646 (let* ((members (custom-sort-items members
3647 custom-browse-sort-alphabetically
3648 custom-browse-order-groups))
3649 (prefixes (widget-get widget :custom-prefixes))
3650 (custom-prefix-list (custom-prefix-add symbol prefixes))
3651 (extra-prefix (if (widget-get widget :custom-last)
3653 " | "))
3654 (prefix (concat prefix extra-prefix))
3655 children entry)
3656 (while members
3657 (setq entry (car members)
3658 members (cdr members))
3659 (push (widget-create-child-and-convert
3660 widget (nth 1 entry)
3661 :group widget
3662 :tag (custom-unlispify-tag-name (nth 0 entry))
3663 :custom-prefixes custom-prefix-list
3664 :custom-level (1+ level)
3665 :custom-last (null members)
3666 :value (nth 0 entry)
3667 :custom-prefix prefix)
3668 children))
3669 (widget-put widget :children (reverse children)))
3670 (message "Creating group...done")))
3671 ;; Nested style.
3672 ((eq state 'hidden)
3673 ;; Create level indicator.
3674 (unless (eq custom-buffer-style 'links)
3675 (insert-char ?\ (* custom-buffer-indent (1- level)))
3676 (insert "-- "))
3677 ;; Create tag.
3678 (let ((begin (point)))
3679 (insert tag)
3680 (widget-specify-sample widget begin (point)))
3681 (insert " group: ")
3682 ;; Create link/visibility indicator.
3683 (if (eq custom-buffer-style 'links)
3684 (push (widget-create-child-and-convert
3685 widget 'custom-group-link
3686 :tag "Go to Group"
3687 symbol)
3688 buttons)
3689 (push (widget-create-child-and-convert
3690 widget 'custom-group-visibility
3691 :help-echo "Show members of this group."
3692 :action 'custom-toggle-parent
3693 (not (eq state 'hidden)))
3694 buttons))
3695 (insert " \n")
3696 ;; Create magic button.
3697 (let ((magic (widget-create-child-and-convert
3698 widget 'custom-magic nil)))
3699 (widget-put widget :custom-magic magic)
3700 (push magic buttons))
3701 ;; Update buttons.
3702 (widget-put widget :buttons buttons)
3703 ;; Insert documentation.
3704 (if (and (eq custom-buffer-style 'links) (> level 1))
3705 (widget-put widget :documentation-indent 0))
3706 (widget-default-format-handler widget ?h))
3707 ;; Nested style.
3708 (t ;Visible.
3709 ;; Add parent groups references above the group.
3710 (if t ;;; This should test that the buffer
3711 ;;; was made to display a group.
3712 (when (eq level 1)
3713 (if (custom-add-parent-links widget
3714 "Go to parent group:")
3715 (insert "\n"))))
3716 ;; Create level indicator.
3717 (insert-char ?\ (* custom-buffer-indent (1- level)))
3718 (insert "/- ")
3719 ;; Create tag.
3720 (let ((start (point)))
3721 (insert tag)
3722 (widget-specify-sample widget start (point)))
3723 (insert " group: ")
3724 ;; Create visibility indicator.
3725 (unless (eq custom-buffer-style 'links)
3726 (insert "--------")
3727 (push (widget-create-child-and-convert
3728 widget 'visibility
3729 :help-echo "Hide members of this group."
3730 :action 'custom-toggle-parent
3731 (not (eq state 'hidden)))
3732 buttons)
3733 (insert " "))
3734 ;; Create more dashes.
3735 ;; Use 76 instead of 75 to compensate for the temporary "<"
3736 ;; added by `widget-insert'.
3737 (insert-char ?- (- 76 (current-column)
3738 (* custom-buffer-indent level)))
3739 (insert "\\\n")
3740 ;; Create magic button.
3741 (let ((magic (widget-create-child-and-convert
3742 widget 'custom-magic
3743 :indent 0
3744 nil)))
3745 (widget-put widget :custom-magic magic)
3746 (push magic buttons))
3747 ;; Update buttons.
3748 (widget-put widget :buttons buttons)
3749 ;; Insert documentation.
3750 (widget-default-format-handler widget ?h)
3751 ;; Parent groups.
3752 (if nil ;;; This should test that the buffer
3753 ;;; was not made to display a group.
3754 (when (eq level 1)
3755 (insert-char ?\ custom-buffer-indent)
3756 (custom-add-parent-links widget)))
3757 (custom-add-see-also widget
3758 (make-string (* custom-buffer-indent level)
3759 ?\ ))
3760 ;; Members.
3761 (message "Creating group...")
3762 (let* ((members (custom-sort-items members
3763 custom-buffer-sort-alphabetically
3764 custom-buffer-order-groups))
3765 (prefixes (widget-get widget :custom-prefixes))
3766 (custom-prefix-list (custom-prefix-add symbol prefixes))
3767 (length (length members))
3768 (count 0)
3769 (children (mapcar (lambda (entry)
3770 (widget-insert "\n")
3771 (message "\
3772 Creating group members... %2d%%"
3773 (/ (* 100.0 count) length))
3774 (setq count (1+ count))
3775 (prog1
3776 (widget-create-child-and-convert
3777 widget (nth 1 entry)
3778 :group widget
3779 :tag (custom-unlispify-tag-name
3780 (nth 0 entry))
3781 :custom-prefixes custom-prefix-list
3782 :custom-level (1+ level)
3783 :value (nth 0 entry))
3784 (unless (eq (preceding-char) ?\n)
3785 (widget-insert "\n"))))
3786 members)))
3787 (message "Creating group magic...")
3788 (mapc 'custom-magic-reset children)
3789 (message "Creating group state...")
3790 (widget-put widget :children children)
3791 (custom-group-state-update widget)
3792 (message "Creating group... done"))
3793 ;; End line
3794 (insert "\n")
3795 (insert-char ?\ (* custom-buffer-indent (1- level)))
3796 (insert "\\- " (widget-get widget :tag) " group end ")
3797 (insert-char ?- (- 75 (current-column) (* custom-buffer-indent level)))
3798 (insert "/\n")))))
3800 (defvar custom-group-menu
3801 '(("Set for Current Session" custom-group-set
3802 (lambda (widget)
3803 (eq (widget-get widget :custom-state) 'modified)))
3804 ("Save for Future Sessions" custom-group-save
3805 (lambda (widget)
3806 (memq (widget-get widget :custom-state) '(modified set))))
3807 ("Reset to Current" custom-group-reset-current
3808 (lambda (widget)
3809 (memq (widget-get widget :custom-state) '(modified))))
3810 ("Reset to Saved" custom-group-reset-saved
3811 (lambda (widget)
3812 (memq (widget-get widget :custom-state) '(modified set))))
3813 ("Reset to standard setting" custom-group-reset-standard
3814 (lambda (widget)
3815 (memq (widget-get widget :custom-state) '(modified set saved)))))
3816 "Alist of actions for the `custom-group' widget.
3817 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3818 the menu entry, ACTION is the function to call on the widget when the
3819 menu is selected, and FILTER is a predicate which takes a `custom-group'
3820 widget as an argument, and returns non-nil if ACTION is valid on that
3821 widget. If FILTER is nil, ACTION is always valid.")
3823 (defun custom-group-action (widget &optional event)
3824 "Show the menu for `custom-group' WIDGET.
3825 Optional EVENT is the location for the menu."
3826 (if (eq (widget-get widget :custom-state) 'hidden)
3827 (custom-toggle-hide widget)
3828 (let* ((completion-ignore-case t)
3829 (answer (widget-choose (concat "Operation on "
3830 (custom-unlispify-tag-name
3831 (widget-get widget :value)))
3832 (custom-menu-filter custom-group-menu
3833 widget)
3834 event)))
3835 (if answer
3836 (funcall answer widget)))))
3838 (defun custom-group-set (widget)
3839 "Set changes in all modified group members."
3840 (let ((children (widget-get widget :children)))
3841 (mapc (lambda (child)
3842 (when (eq (widget-get child :custom-state) 'modified)
3843 (widget-apply child :custom-set)))
3844 children )))
3846 (defun custom-group-save (widget)
3847 "Save all modified group members."
3848 (let ((children (widget-get widget :children)))
3849 (mapc (lambda (child)
3850 (when (memq (widget-get child :custom-state) '(modified set))
3851 (widget-apply child :custom-save)))
3852 children )))
3854 (defun custom-group-reset-current (widget)
3855 "Reset all modified group members."
3856 (let ((children (widget-get widget :children)))
3857 (mapc (lambda (child)
3858 (when (eq (widget-get child :custom-state) 'modified)
3859 (widget-apply child :custom-reset-current)))
3860 children )))
3862 (defun custom-group-reset-saved (widget)
3863 "Reset all modified or set group members."
3864 (let ((children (widget-get widget :children)))
3865 (mapc (lambda (child)
3866 (when (memq (widget-get child :custom-state) '(modified set))
3867 (widget-apply child :custom-reset-saved)))
3868 children )))
3870 (defun custom-group-reset-standard (widget)
3871 "Reset all modified, set, or saved group members."
3872 (let ((children (widget-get widget :children)))
3873 (mapc (lambda (child)
3874 (when (memq (widget-get child :custom-state)
3875 '(modified set saved))
3876 (widget-apply child :custom-reset-standard)))
3877 children )))
3879 (defun custom-group-state-update (widget)
3880 "Update magic."
3881 (unless (eq (widget-get widget :custom-state) 'hidden)
3882 (let* ((children (widget-get widget :children))
3883 (states (mapcar (lambda (child)
3884 (widget-get child :custom-state))
3885 children))
3886 (magics custom-magic-alist)
3887 (found 'standard))
3888 (while magics
3889 (let ((magic (car (car magics))))
3890 (if (and (not (eq magic 'hidden))
3891 (memq magic states))
3892 (setq found magic
3893 magics nil)
3894 (setq magics (cdr magics)))))
3895 (widget-put widget :custom-state found)))
3896 (custom-magic-reset widget))
3898 ;;; Reading and writing the custom file.
3900 ;;;###autoload
3901 (defcustom custom-file nil
3902 "File used for storing customization information.
3903 The default is nil, which means to use your init file
3904 as specified by `user-init-file'. If the value is not nil,
3905 it should be an absolute file name.
3907 You can set this option through Custom, if you carefully read the
3908 last paragraph below. However, usually it is simpler to write
3909 something like the following in your init file:
3911 \(setq custom-file \"~/.emacs-custom.el\")
3912 \(load custom-file)
3914 Note that both lines are necessary: the first line tells Custom to
3915 save all customizations in this file, but does not load it.
3917 When you change this variable outside Custom, look in the
3918 previous custom file \(usually your init file) for the
3919 forms `(custom-set-variables ...)' and `(custom-set-faces ...)',
3920 and copy them (whichever ones you find) to the new custom file.
3921 This will preserve your existing customizations.
3923 If you save this option using Custom, Custom will write all
3924 currently saved customizations, including the new one for this
3925 option itself, into the file you specify, overwriting any
3926 `custom-set-variables' and `custom-set-faces' forms already
3927 present in that file. It will not delete any customizations from
3928 the old custom file. You should do that manually if that is what you
3929 want. You also have to put something like `\(load \"CUSTOM-FILE\")
3930 in your init file, where CUSTOM-FILE is the actual name of the
3931 file. Otherwise, Emacs will not load the file when it starts up,
3932 and hence will not set `custom-file' to that file either."
3933 :type '(choice (const :tag "Your Emacs init file" nil)
3934 (file :format "%t:%v%d"
3935 :doc
3936 "Please read entire docstring below before setting \
3937 this through Custom.
3938 Click om \"More\" \(or position point there and press RETURN)
3939 if only the first line of the docstring is shown."))
3940 :group 'customize)
3942 (defun custom-file ()
3943 "Return the file name for saving customizations."
3944 (file-chase-links
3945 (or custom-file
3946 (let ((user-init-file user-init-file)
3947 (default-init-file
3948 (if (eq system-type 'ms-dos) "~/_emacs" "~/.emacs")))
3949 (when (null user-init-file)
3950 (if (or (file-exists-p default-init-file)
3951 (and (eq system-type 'windows-nt)
3952 (file-exists-p "~/_emacs")))
3953 ;; Started with -q, i.e. the file containing
3954 ;; Custom settings hasn't been read. Saving
3955 ;; settings there would overwrite other settings.
3956 (error "Saving settings from \"emacs -q\" would overwrite existing customizations"))
3957 (setq user-init-file default-init-file))
3958 user-init-file))))
3960 ;;;###autoload
3961 (defun custom-save-all ()
3962 "Save all customizations in `custom-file'."
3963 (let* ((filename (custom-file))
3964 (recentf-exclude (if recentf-mode
3965 (cons (concat "\\`"
3966 (regexp-quote (custom-file))
3967 "\\'")
3968 recentf-exclude)))
3969 (old-buffer (find-buffer-visiting filename)))
3970 (with-current-buffer (or old-buffer (find-file-noselect filename))
3971 (let ((inhibit-read-only t))
3972 (custom-save-variables)
3973 (custom-save-faces))
3974 (let ((file-precious-flag t))
3975 (save-buffer))
3976 (unless old-buffer
3977 (kill-buffer (current-buffer))))))
3979 ;; Editing the custom file contents in a buffer.
3981 (defun custom-save-delete (symbol)
3982 "Delete all calls to SYMBOL from the contents of the current buffer.
3983 Leave point at the old location of the first such call,
3984 or (if there were none) at the end of the buffer.
3986 This function does not save the buffer."
3987 (goto-char (point-min))
3988 ;; Skip all whitespace and comments.
3989 (while (forward-comment 1))
3990 (or (eobp)
3991 (save-excursion (forward-sexp (buffer-size)))) ; Test for scan errors.
3992 (let (first)
3993 (catch 'found
3994 (while t ;; We exit this loop only via throw.
3995 ;; Skip all whitespace and comments.
3996 (while (forward-comment 1))
3997 (let ((start (point))
3998 (sexp (condition-case nil
3999 (read (current-buffer))
4000 (end-of-file (throw 'found nil)))))
4001 (when (and (listp sexp)
4002 (eq (car sexp) symbol))
4003 (delete-region start (point))
4004 (unless first
4005 (setq first (point)))))))
4006 (if first
4007 (goto-char first)
4008 ;; Move in front of local variables, otherwise long Custom
4009 ;; entries would make them ineffective.
4010 (let ((pos (point-max))
4011 (case-fold-search t))
4012 (save-excursion
4013 (goto-char (point-max))
4014 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
4015 'move)
4016 (when (search-forward "Local Variables:" nil t)
4017 (setq pos (line-beginning-position))))
4018 (goto-char pos)))))
4020 (defun custom-save-variables ()
4021 "Save all customized variables in `custom-file'."
4022 (save-excursion
4023 (custom-save-delete 'custom-load-themes)
4024 (custom-save-delete 'custom-reset-variables)
4025 (custom-save-delete 'custom-set-variables)
4026 (custom-save-loaded-themes)
4027 (custom-save-resets 'theme-value 'custom-reset-variables nil)
4028 (let ((standard-output (current-buffer))
4029 (saved-list (make-list 1 0))
4030 sort-fold-case)
4031 ;; First create a sorted list of saved variables.
4032 (mapatoms
4033 (lambda (symbol)
4034 (if (get symbol 'saved-value)
4035 (nconc saved-list (list symbol)))))
4036 (setq saved-list (sort (cdr saved-list) 'string<))
4037 (unless (bolp)
4038 (princ "\n"))
4039 (princ "(custom-set-variables
4040 ;; custom-set-variables was added by Custom.
4041 ;; If you edit it by hand, you could mess it up, so be careful.
4042 ;; Your init file should contain only one such instance.
4043 ;; If there is more than one, they won't work right.\n")
4044 (dolist (symbol saved-list)
4045 (let ((spec (car-safe (get symbol 'theme-value)))
4046 (value (get symbol 'saved-value))
4047 (requests (get symbol 'custom-requests))
4048 (now (not (or (custom-variable-p symbol)
4049 (and (not (boundp symbol))
4050 (not (eq (get symbol 'force-value)
4051 'rogue))))))
4052 (comment (get symbol 'saved-variable-comment)))
4053 ;; Check `requests'.
4054 (dolist (request requests)
4055 (when (and (symbolp request) (not (featurep request)))
4056 (message "Unknown requested feature: %s" request)
4057 (setq requests (delq request requests))))
4058 (when (or (and spec
4059 (eq (nth 0 spec) 'user)
4060 (eq (nth 1 spec) 'set))
4061 comment
4062 (and (null spec) (get symbol 'saved-value)))
4063 (unless (bolp)
4064 (princ "\n"))
4065 (princ " '(")
4066 (prin1 symbol)
4067 (princ " ")
4068 (prin1 (car value))
4069 (when (or now requests comment)
4070 (princ " ")
4071 (prin1 now)
4072 (when (or requests comment)
4073 (princ " ")
4074 (prin1 requests)
4075 (when comment
4076 (princ " ")
4077 (prin1 comment))))
4078 (princ ")"))))
4079 (if (bolp)
4080 (princ " "))
4081 (princ ")")
4082 (unless (looking-at "\n")
4083 (princ "\n")))))
4085 (defun custom-save-faces ()
4086 "Save all customized faces in `custom-file'."
4087 (save-excursion
4088 (custom-save-delete 'custom-reset-faces)
4089 (custom-save-delete 'custom-set-faces)
4090 (custom-save-resets 'theme-face 'custom-reset-faces '(default))
4091 (let ((standard-output (current-buffer))
4092 (saved-list (make-list 1 0))
4093 sort-fold-case)
4094 ;; First create a sorted list of saved faces.
4095 (mapatoms
4096 (lambda (symbol)
4097 (if (get symbol 'saved-face)
4098 (nconc saved-list (list symbol)))))
4099 (setq saved-list (sort (cdr saved-list) 'string<))
4100 ;; The default face must be first, since it affects the others.
4101 (if (memq 'default saved-list)
4102 (setq saved-list (cons 'default (delq 'default saved-list))))
4103 (unless (bolp)
4104 (princ "\n"))
4105 (princ "(custom-set-faces
4106 ;; custom-set-faces was added by Custom.
4107 ;; If you edit it by hand, you could mess it up, so be careful.
4108 ;; Your init file should contain only one such instance.
4109 ;; If there is more than one, they won't work right.\n")
4110 (dolist (symbol saved-list)
4111 (let ((spec (car-safe (get symbol 'theme-face)))
4112 (value (get symbol 'saved-face))
4113 (now (not (or (get symbol 'face-defface-spec)
4114 (and (not (custom-facep symbol))
4115 (not (get symbol 'force-face))))))
4116 (comment (get symbol 'saved-face-comment)))
4117 (when (or (and spec
4118 (eq (nth 0 spec) 'user)
4119 (eq (nth 1 spec) 'set))
4120 comment
4121 (and (null spec) (get symbol 'saved-face)))
4122 ;; Don't print default face here.
4123 (unless (bolp)
4124 (princ "\n"))
4125 (princ " '(")
4126 (prin1 symbol)
4127 (princ " ")
4128 (prin1 value)
4129 (when (or now comment)
4130 (princ " ")
4131 (prin1 now)
4132 (when comment
4133 (princ " ")
4134 (prin1 comment)))
4135 (princ ")"))))
4136 (if (bolp)
4137 (princ " "))
4138 (princ ")")
4139 (unless (looking-at "\n")
4140 (princ "\n")))))
4142 (defun custom-save-resets (property setter special)
4143 (let (started-writing ignored-special)
4144 ;; (custom-save-delete setter) Done by caller
4145 (let ((standard-output (current-buffer))
4146 (mapper `(lambda (object)
4147 (let ((spec (car-safe (get object (quote ,property)))))
4148 (when (and (not (memq object ignored-special))
4149 (eq (nth 0 spec) 'user)
4150 (eq (nth 1 spec) 'reset))
4151 ;; Do not write reset statements unless necessary.
4152 (unless started-writing
4153 (setq started-writing t)
4154 (unless (bolp)
4155 (princ "\n"))
4156 (princ "(")
4157 (princ (quote ,setter))
4158 (princ "\n '(")
4159 (prin1 object)
4160 (princ " ")
4161 (prin1 (nth 3 spec))
4162 (princ ")")))))))
4163 (mapc mapper special)
4164 (setq ignored-special special)
4165 (mapatoms mapper)
4166 (when started-writing
4167 (princ ")\n")))))
4169 (defun custom-save-loaded-themes ()
4170 (let ((themes (reverse (get 'user 'theme-loads-themes)))
4171 (standard-output (current-buffer)))
4172 (when themes
4173 (unless (bolp) (princ "\n"))
4174 (princ "(custom-load-themes")
4175 (mapc (lambda (theme)
4176 (princ "\n '")
4177 (prin1 theme)) themes)
4178 (princ " )\n"))))
4180 ;;;###autoload
4181 (defun customize-save-customized ()
4182 "Save all user options which have been set in this session."
4183 (interactive)
4184 (mapatoms (lambda (symbol)
4185 (let ((face (get symbol 'customized-face))
4186 (value (get symbol 'customized-value))
4187 (face-comment (get symbol 'customized-face-comment))
4188 (variable-comment
4189 (get symbol 'customized-variable-comment)))
4190 (when face
4191 (put symbol 'saved-face face)
4192 (custom-push-theme 'theme-face symbol 'user 'set value)
4193 (put symbol 'customized-face nil))
4194 (when value
4195 (put symbol 'saved-value value)
4196 (custom-push-theme 'theme-value symbol 'user 'set value)
4197 (put symbol 'customized-value nil))
4198 (when variable-comment
4199 (put symbol 'saved-variable-comment variable-comment)
4200 (put symbol 'customized-variable-comment nil))
4201 (when face-comment
4202 (put symbol 'saved-face-comment face-comment)
4203 (put symbol 'customized-face-comment nil)))))
4204 ;; We really should update all custom buffers here.
4205 (custom-save-all))
4207 ;;; The Customize Menu.
4209 ;;; Menu support
4211 (defcustom custom-menu-nesting 2
4212 "Maximum nesting in custom menus."
4213 :type 'integer
4214 :group 'custom-menu)
4216 (defun custom-face-menu-create (widget symbol)
4217 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
4218 (vector (custom-unlispify-menu-entry symbol)
4219 `(customize-face ',symbol)
4222 (defun custom-variable-menu-create (widget symbol)
4223 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
4224 (let ((type (get symbol 'custom-type)))
4225 (unless (listp type)
4226 (setq type (list type)))
4227 (if (and type (widget-get type :custom-menu))
4228 (widget-apply type :custom-menu symbol)
4229 (vector (custom-unlispify-menu-entry symbol)
4230 `(customize-variable ',symbol)
4231 t))))
4233 ;; Add checkboxes to boolean variable entries.
4234 (widget-put (get 'boolean 'widget-type)
4235 :custom-menu (lambda (widget symbol)
4236 (vector (custom-unlispify-menu-entry symbol)
4237 `(customize-variable ',symbol)
4238 ':style 'toggle
4239 ':selected symbol)))
4241 (defun custom-group-menu-create (widget symbol)
4242 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
4243 `( ,(custom-unlispify-menu-entry symbol t)
4244 :filter (lambda (&rest junk)
4245 (let ((menu (custom-menu-create ',symbol)))
4246 (if (consp menu) (cdr menu) menu)))))
4248 ;;;###autoload
4249 (defun custom-menu-create (symbol)
4250 "Create menu for customization group SYMBOL.
4251 The menu is in a format applicable to `easy-menu-define'."
4252 (let* ((item (vector (custom-unlispify-menu-entry symbol)
4253 `(customize-group ',symbol)
4254 t)))
4255 (if (and (or (not (boundp 'custom-menu-nesting))
4256 (>= custom-menu-nesting 0))
4257 (progn
4258 (custom-load-symbol symbol)
4259 (< (length (get symbol 'custom-group)) widget-menu-max-size)))
4260 (let ((custom-prefix-list (custom-prefix-add symbol
4261 custom-prefix-list))
4262 (members (custom-sort-items (get symbol 'custom-group)
4263 custom-menu-sort-alphabetically
4264 custom-menu-order-groups)))
4265 `(,(custom-unlispify-menu-entry symbol t)
4266 ,item
4267 "--"
4268 ,@(mapcar (lambda (entry)
4269 (widget-apply (if (listp (nth 1 entry))
4270 (nth 1 entry)
4271 (list (nth 1 entry)))
4272 :custom-menu (nth 0 entry)))
4273 members)))
4274 item)))
4276 ;;;###autoload
4277 (defun customize-menu-create (symbol &optional name)
4278 "Return a customize menu for customization group SYMBOL.
4279 If optional NAME is given, use that as the name of the menu.
4280 Otherwise the menu will be named `Customize'.
4281 The format is suitable for use with `easy-menu-define'."
4282 (unless name
4283 (setq name "Customize"))
4284 `(,name
4285 :filter (lambda (&rest junk)
4286 (let ((menu (custom-menu-create ',symbol)))
4287 (if (consp menu) (cdr menu) menu)))))
4289 ;;; The Custom Mode.
4291 (defvar custom-mode-map
4292 ;; This keymap should be dense, but a dense keymap would prevent inheriting
4293 ;; "\r" bindings from the parent map.
4294 ;; Actually, this misfeature of dense keymaps was fixed on 2001-11-26.
4295 (let ((map (make-keymap)))
4296 (set-keymap-parent map widget-keymap)
4297 (suppress-keymap map)
4298 (define-key map " " 'scroll-up)
4299 (define-key map "\177" 'scroll-down)
4300 (define-key map "\C-c\C-c" 'Custom-set)
4301 (define-key map "\C-x\C-s" 'Custom-save)
4302 (define-key map "q" 'Custom-buffer-done)
4303 (define-key map "u" 'Custom-goto-parent)
4304 (define-key map "n" 'widget-forward)
4305 (define-key map "p" 'widget-backward)
4306 (define-key map [mouse-1] 'widget-move-and-invoke)
4307 map)
4308 "Keymap for `custom-mode'.")
4310 (easy-menu-define Custom-mode-menu
4311 custom-mode-map
4312 "Menu used in customization buffers."
4313 `("Custom"
4314 ,(customize-menu-create 'customize)
4315 ["Set" Custom-set t]
4316 ["Save" Custom-save t]
4317 ["Reset to Current" Custom-reset-current t]
4318 ["Reset to Saved" Custom-reset-saved t]
4319 ["Reset to Standard Settings" Custom-reset-standard t]
4320 ["Info" (info "(emacs)Easy Customization") t]))
4322 (defun Custom-goto-parent ()
4323 "Go to the parent group listed at the top of this buffer.
4324 If several parents are listed, go to the first of them."
4325 (interactive)
4326 (save-excursion
4327 (goto-char (point-min))
4328 (if (search-forward "\nGo to parent group: " nil t)
4329 (let* ((button (get-char-property (point) 'button))
4330 (parent (downcase (widget-get button :tag))))
4331 (customize-group parent)))))
4333 (defcustom custom-mode-hook nil
4334 "Hook called when entering Custom mode."
4335 :type 'hook
4336 :group 'custom-buffer )
4338 (defun custom-state-buffer-message (widget)
4339 (if (eq (widget-get (widget-get widget :parent) :custom-state) 'modified)
4340 (message "To install your edits, invoke [State] and choose the Set operation")))
4342 (defun custom-mode ()
4343 "Major mode for editing customization buffers.
4345 The following commands are available:
4347 Move to next button or editable field. \\[widget-forward]
4348 Move to previous button or editable field. \\[widget-backward]
4349 \\<widget-field-keymap>\
4350 Complete content of editable text field. \\[widget-complete]
4351 \\<custom-mode-map>\
4352 Invoke button under the mouse pointer. \\[Custom-move-and-invoke]
4353 Invoke button under point. \\[widget-button-press]
4354 Set all modifications. \\[Custom-set]
4355 Make all modifications default. \\[Custom-save]
4356 Reset all modified options. \\[Custom-reset-current]
4357 Reset all modified or set options. \\[Custom-reset-saved]
4358 Reset all options. \\[Custom-reset-standard]
4360 Entry to this mode calls the value of `custom-mode-hook'
4361 if that value is non-nil."
4362 (kill-all-local-variables)
4363 (setq major-mode 'custom-mode
4364 mode-name "Custom")
4365 (use-local-map custom-mode-map)
4366 (easy-menu-add Custom-mode-menu)
4367 (make-local-variable 'custom-options)
4368 (make-local-variable 'custom-local-buffer)
4369 (make-local-variable 'widget-documentation-face)
4370 (setq widget-documentation-face 'custom-documentation)
4371 (make-local-variable 'widget-button-face)
4372 (setq widget-button-face custom-button)
4373 (set (make-local-variable 'widget-button-pressed-face) custom-button-pressed)
4374 (if custom-raised-buttons
4375 (set (make-local-variable 'widget-mouse-face) custom-button))
4377 ;; When possible, use relief for buttons, not bracketing. This test
4378 ;; may not be optimal.
4379 (when custom-raised-buttons
4380 (set (make-local-variable 'widget-push-button-prefix) "")
4381 (set (make-local-variable 'widget-push-button-suffix) "")
4382 (set (make-local-variable 'widget-link-prefix) "")
4383 (set (make-local-variable 'widget-link-suffix) ""))
4384 (add-hook 'widget-edit-functions 'custom-state-buffer-message nil t)
4385 (run-mode-hooks 'custom-mode-hook))
4387 (put 'custom-mode 'mode-class 'special)
4389 (add-to-list
4390 'debug-ignored-errors
4391 "^No user options have changed defaults in recent Emacs versions$")
4393 ;;; The End.
4395 (provide 'cus-edit)
4397 ;; arch-tag: 64533aa4-1b1a-48c3-8812-f9dc718e8a6f
4398 ;;; cus-edit.el ends here