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