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