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