Revision: emacs@sv.gnu.org/emacs--devo--0--patch-65
[emacs.git] / lisp / cus-edit.el
blob763b4b8c57f432b0647ef6fe93501fa44ba6633f
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 variables 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 'custom-manual
1474 :tag "Custom file"
1475 "(emacs)Saving Customizations")
1476 (widget-insert
1477 " for information on how to save in a different file.\n
1478 See ")
1479 (widget-create 'custom-manual
1480 :tag "Help"
1481 :help-echo "Read the online help."
1482 "(emacs)Easy Customization")
1483 (widget-insert " for more information.\n\n")
1484 (widget-insert "Operate on all settings in this buffer that \
1485 are not marked HIDDEN:\n "))
1486 (widget-insert " "))
1487 (widget-create 'push-button
1488 :tag "Set for Current Session"
1489 :help-echo "\
1490 Make your editing in this buffer take effect for this session."
1491 :action (lambda (widget &optional event)
1492 (Custom-set)))
1493 (if (not custom-buffer-verbose-help)
1494 (progn
1495 (widget-insert " ")
1496 (widget-create 'custom-manual
1497 :tag "Help"
1498 :help-echo "Read the online help."
1499 "(emacs)Easy Customization")))
1500 (when (or custom-file user-init-file)
1501 (widget-insert " ")
1502 (widget-create 'push-button
1503 :tag "Save for Future Sessions"
1504 :help-echo "\
1505 Make your editing in this buffer take effect for future Emacs sessions.
1506 This updates your Emacs initialization file or creates a new one."
1507 :action (lambda (widget &optional event)
1508 (Custom-save))))
1509 (if custom-reset-button-menu
1510 (progn
1511 (widget-insert " ")
1512 (widget-create 'push-button
1513 :tag "Reset buffer"
1514 :help-echo "Show a menu with reset operations."
1515 :mouse-down-action (lambda (&rest junk) t)
1516 :action (lambda (widget &optional event)
1517 (custom-reset event))))
1518 (widget-insert "\n ")
1519 (widget-create 'push-button
1520 :tag "Undo Edits"
1521 :help-echo "\
1522 Reset all edited text in this buffer to reflect current values."
1523 :action 'Custom-reset-current)
1524 (widget-insert " ")
1525 (widget-create 'push-button
1526 :tag "Reset to Saved"
1527 :help-echo "\
1528 Reset all settings in this buffer to their saved values."
1529 :action 'Custom-reset-saved)
1530 (widget-insert " ")
1531 (when (or custom-file user-init-file)
1532 (widget-create 'push-button
1533 :tag "Erase Customization"
1534 :help-echo "\
1535 Un-customize all settings in this buffer and save them with standard values."
1536 :action 'Custom-reset-standard)))
1537 (widget-insert " ")
1538 (widget-create 'push-button
1539 :tag "Finish"
1540 :help-echo
1541 (lambda (&rest ignore)
1542 (if custom-buffer-done-kill
1543 "Kill this buffer"
1544 "Bury this buffer"))
1545 :action #'Custom-buffer-done)
1546 (widget-insert "\n\n")
1547 (message "Creating customization items...")
1548 (buffer-disable-undo)
1549 (setq custom-options
1550 (if (= (length options) 1)
1551 (mapcar (lambda (entry)
1552 (widget-create (nth 1 entry)
1553 :documentation-shown t
1554 :custom-state 'unknown
1555 :tag (custom-unlispify-tag-name
1556 (nth 0 entry))
1557 :value (nth 0 entry)))
1558 options)
1559 (let ((count 0)
1560 (length (length options)))
1561 (mapcar (lambda (entry)
1562 (prog2
1563 (message "Creating customization items ...%2d%%"
1564 (/ (* 100.0 count) length))
1565 (widget-create (nth 1 entry)
1566 :tag (custom-unlispify-tag-name
1567 (nth 0 entry))
1568 :value (nth 0 entry))
1569 (setq count (1+ count))
1570 (unless (eq (preceding-char) ?\n)
1571 (widget-insert "\n"))
1572 (widget-insert "\n")))
1573 options))))
1574 (unless (eq (preceding-char) ?\n)
1575 (widget-insert "\n"))
1576 (message "Creating customization items ...done")
1577 (message "Resetting customization items...")
1578 (unless (eq custom-buffer-style 'tree)
1579 (mapc 'custom-magic-reset custom-options))
1580 (message "Resetting customization items...done")
1581 (message "Creating customization setup...")
1582 (widget-setup)
1583 (buffer-enable-undo)
1584 (goto-char (point-min))
1585 (message "Creating customization setup...done"))
1587 ;;; The Tree Browser.
1589 ;;;###autoload
1590 (defun customize-browse (&optional group)
1591 "Create a tree browser for the customize hierarchy."
1592 (interactive)
1593 (unless group
1594 (setq group 'emacs))
1595 (let ((name "*Customize Browser*"))
1596 (pop-to-buffer (custom-get-fresh-buffer name)))
1597 (custom-mode)
1598 (widget-insert (format "\
1599 %s buttons; type RET or click mouse-1
1600 on a button to invoke its action.
1601 Invoke [+] to expand a group, and [-] to collapse an expanded group.\n"
1602 (if custom-raised-buttons
1603 "`Raised' text indicates"
1604 "Square brackets indicate")))
1607 (if custom-browse-only-groups
1608 (widget-insert "\
1609 Invoke the [Group] button below to edit that item in another window.\n\n")
1610 (widget-insert "Invoke the ")
1611 (widget-create 'item
1612 :format "%t"
1613 :tag "[Group]"
1614 :tag-glyph "folder")
1615 (widget-insert ", ")
1616 (widget-create 'item
1617 :format "%t"
1618 :tag "[Face]"
1619 :tag-glyph "face")
1620 (widget-insert ", and ")
1621 (widget-create 'item
1622 :format "%t"
1623 :tag "[Option]"
1624 :tag-glyph "option")
1625 (widget-insert " buttons below to edit that
1626 item in another window.\n\n"))
1627 (let ((custom-buffer-style 'tree))
1628 (widget-create 'custom-group
1629 :custom-last t
1630 :custom-state 'unknown
1631 :tag (custom-unlispify-tag-name group)
1632 :value group))
1633 (widget-setup)
1634 (goto-char (point-min)))
1636 (define-widget 'custom-browse-visibility 'item
1637 "Control visibility of items in the customize tree browser."
1638 :format "%[[%t]%]"
1639 :action 'custom-browse-visibility-action)
1641 (defun custom-browse-visibility-action (widget &rest ignore)
1642 (let ((custom-buffer-style 'tree))
1643 (custom-toggle-parent widget)))
1645 (define-widget 'custom-browse-group-tag 'custom-group-link
1646 "Show parent in other window when activated."
1647 :tag "Group"
1648 :tag-glyph "folder"
1649 :action 'custom-browse-group-tag-action)
1651 (defun custom-browse-group-tag-action (widget &rest ignore)
1652 (let ((parent (widget-get widget :parent)))
1653 (customize-group-other-window (widget-value parent))))
1655 (define-widget 'custom-browse-variable-tag 'custom-group-link
1656 "Show parent in other window when activated."
1657 :tag "Option"
1658 :tag-glyph "option"
1659 :action 'custom-browse-variable-tag-action)
1661 (defun custom-browse-variable-tag-action (widget &rest ignore)
1662 (let ((parent (widget-get widget :parent)))
1663 (customize-variable-other-window (widget-value parent))))
1665 (define-widget 'custom-browse-face-tag 'custom-group-link
1666 "Show parent in other window when activated."
1667 :tag "Face"
1668 :tag-glyph "face"
1669 :action 'custom-browse-face-tag-action)
1671 (defun custom-browse-face-tag-action (widget &rest ignore)
1672 (let ((parent (widget-get widget :parent)))
1673 (customize-face-other-window (widget-value parent))))
1675 (defconst custom-browse-alist '((" " "space")
1676 (" | " "vertical")
1677 ("-\\ " "top")
1678 (" |-" "middle")
1679 (" `-" "bottom")))
1681 (defun custom-browse-insert-prefix (prefix)
1682 "Insert PREFIX. On XEmacs convert it to line graphics."
1683 ;; Fixme: do graphics.
1684 (if nil ; (string-match "XEmacs" emacs-version)
1685 (progn
1686 (insert "*")
1687 (while (not (string-equal prefix ""))
1688 (let ((entry (substring prefix 0 3)))
1689 (setq prefix (substring prefix 3))
1690 (let ((overlay (make-overlay (1- (point)) (point) nil t nil))
1691 (name (nth 1 (assoc entry custom-browse-alist))))
1692 (overlay-put overlay 'end-glyph (widget-glyph-find name entry))
1693 (overlay-put overlay 'start-open t)
1694 (overlay-put overlay 'end-open t)))))
1695 (insert prefix)))
1697 ;;; Modification of Basic Widgets.
1699 ;; We add extra properties to the basic widgets needed here. This is
1700 ;; fine, as long as we are careful to stay within out own namespace.
1702 ;; We want simple widgets to be displayed by default, but complex
1703 ;; widgets to be hidden.
1705 (widget-put (get 'item 'widget-type) :custom-show t)
1706 (widget-put (get 'editable-field 'widget-type)
1707 :custom-show (lambda (widget value)
1708 (let ((pp (pp-to-string value)))
1709 (cond ((string-match "\n" pp)
1710 nil)
1711 ((> (length pp) 40)
1712 nil)
1713 (t t)))))
1714 (widget-put (get 'menu-choice 'widget-type) :custom-show t)
1716 ;;; The `custom-manual' Widget.
1718 (define-widget 'custom-manual 'info-link
1719 "Link to the manual entry for this customization option."
1720 :help-echo "Read the manual entry for this option."
1721 :button-face 'custom-link
1722 :mouse-face 'highlight
1723 :tag "Manual")
1725 ;;; The `custom-magic' Widget.
1727 (defgroup custom-magic-faces nil
1728 "Faces used by the magic button."
1729 :group 'custom-faces
1730 :group 'custom-buffer)
1732 (defface custom-invalid '((((class color))
1733 (:foreground "yellow1" :background "red1"))
1735 (:weight bold :slant italic :underline t)))
1736 "Face used when the customize item is invalid."
1737 :group 'custom-magic-faces)
1738 ;; backward-compatibility alias
1739 (put 'custom-invalid-face 'face-alias 'custom-invalid)
1741 (defface custom-rogue '((((class color))
1742 (:foreground "pink" :background "black"))
1744 (:underline t)))
1745 "Face used when the customize item is not defined for customization."
1746 :group 'custom-magic-faces)
1747 ;; backward-compatibility alias
1748 (put 'custom-rogue-face 'face-alias 'custom-rogue)
1750 (defface custom-modified '((((min-colors 88) (class color))
1751 (:foreground "white" :background "blue1"))
1752 (((class color))
1753 (:foreground "white" :background "blue"))
1755 (:slant italic :bold)))
1756 "Face used when the customize item has been modified."
1757 :group 'custom-magic-faces)
1758 ;; backward-compatibility alias
1759 (put 'custom-modified-face 'face-alias 'custom-modified)
1761 (defface custom-set '((((min-colors 88) (class color))
1762 (:foreground "blue1" :background "white"))
1763 (((class color))
1764 (:foreground "blue" :background "white"))
1766 (:slant italic)))
1767 "Face used when the customize item has been set."
1768 :group 'custom-magic-faces)
1769 ;; backward-compatibility alias
1770 (put 'custom-set-face 'face-alias 'custom-set)
1772 (defface custom-changed '((((min-colors 88) (class color))
1773 (:foreground "white" :background "blue1"))
1774 (((class color))
1775 (:foreground "white" :background "blue"))
1777 (:slant italic)))
1778 "Face used when the customize item has been changed."
1779 :group 'custom-magic-faces)
1780 ;; backward-compatibility alias
1781 (put 'custom-changed-face 'face-alias 'custom-changed)
1783 (defface custom-themed '((((min-colors 88) (class color))
1784 (:foreground "white" :background "blue1"))
1785 (((class color))
1786 (:foreground "white" :background "blue"))
1788 (:slant italic)))
1789 "Face used when the customize item has been set by a theme."
1790 :group 'custom-magic-faces)
1792 (defface custom-saved '((t (:underline t)))
1793 "Face used when the customize item has been saved."
1794 :group 'custom-magic-faces)
1795 ;; backward-compatibility alias
1796 (put 'custom-saved-face 'face-alias 'custom-saved)
1798 (defconst custom-magic-alist
1799 '((nil "#" underline "\
1800 UNINITIALIZED, you should not see this.")
1801 (unknown "?" italic "\
1802 UNKNOWN, you should not see this.")
1803 (hidden "-" default "\
1804 HIDDEN, invoke \"Show\" in the previous line to show." "\
1805 group now hidden, invoke \"Show\", above, to show contents.")
1806 (invalid "x" custom-invalid "\
1807 INVALID, the displayed value cannot be set.")
1808 (modified "*" custom-modified "\
1809 EDITED, shown value does not take effect until you set or save it." "\
1810 something in this group has been edited but not set.")
1811 (set "+" custom-set "\
1812 SET for current session only." "\
1813 something in this group has been set but not saved.")
1814 (changed ":" custom-changed "\
1815 CHANGED outside Customize; operating on it here may be unreliable." "\
1816 something in this group has been changed outside customize.")
1817 (saved "!" custom-saved "\
1818 SAVED and set." "\
1819 something in this group has been set and saved.")
1820 (themed "o" custom-themed "\
1821 THEMED." "\
1822 visible group members are all at standard values.")
1823 (rogue "@" custom-rogue "\
1824 NO CUSTOMIZATION DATA; not intended to be customized." "\
1825 something in this group is not prepared for customization.")
1826 (standard " " nil "\
1827 STANDARD." "\
1828 visible group members are all at standard values."))
1829 "Alist of customize option states.
1830 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1832 STATE is one of the following symbols:
1834 `nil'
1835 For internal use, should never occur.
1836 `unknown'
1837 For internal use, should never occur.
1838 `hidden'
1839 This item is not being displayed.
1840 `invalid'
1841 This item is modified, but has an invalid form.
1842 `modified'
1843 This item is modified, and has a valid form.
1844 `set'
1845 This item has been set but not saved.
1846 `changed'
1847 The current value of this item has been changed outside Customize.
1848 `saved'
1849 This item is marked for saving.
1850 `rogue'
1851 This item has no customization information.
1852 `standard'
1853 This item is unchanged from the standard setting.
1855 MAGIC is a string used to present that state.
1857 FACE is a face used to present the state.
1859 ITEM-DESC is a string describing the state for options.
1861 GROUP-DESC is a string describing the state for groups. If this is
1862 left out, ITEM-DESC will be used.
1864 The string %c in either description will be replaced with the
1865 category of the item. These are `group'. `option', and `face'.
1867 The list should be sorted most significant first.")
1869 (defcustom custom-magic-show 'long
1870 "If non-nil, show textual description of the state.
1871 If `long', show a full-line description, not just one word."
1872 :type '(choice (const :tag "no" nil)
1873 (const long)
1874 (other :tag "short" short))
1875 :group 'custom-buffer)
1877 (defcustom custom-magic-show-hidden '(option face)
1878 "Control whether the State button is shown for hidden items.
1879 The value should be a list with the custom categories where the State
1880 button should be visible. Possible categories are `group', `option',
1881 and `face'."
1882 :type '(set (const group) (const option) (const face))
1883 :group 'custom-buffer)
1885 (defcustom custom-magic-show-button nil
1886 "Show a \"magic\" button indicating the state of each customization option."
1887 :type 'boolean
1888 :group 'custom-buffer)
1890 (define-widget 'custom-magic 'default
1891 "Show and manipulate state for a customization option."
1892 :format "%v"
1893 :action 'widget-parent-action
1894 :notify 'ignore
1895 :value-get 'ignore
1896 :value-create 'custom-magic-value-create
1897 :value-delete 'widget-children-value-delete)
1899 (defun widget-magic-mouse-down-action (widget &optional event)
1900 ;; Non-nil unless hidden.
1901 (not (eq (widget-get (widget-get (widget-get widget :parent) :parent)
1902 :custom-state)
1903 'hidden)))
1905 (defun custom-magic-value-create (widget)
1906 "Create compact status report for WIDGET."
1907 (let* ((parent (widget-get widget :parent))
1908 (state (widget-get parent :custom-state))
1909 (hidden (eq state 'hidden))
1910 (entry (assq state custom-magic-alist))
1911 (magic (nth 1 entry))
1912 (face (nth 2 entry))
1913 (category (widget-get parent :custom-category))
1914 (text (or (and (eq category 'group)
1915 (nth 4 entry))
1916 (nth 3 entry)))
1917 (form (widget-get parent :custom-form))
1918 children)
1919 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text)
1920 (setq text (concat (match-string 1 text)
1921 (symbol-name category)
1922 (match-string 2 text))))
1923 (when (and custom-magic-show
1924 (or (not hidden)
1925 (memq category custom-magic-show-hidden)))
1926 (insert " ")
1927 (when (and (eq category 'group)
1928 (not (and (eq custom-buffer-style 'links)
1929 (> (widget-get parent :custom-level) 1))))
1930 (insert-char ?\ (* custom-buffer-indent
1931 (widget-get parent :custom-level))))
1932 (push (widget-create-child-and-convert
1933 widget 'choice-item
1934 :help-echo "Change the state of this item."
1935 :format (if hidden "%t" "%[%t%]")
1936 :button-prefix 'widget-push-button-prefix
1937 :button-suffix 'widget-push-button-suffix
1938 :mouse-down-action 'widget-magic-mouse-down-action
1939 :tag "State")
1940 children)
1941 (insert ": ")
1942 (let ((start (point)))
1943 (if (eq custom-magic-show 'long)
1944 (insert text)
1945 (insert (symbol-name state)))
1946 (cond ((eq form 'lisp)
1947 (insert " (lisp)"))
1948 ((eq form 'mismatch)
1949 (insert " (mismatch)")))
1950 (put-text-property start (point) 'face 'custom-state))
1951 (insert "\n"))
1952 (when (and (eq category 'group)
1953 (not (and (eq custom-buffer-style 'links)
1954 (> (widget-get parent :custom-level) 1))))
1955 (insert-char ?\ (* custom-buffer-indent
1956 (widget-get parent :custom-level))))
1957 (when custom-magic-show-button
1958 (when custom-magic-show
1959 (let ((indent (widget-get parent :indent)))
1960 (when indent
1961 (insert-char ? indent))))
1962 (push (widget-create-child-and-convert
1963 widget 'choice-item
1964 :mouse-down-action 'widget-magic-mouse-down-action
1965 :button-face face
1966 :button-prefix ""
1967 :button-suffix ""
1968 :help-echo "Change the state."
1969 :format (if hidden "%t" "%[%t%]")
1970 :tag (if (memq form '(lisp mismatch))
1971 (concat "(" magic ")")
1972 (concat "[" magic "]")))
1973 children)
1974 (insert " "))
1975 (widget-put widget :children children)))
1977 (defun custom-magic-reset (widget)
1978 "Redraw the :custom-magic property of WIDGET."
1979 (let ((magic (widget-get widget :custom-magic)))
1980 (widget-value-set magic (widget-value magic))))
1982 ;;; The `custom' Widget.
1984 (defface custom-button
1985 '((((type x w32 mac) (class color)) ; Like default modeline
1986 (:box (:line-width 2 :style released-button)
1987 :background "lightgrey" :foreground "black"))
1989 nil))
1990 "Face for custom buffer buttons if `custom-raised-buttons' is non-nil."
1991 :version "21.1"
1992 :group 'custom-faces)
1993 ;; backward-compatibility alias
1994 (put 'custom-button-face 'face-alias 'custom-button)
1996 (defface custom-button-mouse
1997 '((((type x w32 mac) (class color))
1998 (:box (:line-width 2 :style released-button)
1999 :background "grey90" :foreground "black"))
2001 nil))
2002 "Mouse face for custom buffer buttons if `custom-raised-buttons' is non-nil."
2003 :version "22.1"
2004 :group 'custom-faces)
2006 (defface custom-button-unraised
2007 '((t :inherit underline))
2008 "Face for custom buffer buttons if `custom-raised-buttons' is nil."
2009 :version "22.1"
2010 :group 'custom-faces)
2012 (setq custom-button
2013 (if custom-raised-buttons 'custom-button 'custom-button-unraised))
2015 (setq custom-button-mouse
2016 (if custom-raised-buttons 'custom-button-mouse 'highlight))
2018 (defface custom-button-pressed
2019 '((((type x w32 mac) (class color))
2020 (:box (:line-width 2 :style pressed-button)
2021 :background "lightgrey" :foreground "black"))
2023 (:inverse-video t)))
2024 "Face for pressed custom buttons if `custom-raised-buttons' is non-nil."
2025 :version "21.1"
2026 :group 'custom-faces)
2027 ;; backward-compatibility alias
2028 (put 'custom-button-pressed-face 'face-alias 'custom-button-pressed)
2030 (defface custom-button-pressed-unraised
2031 '((default :inherit custom-button-unraised)
2032 (((class color) (background light)) :foreground "magenta4")
2033 (((class color) (background dark)) :foreground "violet"))
2034 "Face for pressed custom buttons if `custom-raised-buttons' is nil."
2035 :version "22.1"
2036 :group 'custom-faces)
2038 (setq custom-button-pressed
2039 (if custom-raised-buttons
2040 'custom-button-pressed
2041 'custom-button-pressed-unraised))
2043 (defface custom-documentation nil
2044 "Face used for documentation strings in customization buffers."
2045 :group 'custom-faces)
2046 ;; backward-compatibility alias
2047 (put 'custom-documentation-face 'face-alias 'custom-documentation)
2049 (defface custom-state '((((class color)
2050 (background dark))
2051 (:foreground "lime green"))
2052 (((class color)
2053 (background light))
2054 (:foreground "dark green"))
2055 (t nil))
2056 "Face used for State descriptions in the customize buffer."
2057 :group 'custom-faces)
2058 ;; backward-compatibility alias
2059 (put 'custom-state-face 'face-alias 'custom-state)
2061 (defface custom-link
2062 '((t :inherit link))
2063 "Face for links in customization buffers."
2064 :version "22.1"
2065 :group 'custom-faces)
2067 (define-widget 'custom 'default
2068 "Customize a user option."
2069 :format "%v"
2070 :convert-widget 'custom-convert-widget
2071 :notify 'custom-notify
2072 :custom-prefix ""
2073 :custom-level 1
2074 :custom-state 'hidden
2075 :documentation-property 'widget-subclass-responsibility
2076 :value-create 'widget-subclass-responsibility
2077 :value-delete 'widget-children-value-delete
2078 :value-get 'widget-value-value-get
2079 :validate 'widget-children-validate
2080 :match (lambda (widget value) (symbolp value)))
2082 (defun custom-convert-widget (widget)
2083 "Initialize :value and :tag from :args in WIDGET."
2084 (let ((args (widget-get widget :args)))
2085 (when args
2086 (widget-put widget :value (widget-apply widget
2087 :value-to-internal (car args)))
2088 (widget-put widget :tag (custom-unlispify-tag-name (car args)))
2089 (widget-put widget :args nil)))
2090 widget)
2092 (defun custom-notify (widget &rest args)
2093 "Keep track of changes."
2094 (let ((state (widget-get widget :custom-state)))
2095 (unless (eq state 'modified)
2096 (unless (memq state '(nil unknown hidden))
2097 (widget-put widget :custom-state 'modified))
2098 (custom-magic-reset widget)
2099 (apply 'widget-default-notify widget args))))
2101 (defun custom-redraw (widget)
2102 "Redraw WIDGET with current settings."
2103 (let ((line (count-lines (point-min) (point)))
2104 (column (current-column))
2105 (pos (point))
2106 (from (marker-position (widget-get widget :from)))
2107 (to (marker-position (widget-get widget :to))))
2108 (save-excursion
2109 (widget-value-set widget (widget-value widget))
2110 (custom-redraw-magic widget))
2111 (when (and (>= pos from) (<= pos to))
2112 (condition-case nil
2113 (progn
2114 (if (> column 0)
2115 (goto-line line)
2116 (goto-line (1+ line)))
2117 (move-to-column column))
2118 (error nil)))))
2120 (defun custom-redraw-magic (widget)
2121 "Redraw WIDGET state with current settings."
2122 (while widget
2123 (let ((magic (widget-get widget :custom-magic)))
2124 (cond (magic
2125 (widget-value-set magic (widget-value magic))
2126 (when (setq widget (widget-get widget :group))
2127 (custom-group-state-update widget)))
2129 (setq widget nil)))))
2130 (widget-setup))
2132 (defun custom-show (widget value)
2133 "Non-nil if WIDGET should be shown with VALUE by default."
2134 (let ((show (widget-get widget :custom-show)))
2135 (cond ((null show)
2136 nil)
2137 ((eq t show)
2140 (funcall show widget value)))))
2142 (defun custom-load-widget (widget)
2143 "Load all dependencies for WIDGET."
2144 (custom-load-symbol (widget-value widget)))
2146 (defun custom-unloaded-symbol-p (symbol)
2147 "Return non-nil if the dependencies of SYMBOL have not yet been loaded."
2148 (let ((found nil)
2149 (loads (get symbol 'custom-loads))
2150 load)
2151 (while loads
2152 (setq load (car loads)
2153 loads (cdr loads))
2154 (cond ((symbolp load)
2155 (unless (featurep load)
2156 (setq found t)))
2157 ((assoc load load-history))
2158 ((assoc (locate-library load) load-history)
2159 (message nil))
2161 (setq found t))))
2162 found))
2164 (defun custom-unloaded-widget-p (widget)
2165 "Return non-nil if the dependencies of WIDGET have not yet been loaded."
2166 (custom-unloaded-symbol-p (widget-value widget)))
2168 (defun custom-toggle-hide (widget)
2169 "Toggle visibility of WIDGET."
2170 (custom-load-widget widget)
2171 (let ((state (widget-get widget :custom-state)))
2172 (cond ((memq state '(invalid modified))
2173 (error "There are unset changes"))
2174 ((eq state 'hidden)
2175 (widget-put widget :custom-state 'unknown))
2177 (widget-put widget :documentation-shown nil)
2178 (widget-put widget :custom-state 'hidden)))
2179 (custom-redraw widget)
2180 (widget-setup)))
2182 (defun custom-toggle-parent (widget &rest ignore)
2183 "Toggle visibility of parent of WIDGET."
2184 (custom-toggle-hide (widget-get widget :parent)))
2186 (defun custom-add-see-also (widget &optional prefix)
2187 "Add `See also ...' to WIDGET if there are any links.
2188 Insert PREFIX first if non-nil."
2189 (let* ((symbol (widget-get widget :value))
2190 (links (get symbol 'custom-links))
2191 (many (> (length links) 2))
2192 (buttons (widget-get widget :buttons))
2193 (indent (widget-get widget :indent)))
2194 (when links
2195 (when indent
2196 (insert-char ?\ indent))
2197 (when prefix
2198 (insert prefix))
2199 (insert "See also ")
2200 (while links
2201 (push (widget-create-child-and-convert
2202 widget (car links)
2203 :button-face 'custom-link
2204 :mouse-face 'highlight)
2205 buttons)
2206 (setq links (cdr links))
2207 (cond ((null links)
2208 (insert ".\n"))
2209 ((null (cdr links))
2210 (if many
2211 (insert ", and ")
2212 (insert " and ")))
2214 (insert ", "))))
2215 (widget-put widget :buttons buttons))))
2217 (defun custom-add-parent-links (widget &optional initial-string)
2218 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
2219 The value is non-nil if any parents were found.
2220 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
2221 (let ((name (widget-value widget))
2222 (type (widget-type widget))
2223 (buttons (widget-get widget :buttons))
2224 (start (point))
2225 (parents nil))
2226 (insert (or initial-string "Parent groups:"))
2227 (mapatoms (lambda (symbol)
2228 (when (member (list name type) (get symbol 'custom-group))
2229 (insert " ")
2230 (push (widget-create-child-and-convert
2231 widget 'custom-group-link
2232 :tag (custom-unlispify-tag-name symbol)
2233 symbol)
2234 buttons)
2235 (setq parents (cons symbol parents)))))
2236 (and (null (get name 'custom-links)) ;No links of its own.
2237 (= (length parents) 1) ;A single parent.
2238 (let* ((links (delq nil (mapcar (lambda (w)
2239 (unless (eq (widget-type w)
2240 'custom-group-link)
2242 (get (car parents) 'custom-links))))
2243 (many (> (length links) 2)))
2244 (when links
2245 (insert "\nParent documentation: ")
2246 (while links
2247 (push (widget-create-child-and-convert
2248 widget (car links)
2249 :button-face 'custom-link
2250 :mouse-face 'highlight)
2251 buttons)
2252 (setq links (cdr links))
2253 (cond ((null links)
2254 (insert ".\n"))
2255 ((null (cdr links))
2256 (if many
2257 (insert ", and ")
2258 (insert " and ")))
2260 (insert ", ")))))))
2261 (if parents
2262 (insert "\n")
2263 (delete-region start (point)))
2264 (widget-put widget :buttons buttons)
2265 parents))
2267 ;;; The `custom-comment' Widget.
2269 ;; like the editable field
2270 (defface custom-comment '((((type tty))
2271 :background "yellow3"
2272 :foreground "black")
2273 (((class grayscale color)
2274 (background light))
2275 :background "gray85")
2276 (((class grayscale color)
2277 (background dark))
2278 :background "dim gray")
2280 :slant italic))
2281 "Face used for comments on variables or faces"
2282 :version "21.1"
2283 :group 'custom-faces)
2284 ;; backward-compatibility alias
2285 (put 'custom-comment-face 'face-alias 'custom-comment)
2287 ;; like font-lock-comment-face
2288 (defface custom-comment-tag
2289 '((((class color) (background dark)) (:foreground "gray80"))
2290 (((class color) (background light)) (:foreground "blue4"))
2291 (((class grayscale) (background light))
2292 (:foreground "DimGray" :weight bold :slant italic))
2293 (((class grayscale) (background dark))
2294 (:foreground "LightGray" :weight bold :slant italic))
2295 (t (:weight bold)))
2296 "Face used for variables or faces comment tags"
2297 :group 'custom-faces)
2298 ;; backward-compatibility alias
2299 (put 'custom-comment-tag-face 'face-alias 'custom-comment-tag)
2301 (define-widget 'custom-comment 'string
2302 "User comment."
2303 :tag "Comment"
2304 :help-echo "Edit a comment here."
2305 :sample-face 'custom-comment-tag-face
2306 :value-face 'custom-comment-face
2307 :shown nil
2308 :create 'custom-comment-create)
2310 (defun custom-comment-create (widget)
2311 (let* ((null-comment (equal "" (widget-value widget))))
2312 (if (or (widget-get (widget-get widget :parent) :comment-shown)
2313 (not null-comment))
2314 (widget-default-create widget)
2315 ;; `widget-default-delete' expects markers in these slots --
2316 ;; maybe it shouldn't.
2317 (widget-put widget :from (point-marker))
2318 (widget-put widget :to (point-marker)))))
2320 (defun custom-comment-hide (widget)
2321 (widget-put (widget-get widget :parent) :comment-shown nil))
2323 ;; Those functions are for the menu. WIDGET is NOT the comment widget. It's
2324 ;; the global custom one
2325 (defun custom-comment-show (widget)
2326 (widget-put widget :comment-shown t)
2327 (custom-redraw widget)
2328 (widget-setup))
2330 (defun custom-comment-invisible-p (widget)
2331 (let ((val (widget-value (widget-get widget :comment-widget))))
2332 (and (equal "" val)
2333 (not (widget-get widget :comment-shown)))))
2335 ;;; The `custom-variable' Widget.
2337 ;; When this was underlined blue, users confused it with a
2338 ;; Mosaic-style hyperlink...
2339 (defface custom-variable-tag
2340 `((((class color)
2341 (background dark))
2342 (:foreground "light blue" :weight bold :height 1.2 :inherit variable-pitch))
2343 (((min-colors 88) (class color)
2344 (background light))
2345 (:foreground "blue1" :weight bold :height 1.2 :inherit variable-pitch))
2346 (((class color)
2347 (background light))
2348 (:foreground "blue" :weight bold :height 1.2 :inherit variable-pitch))
2349 (t (:weight bold)))
2350 "Face used for unpushable variable tags."
2351 :group 'custom-faces)
2352 ;; backward-compatibility alias
2353 (put 'custom-variable-tag-face 'face-alias 'custom-variable-tag)
2355 (defface custom-variable-button '((t (:underline t :weight bold)))
2356 "Face used for pushable variable tags."
2357 :group 'custom-faces)
2358 ;; backward-compatibility alias
2359 (put 'custom-variable-button-face 'face-alias 'custom-variable-button)
2361 (defcustom custom-variable-default-form 'edit
2362 "Default form of displaying variable values."
2363 :type '(choice (const edit)
2364 (const lisp))
2365 :group 'custom-buffer
2366 :version "20.3")
2368 (defun custom-variable-documentation (variable)
2369 "Return documentation of VARIABLE for use in Custom buffer.
2370 Normally just return the docstring. But if VARIABLE automatically
2371 becomes buffer local when set, append a message to that effect."
2372 (if (and (local-variable-if-set-p variable)
2373 (or (not (local-variable-p variable))
2374 (with-temp-buffer
2375 (local-variable-if-set-p variable))))
2376 (concat (documentation-property variable 'variable-documentation)
2378 This variable automatically becomes buffer-local when set outside Custom.
2379 However, setting it through Custom sets the default value.")
2380 (documentation-property variable 'variable-documentation)))
2382 (define-widget 'custom-variable 'custom
2383 "Customize variable."
2384 :format "%v"
2385 :help-echo "Set or reset this variable."
2386 :documentation-property #'custom-variable-documentation
2387 :custom-category 'option
2388 :custom-state nil
2389 :custom-menu 'custom-variable-menu-create
2390 :custom-form nil ; defaults to value of `custom-variable-default-form'
2391 :value-create 'custom-variable-value-create
2392 :action 'custom-variable-action
2393 :custom-set 'custom-variable-set
2394 :custom-save 'custom-variable-save
2395 :custom-reset-current 'custom-redraw
2396 :custom-reset-saved 'custom-variable-reset-saved
2397 :custom-reset-standard 'custom-variable-reset-standard
2398 :custom-standard-value 'custom-variable-standard-value)
2400 (defun custom-variable-type (symbol)
2401 "Return a widget suitable for editing the value of SYMBOL.
2402 If SYMBOL has a `custom-type' property, use that.
2403 Otherwise, look up symbol in `custom-guess-type-alist'."
2404 (let* ((type (or (get symbol 'custom-type)
2405 (and (not (get symbol 'standard-value))
2406 (custom-guess-type symbol))
2407 'sexp))
2408 (options (get symbol 'custom-options))
2409 (tmp (if (listp type)
2410 (copy-sequence type)
2411 (list type))))
2412 (when options
2413 (widget-put tmp :options options))
2414 tmp))
2416 (defun custom-variable-value-create (widget)
2417 "Here is where you edit the variable's value."
2418 (custom-load-widget widget)
2419 (unless (widget-get widget :custom-form)
2420 (widget-put widget :custom-form custom-variable-default-form))
2421 (let* ((buttons (widget-get widget :buttons))
2422 (children (widget-get widget :children))
2423 (form (widget-get widget :custom-form))
2424 (state (widget-get widget :custom-state))
2425 (symbol (widget-get widget :value))
2426 (tag (widget-get widget :tag))
2427 (type (custom-variable-type symbol))
2428 (conv (widget-convert type))
2429 (get (or (get symbol 'custom-get) 'default-value))
2430 (prefix (widget-get widget :custom-prefix))
2431 (last (widget-get widget :custom-last))
2432 (value (if (default-boundp symbol)
2433 (funcall get symbol)
2434 (widget-get conv :value))))
2435 ;; If the widget is new, the child determines whether it is hidden.
2436 (cond (state)
2437 ((custom-show type value)
2438 (setq state 'unknown))
2440 (setq state 'hidden)))
2441 ;; If we don't know the state, see if we need to edit it in lisp form.
2442 (when (eq state 'unknown)
2443 (unless (widget-apply conv :match value)
2444 ;; (widget-apply (widget-convert type) :match value)
2445 (setq form 'mismatch)))
2446 ;; Now we can create the child widget.
2447 (cond ((eq custom-buffer-style 'tree)
2448 (insert prefix (if last " `--- " " |--- "))
2449 (push (widget-create-child-and-convert
2450 widget 'custom-browse-variable-tag)
2451 buttons)
2452 (insert " " tag "\n")
2453 (widget-put widget :buttons buttons))
2454 ((eq state 'hidden)
2455 ;; Indicate hidden value.
2456 (push (widget-create-child-and-convert
2457 widget 'item
2458 :format "%{%t%}: "
2459 :sample-face 'custom-variable-tag-face
2460 :tag tag
2461 :parent widget)
2462 buttons)
2463 (push (widget-create-child-and-convert
2464 widget 'visibility
2465 :help-echo "Show the value of this option."
2466 :off "Show Value"
2467 :action 'custom-toggle-parent
2468 nil)
2469 buttons))
2470 ((memq form '(lisp mismatch))
2471 ;; In lisp mode edit the saved value when possible.
2472 (let* ((value (cond ((get symbol 'saved-value)
2473 (car (get symbol 'saved-value)))
2474 ((get symbol 'standard-value)
2475 (car (get symbol 'standard-value)))
2476 ((default-boundp symbol)
2477 (custom-quote (funcall get symbol)))
2479 (custom-quote (widget-get conv :value))))))
2480 (insert (symbol-name symbol) ": ")
2481 (push (widget-create-child-and-convert
2482 widget 'visibility
2483 :help-echo "Hide the value of this option."
2484 :on "Hide Value"
2485 :off "Show Value"
2486 :action 'custom-toggle-parent
2488 buttons)
2489 (insert " ")
2490 (push (widget-create-child-and-convert
2491 widget 'sexp
2492 :button-face 'custom-variable-button-face
2493 :format "%v"
2494 :tag (symbol-name symbol)
2495 :parent widget
2496 :value value)
2497 children)))
2499 ;; Edit mode.
2500 (let* ((format (widget-get type :format))
2501 tag-format value-format)
2502 (unless (string-match ":" format)
2503 (error "Bad format"))
2504 (setq tag-format (substring format 0 (match-end 0)))
2505 (setq value-format (substring format (match-end 0)))
2506 (push (widget-create-child-and-convert
2507 widget 'item
2508 :format tag-format
2509 :action 'custom-tag-action
2510 :help-echo "Change value of this option."
2511 :mouse-down-action 'custom-tag-mouse-down-action
2512 :button-face 'custom-variable-button-face
2513 :sample-face 'custom-variable-tag-face
2514 tag)
2515 buttons)
2516 (insert " ")
2517 (push (widget-create-child-and-convert
2518 widget 'visibility
2519 :help-echo "Hide the value of this option."
2520 :on "Hide Value"
2521 :off "Show Value"
2522 :action 'custom-toggle-parent
2524 buttons)
2525 (push (widget-create-child-and-convert
2526 widget type
2527 :format value-format
2528 :value value)
2529 children))))
2530 (unless (eq custom-buffer-style 'tree)
2531 (unless (eq (preceding-char) ?\n)
2532 (widget-insert "\n"))
2533 ;; Create the magic button.
2534 (let ((magic (widget-create-child-and-convert
2535 widget 'custom-magic nil)))
2536 (widget-put widget :custom-magic magic)
2537 (push magic buttons))
2538 ;; ### NOTE: this is ugly!!!! I need to update the :buttons property
2539 ;; before the call to `widget-default-format-handler'. Otherwise, I
2540 ;; loose my current `buttons'. This function shouldn't be called like
2541 ;; this anyway. The doc string widget should be added like the others.
2542 ;; --dv
2543 (widget-put widget :buttons buttons)
2544 (insert "\n")
2545 ;; Insert documentation.
2546 (widget-default-format-handler widget ?h)
2548 ;; The comment field
2549 (unless (eq state 'hidden)
2550 (let* ((comment (get symbol 'variable-comment))
2551 (comment-widget
2552 (widget-create-child-and-convert
2553 widget 'custom-comment
2554 :parent widget
2555 :value (or comment ""))))
2556 (widget-put widget :comment-widget comment-widget)
2557 ;; Don't push it !!! Custom assumes that the first child is the
2558 ;; value one.
2559 (setq children (append children (list comment-widget)))))
2560 ;; Update the rest of the properties properties.
2561 (widget-put widget :custom-form form)
2562 (widget-put widget :children children)
2563 ;; Now update the state.
2564 (if (eq state 'hidden)
2565 (widget-put widget :custom-state state)
2566 (custom-variable-state-set widget))
2567 ;; See also.
2568 (unless (eq state 'hidden)
2569 (when (eq (widget-get widget :custom-level) 1)
2570 (custom-add-parent-links widget))
2571 (custom-add-see-also widget)))))
2573 (defun custom-tag-action (widget &rest args)
2574 "Pass :action to first child of WIDGET's parent."
2575 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
2576 :action args))
2578 (defun custom-tag-mouse-down-action (widget &rest args)
2579 "Pass :mouse-down-action to first child of WIDGET's parent."
2580 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
2581 :mouse-down-action args))
2583 (defun custom-variable-state-set (widget)
2584 "Set the state of WIDGET."
2585 (let* ((symbol (widget-value widget))
2586 (get (or (get symbol 'custom-get) 'default-value))
2587 (value (if (default-boundp symbol)
2588 (funcall get symbol)
2589 (widget-get widget :value)))
2590 (comment (get symbol 'variable-comment))
2592 temp
2593 (state (cond ((progn (setq tmp (get symbol 'customized-value))
2594 (setq temp
2595 (get symbol 'customized-variable-comment))
2596 (or tmp temp))
2597 (if (condition-case nil
2598 (and (equal value (eval (car tmp)))
2599 (equal comment temp))
2600 (error nil))
2601 'set
2602 'changed))
2603 ((progn (setq tmp (get symbol 'theme-value))
2604 (setq temp (get symbol 'saved-variable-comment))
2605 (or tmp temp))
2606 (if (condition-case nil
2607 (and (equal comment temp)
2608 (equal value
2609 (eval
2610 (car (custom-variable-theme-value
2611 symbol)))))
2612 (error nil))
2613 (cond
2614 ((eq (caar tmp) 'user) 'saved)
2615 ((eq (caar tmp) 'changed) 'changed)
2616 (t 'themed))
2617 'changed))
2618 ((setq tmp (get symbol 'standard-value))
2619 (if (condition-case nil
2620 (and (equal value (eval (car tmp)))
2621 (equal comment nil))
2622 (error nil))
2623 'standard
2624 'changed))
2625 (t 'rogue))))
2626 (widget-put widget :custom-state state)))
2628 (defun custom-variable-standard-value (widget)
2629 (get (widget-value widget) 'standard-value))
2631 (defvar custom-variable-menu
2632 `(("Set for Current Session" custom-variable-set
2633 (lambda (widget)
2634 (eq (widget-get widget :custom-state) 'modified)))
2635 ,@(when (or custom-file user-init-file)
2636 '(("Save for Future Sessions" custom-variable-save
2637 (lambda (widget)
2638 (memq (widget-get widget :custom-state)
2639 '(modified set changed rogue))))))
2640 ("Undo Edits" custom-redraw
2641 (lambda (widget)
2642 (and (default-boundp (widget-value widget))
2643 (memq (widget-get widget :custom-state) '(modified changed)))))
2644 ("Reset to Saved" custom-variable-reset-saved
2645 (lambda (widget)
2646 (and (or (get (widget-value widget) 'saved-value)
2647 (get (widget-value widget) 'saved-variable-comment))
2648 (memq (widget-get widget :custom-state)
2649 '(modified set changed rogue)))))
2650 ,@(when (or custom-file user-init-file)
2651 '(("Erase Customization" custom-variable-reset-standard
2652 (lambda (widget)
2653 (and (get (widget-value widget) 'standard-value)
2654 (memq (widget-get widget :custom-state)
2655 '(modified set changed saved rogue)))))))
2656 ("Set to Backup Value" custom-variable-reset-backup
2657 (lambda (widget)
2658 (get (widget-value widget) 'backup-value)))
2659 ("---" ignore ignore)
2660 ("Add Comment" custom-comment-show custom-comment-invisible-p)
2661 ("---" ignore ignore)
2662 ("Show Current Value" custom-variable-edit
2663 (lambda (widget)
2664 (eq (widget-get widget :custom-form) 'lisp)))
2665 ("Show Saved Lisp Expression" custom-variable-edit-lisp
2666 (lambda (widget)
2667 (eq (widget-get widget :custom-form) 'edit))))
2668 "Alist of actions for the `custom-variable' widget.
2669 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2670 the menu entry, ACTION is the function to call on the widget when the
2671 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2672 widget as an argument, and returns non-nil if ACTION is valid on that
2673 widget. If FILTER is nil, ACTION is always valid.")
2675 (defun custom-variable-action (widget &optional event)
2676 "Show the menu for `custom-variable' WIDGET.
2677 Optional EVENT is the location for the menu."
2678 (if (eq (widget-get widget :custom-state) 'hidden)
2679 (custom-toggle-hide widget)
2680 (unless (eq (widget-get widget :custom-state) 'modified)
2681 (custom-variable-state-set widget))
2682 (custom-redraw-magic widget)
2683 (let* ((completion-ignore-case t)
2684 (answer (widget-choose (concat "Operation on "
2685 (custom-unlispify-tag-name
2686 (widget-get widget :value)))
2687 (custom-menu-filter custom-variable-menu
2688 widget)
2689 event)))
2690 (if answer
2691 (funcall answer widget)))))
2693 (defun custom-variable-edit (widget)
2694 "Edit value of WIDGET."
2695 (widget-put widget :custom-state 'unknown)
2696 (widget-put widget :custom-form 'edit)
2697 (custom-redraw widget))
2699 (defun custom-variable-edit-lisp (widget)
2700 "Edit the Lisp representation of the value of WIDGET."
2701 (widget-put widget :custom-state 'unknown)
2702 (widget-put widget :custom-form 'lisp)
2703 (custom-redraw widget))
2705 (defun custom-variable-set (widget)
2706 "Set the current value for the variable being edited by WIDGET."
2707 (let* ((form (widget-get widget :custom-form))
2708 (state (widget-get widget :custom-state))
2709 (child (car (widget-get widget :children)))
2710 (symbol (widget-value widget))
2711 (set (or (get symbol 'custom-set) 'set-default))
2712 (comment-widget (widget-get widget :comment-widget))
2713 (comment (widget-value comment-widget))
2714 val)
2715 (cond ((eq state 'hidden)
2716 (error "Cannot set hidden variable"))
2717 ((setq val (widget-apply child :validate))
2718 (goto-char (widget-get val :from))
2719 (error "%s" (widget-get val :error)))
2720 ((memq form '(lisp mismatch))
2721 (when (equal comment "")
2722 (setq comment nil)
2723 ;; Make the comment invisible by hand if it's empty
2724 (custom-comment-hide comment-widget))
2725 (custom-variable-backup-value widget)
2726 (custom-push-theme 'theme-value symbol 'user
2727 'set (custom-quote (widget-value child)))
2728 (funcall set symbol (eval (setq val (widget-value child))))
2729 (put symbol 'customized-value (list val))
2730 (put symbol 'variable-comment comment)
2731 (put symbol 'customized-variable-comment comment))
2733 (when (equal comment "")
2734 (setq comment nil)
2735 ;; Make the comment invisible by hand if it's empty
2736 (custom-comment-hide comment-widget))
2737 (custom-variable-backup-value widget)
2738 (custom-push-theme 'theme-value symbol 'user
2739 'set (custom-quote (widget-value child)))
2740 (funcall set symbol (setq val (widget-value child)))
2741 (put symbol 'customized-value (list (custom-quote val)))
2742 (put symbol 'variable-comment comment)
2743 (put symbol 'customized-variable-comment comment)))
2744 (custom-variable-state-set widget)
2745 (custom-redraw-magic widget)))
2747 (defun custom-variable-save (widget)
2748 "Set and save the value for the variable being edited by WIDGET."
2749 (let* ((form (widget-get widget :custom-form))
2750 (state (widget-get widget :custom-state))
2751 (child (car (widget-get widget :children)))
2752 (symbol (widget-value widget))
2753 (set (or (get symbol 'custom-set) 'set-default))
2754 (comment-widget (widget-get widget :comment-widget))
2755 (comment (widget-value comment-widget))
2756 val)
2757 (cond ((eq state 'hidden)
2758 (error "Cannot set hidden variable"))
2759 ((setq val (widget-apply child :validate))
2760 (goto-char (widget-get val :from))
2761 (error "Saving %s: %s" symbol (widget-get val :error)))
2762 ((memq form '(lisp mismatch))
2763 (when (equal comment "")
2764 (setq comment nil)
2765 ;; Make the comment invisible by hand if it's empty
2766 (custom-comment-hide comment-widget))
2767 (put symbol 'saved-value (list (widget-value child)))
2768 (custom-push-theme 'theme-value symbol 'user
2769 'set (custom-quote (widget-value child)))
2770 (funcall set symbol (eval (widget-value child)))
2771 (put symbol 'variable-comment comment)
2772 (put symbol 'saved-variable-comment comment))
2774 (when (equal comment "")
2775 (setq comment nil)
2776 ;; Make the comment invisible by hand if it's empty
2777 (custom-comment-hide comment-widget))
2778 (put symbol 'saved-value
2779 (list (custom-quote (widget-value child))))
2780 (custom-push-theme 'theme-value symbol 'user
2781 'set (custom-quote (widget-value child)))
2782 (funcall set symbol (widget-value child))
2783 (put symbol 'variable-comment comment)
2784 (put symbol 'saved-variable-comment comment)))
2785 (put symbol 'customized-value nil)
2786 (put symbol 'customized-variable-comment nil)
2787 (custom-save-all)
2788 (custom-variable-state-set widget)
2789 (custom-redraw-magic widget)))
2791 (defun custom-variable-reset-saved (widget)
2792 "Restore the saved value for the variable being edited by WIDGET.
2793 This also updates the buffer to show that value.
2794 The value that was current before this operation
2795 becomes the backup value, so you can get it again."
2796 (let* ((symbol (widget-value widget))
2797 (set (or (get symbol 'custom-set) 'set-default))
2798 (value (get symbol 'saved-value))
2799 (comment (get symbol 'saved-variable-comment)))
2800 (cond ((or value comment)
2801 (put symbol 'variable-comment comment)
2802 (custom-variable-backup-value widget)
2803 (custom-push-theme 'theme-value symbol 'user 'set (car-safe value))
2804 (condition-case nil
2805 (funcall set symbol (eval (car value)))
2806 (error nil)))
2808 (error "No saved value for %s" symbol)))
2809 (put symbol 'customized-value nil)
2810 (put symbol 'customized-variable-comment nil)
2811 (widget-put widget :custom-state 'unknown)
2812 ;; This call will possibly make the comment invisible
2813 (custom-redraw widget)))
2815 (defun custom-variable-reset-standard (widget)
2816 "Restore the standard setting for the variable being edited by WIDGET.
2817 This operation eliminates any saved setting for the variable,
2818 restoring it to the state of a variable that has never been customized.
2819 The value that was current before this operation
2820 becomes the backup value, so you can get it again."
2821 (let* ((symbol (widget-value widget)))
2822 (if (get symbol 'standard-value)
2823 (custom-variable-backup-value widget)
2824 (error "No standard setting known for %S" symbol))
2825 (put symbol 'variable-comment nil)
2826 (put symbol 'customized-value nil)
2827 (put symbol 'customized-variable-comment nil)
2828 (custom-push-theme 'theme-value symbol 'user 'reset)
2829 (custom-theme-recalc-variable symbol)
2830 (when (or (get symbol 'saved-value) (get symbol 'saved-variable-comment))
2831 (put symbol 'saved-value nil)
2832 (put symbol 'saved-variable-comment nil)
2833 (custom-save-all))
2834 (widget-put widget :custom-state 'unknown)
2835 ;; This call will possibly make the comment invisible
2836 (custom-redraw widget)))
2838 (defun custom-variable-backup-value (widget)
2839 "Back up the current value for WIDGET's variable.
2840 The backup value is kept in the car of the `backup-value' property."
2841 (let* ((symbol (widget-value widget))
2842 (get (or (get symbol 'custom-get) 'default-value))
2843 (type (custom-variable-type symbol))
2844 (conv (widget-convert type))
2845 (value (if (default-boundp symbol)
2846 (funcall get symbol)
2847 (widget-get conv :value))))
2848 (put symbol 'backup-value (list value))))
2850 (defun custom-variable-reset-backup (widget)
2851 "Restore the backup value for the variable being edited by WIDGET.
2852 The value that was current before this operation
2853 becomes the backup value, so you can use this operation repeatedly
2854 to switch between two values."
2855 (let* ((symbol (widget-value widget))
2856 (set (or (get symbol 'custom-set) 'set-default))
2857 (value (get symbol 'backup-value))
2858 (comment-widget (widget-get widget :comment-widget))
2859 (comment (widget-value comment-widget)))
2860 (if value
2861 (progn
2862 (custom-variable-backup-value widget)
2863 (custom-push-theme 'theme-value symbol 'user 'set value)
2864 (condition-case nil
2865 (funcall set symbol (car value))
2866 (error nil)))
2867 (error "No backup value for %s" symbol))
2868 (put symbol 'customized-value (list (car value)))
2869 (put symbol 'variable-comment comment)
2870 (put symbol 'customized-variable-comment comment)
2871 (custom-variable-state-set widget)
2872 ;; This call will possibly make the comment invisible
2873 (custom-redraw widget)))
2875 ;;; The `custom-face-edit' Widget.
2877 (define-widget 'custom-face-edit 'checklist
2878 "Edit face attributes."
2879 :format "%t: %v"
2880 :tag "Attributes"
2881 :extra-offset 13
2882 :button-args '(:help-echo "Control whether this attribute has any effect.")
2883 :value-to-internal 'custom-face-edit-fix-value
2884 :match (lambda (widget value)
2885 (widget-checklist-match widget
2886 (custom-face-edit-fix-value widget value)))
2887 :convert-widget 'custom-face-edit-convert-widget
2888 :args (mapcar (lambda (att)
2889 (list 'group
2890 :inline t
2891 :sibling-args (widget-get (nth 1 att) :sibling-args)
2892 (list 'const :format "" :value (nth 0 att))
2893 (nth 1 att)))
2894 custom-face-attributes))
2896 (defun custom-face-edit-fix-value (widget value)
2897 "Ignoring WIDGET, convert :bold and :italic in VALUE to new form.
2898 Also change :reverse-video to :inverse-video."
2899 (if (listp value)
2900 (let (result)
2901 (while value
2902 (let ((key (car value))
2903 (val (car (cdr value))))
2904 (cond ((eq key :italic)
2905 (push :slant result)
2906 (push (if val 'italic 'normal) result))
2907 ((eq key :bold)
2908 (push :weight result)
2909 (push (if val 'bold 'normal) result))
2910 ((eq key :reverse-video)
2911 (push :inverse-video result)
2912 (push val result))
2914 (push key result)
2915 (push val result))))
2916 (setq value (cdr (cdr value))))
2917 (setq result (nreverse result))
2918 result)
2919 value))
2921 (defun custom-face-edit-convert-widget (widget)
2922 "Convert :args as widget types in WIDGET."
2923 (widget-put
2924 widget
2925 :args (mapcar (lambda (arg)
2926 (widget-convert arg
2927 :deactivate 'custom-face-edit-deactivate
2928 :activate 'custom-face-edit-activate
2929 :delete 'custom-face-edit-delete))
2930 (widget-get widget :args)))
2931 widget)
2933 (defun custom-face-edit-deactivate (widget)
2934 "Make face widget WIDGET inactive for user modifications."
2935 (unless (widget-get widget :inactive)
2936 (let ((tag (custom-face-edit-attribute-tag widget))
2937 (from (copy-marker (widget-get widget :from)))
2938 (value (widget-value widget))
2939 (inhibit-read-only t)
2940 (inhibit-modification-hooks t))
2941 (save-excursion
2942 (goto-char from)
2943 (widget-default-delete widget)
2944 (insert tag ": *\n")
2945 (widget-put widget :inactive
2946 (cons value (cons from (- (point) from))))))))
2948 (defun custom-face-edit-activate (widget)
2949 "Make face widget WIDGET inactive for user modifications."
2950 (let ((inactive (widget-get widget :inactive))
2951 (inhibit-read-only t)
2952 (inhibit-modification-hooks t))
2953 (when (consp inactive)
2954 (save-excursion
2955 (goto-char (car (cdr inactive)))
2956 (delete-region (point) (+ (point) (cdr (cdr inactive))))
2957 (widget-put widget :inactive nil)
2958 (widget-apply widget :create)
2959 (widget-value-set widget (car inactive))
2960 (widget-setup)))))
2962 (defun custom-face-edit-delete (widget)
2963 "Remove WIDGET from the buffer."
2964 (let ((inactive (widget-get widget :inactive))
2965 (inhibit-read-only t)
2966 (inhibit-modification-hooks t))
2967 (if (not inactive)
2968 ;; Widget is alive, we don't have to do anything special
2969 (widget-default-delete widget)
2970 ;; WIDGET is already deleted because we did so to inactivate it;
2971 ;; now just get rid of the label we put in its place.
2972 (delete-region (car (cdr inactive))
2973 (+ (car (cdr inactive)) (cdr (cdr inactive))))
2974 (widget-put widget :inactive nil))))
2977 (defun custom-face-edit-attribute-tag (widget)
2978 "Returns the first :tag property in WIDGET or one of its children."
2979 (let ((tag (widget-get widget :tag)))
2980 (or (and (not (equal tag "")) tag)
2981 (let ((children (widget-get widget :children)))
2982 (while (and (null tag) children)
2983 (setq tag (custom-face-edit-attribute-tag (pop children))))
2984 tag))))
2986 ;;; The `custom-display' Widget.
2988 (define-widget 'custom-display 'menu-choice
2989 "Select a display type."
2990 :tag "Display"
2991 :value t
2992 :help-echo "Specify frames where the face attributes should be used."
2993 :args '((const :tag "all" t)
2994 (const :tag "defaults" default)
2995 (checklist
2996 :offset 0
2997 :extra-offset 9
2998 :args ((group :sibling-args (:help-echo "\
2999 Only match the specified window systems.")
3000 (const :format "Type: "
3001 type)
3002 (checklist :inline t
3003 :offset 0
3004 (const :format "X "
3005 :sibling-args (:help-echo "\
3006 The X11 Window System.")
3008 (const :format "PM "
3009 :sibling-args (:help-echo "\
3010 OS/2 Presentation Manager.")
3012 (const :format "W32 "
3013 :sibling-args (:help-echo "\
3014 Windows NT/9X.")
3015 w32)
3016 (const :format "MAC "
3017 :sibling-args (:help-echo "\
3018 Macintosh OS.")
3019 mac)
3020 (const :format "DOS "
3021 :sibling-args (:help-echo "\
3022 Plain MS-DOS.")
3024 (const :format "TTY%n"
3025 :sibling-args (:help-echo "\
3026 Plain text terminals.")
3027 tty)))
3028 (group :sibling-args (:help-echo "\
3029 Only match the frames with the specified color support.")
3030 (const :format "Class: "
3031 class)
3032 (checklist :inline t
3033 :offset 0
3034 (const :format "Color "
3035 :sibling-args (:help-echo "\
3036 Match color frames.")
3037 color)
3038 (const :format "Grayscale "
3039 :sibling-args (:help-echo "\
3040 Match grayscale frames.")
3041 grayscale)
3042 (const :format "Monochrome%n"
3043 :sibling-args (:help-echo "\
3044 Match frames with no color support.")
3045 mono)))
3046 (group :sibling-args (:help-echo "\
3047 The minimum number of colors the frame should support.")
3048 (const :format "" min-colors)
3049 (integer :tag "Minimum number of colors" ))
3050 (group :sibling-args (:help-echo "\
3051 Only match frames with the specified intensity.")
3052 (const :format "\
3053 Background brightness: "
3054 background)
3055 (checklist :inline t
3056 :offset 0
3057 (const :format "Light "
3058 :sibling-args (:help-echo "\
3059 Match frames with light backgrounds.")
3060 light)
3061 (const :format "Dark\n"
3062 :sibling-args (:help-echo "\
3063 Match frames with dark backgrounds.")
3064 dark)))
3065 (group :sibling-args (:help-echo "\
3066 Only match frames that support the specified face attributes.")
3067 (const :format "Supports attributes:" supports)
3068 (custom-face-edit :inline t :format "%n%v"))))))
3070 ;;; The `custom-face' Widget.
3072 (defface custom-face-tag
3073 `((t (:weight bold :height 1.2 :inherit variable-pitch)))
3074 "Face used for face tags."
3075 :group 'custom-faces)
3076 ;; backward-compatibility alias
3077 (put 'custom-face-tag-face 'face-alias 'custom-face-tag)
3079 (defcustom custom-face-default-form 'selected
3080 "Default form of displaying face definition."
3081 :type '(choice (const all)
3082 (const selected)
3083 (const lisp))
3084 :group 'custom-buffer
3085 :version "20.3")
3087 (define-widget 'custom-face 'custom
3088 "Customize face."
3089 :sample-face 'custom-face-tag-face
3090 :help-echo "Set or reset this face."
3091 :documentation-property #'face-doc-string
3092 :value-create 'custom-face-value-create
3093 :action 'custom-face-action
3094 :custom-category 'face
3095 :custom-form nil ; defaults to value of `custom-face-default-form'
3096 :custom-set 'custom-face-set
3097 :custom-save 'custom-face-save
3098 :custom-reset-current 'custom-redraw
3099 :custom-reset-saved 'custom-face-reset-saved
3100 :custom-reset-standard 'custom-face-reset-standard
3101 :custom-standard-value 'custom-face-standard-value
3102 :custom-menu 'custom-face-menu-create)
3104 (define-widget 'custom-face-all 'editable-list
3105 "An editable list of display specifications and attributes."
3106 :entry-format "%i %d %v"
3107 :insert-button-args '(:help-echo "Insert new display specification here.")
3108 :append-button-args '(:help-echo "Append new display specification here.")
3109 :delete-button-args '(:help-echo "Delete this display specification.")
3110 :args '((group :format "%v" custom-display custom-face-edit)))
3112 (defconst custom-face-all (widget-convert 'custom-face-all)
3113 "Converted version of the `custom-face-all' widget.")
3115 (define-widget 'custom-display-unselected 'item
3116 "A display specification that doesn't match the selected display."
3117 :match 'custom-display-unselected-match)
3119 (defun custom-display-unselected-match (widget value)
3120 "Non-nil if VALUE is an unselected display specification."
3121 (not (face-spec-set-match-display value (selected-frame))))
3123 (define-widget 'custom-face-selected 'group
3124 "Edit the attributes of the selected display in a face specification."
3125 :args '((choice :inline t
3126 (group :tag "With Defaults" :inline t
3127 (group (const :tag "" default)
3128 (custom-face-edit :tag " Default\n Attributes"))
3129 (repeat :format ""
3130 :inline t
3131 (group custom-display-unselected sexp))
3132 (group (sexp :format "")
3133 (custom-face-edit :tag " Overriding\n Attributes"))
3134 (repeat :format ""
3135 :inline t
3136 sexp))
3137 (group :tag "No Defaults" :inline t
3138 (repeat :format ""
3139 :inline t
3140 (group custom-display-unselected sexp))
3141 (group (sexp :format "")
3142 (custom-face-edit :tag "\n Attributes"))
3143 (repeat :format ""
3144 :inline t
3145 sexp)))))
3149 (defconst custom-face-selected (widget-convert 'custom-face-selected)
3150 "Converted version of the `custom-face-selected' widget.")
3152 (defun custom-filter-face-spec (spec filter-index &optional default-filter)
3153 "Return a canonicalized version of SPEC using.
3154 FILTER-INDEX is the index in the entry for each attribute in
3155 `custom-face-attributes' at which the appropriate filter function can be
3156 found, and DEFAULT-FILTER is the filter to apply for attributes that
3157 don't specify one."
3158 (mapcar (lambda (entry)
3159 ;; Filter a single face-spec entry
3160 (let ((tests (car entry))
3161 (unfiltered-attrs
3162 ;; Handle both old- and new-style attribute syntax
3163 (if (listp (car (cdr entry)))
3164 (car (cdr entry))
3165 (cdr entry)))
3166 (filtered-attrs nil))
3167 ;; Filter each face attribute
3168 (while unfiltered-attrs
3169 (let* ((attr (pop unfiltered-attrs))
3170 (pre-filtered-value (pop unfiltered-attrs))
3171 (filter
3172 (or (nth filter-index (assq attr custom-face-attributes))
3173 default-filter))
3174 (filtered-value
3175 (if filter
3176 (funcall filter pre-filtered-value)
3177 pre-filtered-value)))
3178 (push filtered-value filtered-attrs)
3179 (push attr filtered-attrs)))
3181 (list tests filtered-attrs)))
3182 spec))
3184 (defun custom-pre-filter-face-spec (spec)
3185 "Return SPEC changed as necessary for editing by the face customization widget.
3186 SPEC must be a full face spec."
3187 (custom-filter-face-spec spec 2))
3189 (defun custom-post-filter-face-spec (spec)
3190 "Return the customized SPEC in a form suitable for setting the face."
3191 (custom-filter-face-spec spec 3))
3193 (defun custom-face-value-create (widget)
3194 "Create a list of the display specifications for WIDGET."
3195 (let ((buttons (widget-get widget :buttons))
3196 children
3197 (symbol (widget-get widget :value))
3198 (tag (widget-get widget :tag))
3199 (state (widget-get widget :custom-state))
3200 (begin (point))
3201 (is-last (widget-get widget :custom-last))
3202 (prefix (widget-get widget :custom-prefix)))
3203 (unless tag
3204 (setq tag (prin1-to-string symbol)))
3205 (cond ((eq custom-buffer-style 'tree)
3206 (insert prefix (if is-last " `--- " " |--- "))
3207 (push (widget-create-child-and-convert
3208 widget 'custom-browse-face-tag)
3209 buttons)
3210 (insert " " tag "\n")
3211 (widget-put widget :buttons buttons))
3213 ;; Create tag.
3214 (insert tag)
3215 (widget-specify-sample widget begin (point))
3216 (if (eq custom-buffer-style 'face)
3217 (insert " ")
3218 (if (string-match "face\\'" tag)
3219 (insert ":")
3220 (insert " face: ")))
3221 ;; Sample.
3222 (push (widget-create-child-and-convert widget 'item
3223 :format "(%{%t%})"
3224 :sample-face symbol
3225 :tag "sample")
3226 buttons)
3227 ;; Visibility.
3228 (insert " ")
3229 (push (widget-create-child-and-convert
3230 widget 'visibility
3231 :help-echo "Hide or show this face."
3232 :on "Hide Face"
3233 :off "Show Face"
3234 :action 'custom-toggle-parent
3235 (not (eq state 'hidden)))
3236 buttons)
3237 ;; Magic.
3238 (insert "\n")
3239 (let ((magic (widget-create-child-and-convert
3240 widget 'custom-magic nil)))
3241 (widget-put widget :custom-magic magic)
3242 (push magic buttons))
3243 ;; Update buttons.
3244 (widget-put widget :buttons buttons)
3245 ;; Insert documentation.
3246 (widget-default-format-handler widget ?h)
3247 ;; The comment field
3248 (unless (eq state 'hidden)
3249 (let* ((comment (get symbol 'face-comment))
3250 (comment-widget
3251 (widget-create-child-and-convert
3252 widget 'custom-comment
3253 :parent widget
3254 :value (or comment ""))))
3255 (widget-put widget :comment-widget comment-widget)
3256 (push comment-widget children)))
3257 ;; See also.
3258 (unless (eq state 'hidden)
3259 (when (eq (widget-get widget :custom-level) 1)
3260 (custom-add-parent-links widget))
3261 (custom-add-see-also widget))
3262 ;; Editor.
3263 (unless (eq (preceding-char) ?\n)
3264 (insert "\n"))
3265 (unless (eq state 'hidden)
3266 (message "Creating face editor...")
3267 (custom-load-widget widget)
3268 (unless (widget-get widget :custom-form)
3269 (widget-put widget :custom-form custom-face-default-form))
3270 (let* ((symbol (widget-value widget))
3271 (spec (or (get symbol 'customized-face)
3272 (get symbol 'saved-face)
3273 (get symbol 'face-defface-spec)
3274 ;; Attempt to construct it.
3275 (list (list t (custom-face-attributes-get
3276 symbol (selected-frame))))))
3277 (form (widget-get widget :custom-form))
3278 (indent (widget-get widget :indent))
3279 edit)
3280 ;; If the user has changed this face in some other way,
3281 ;; edit it as the user has specified it.
3282 (if (not (face-spec-match-p symbol spec (selected-frame)))
3283 (setq spec (list (list t (face-attr-construct symbol (selected-frame))))))
3284 (setq spec (custom-pre-filter-face-spec spec))
3285 (setq edit (widget-create-child-and-convert
3286 widget
3287 (cond ((and (eq form 'selected)
3288 (widget-apply custom-face-selected
3289 :match spec))
3290 (when indent (insert-char ?\ indent))
3291 'custom-face-selected)
3292 ((and (not (eq form 'lisp))
3293 (widget-apply custom-face-all
3294 :match spec))
3295 'custom-face-all)
3297 (when indent (insert-char ?\ indent))
3298 'sexp))
3299 :value spec))
3300 (custom-face-state-set widget)
3301 (push edit children)
3302 (widget-put widget :children children))
3303 (message "Creating face editor...done"))))))
3305 (defvar custom-face-menu
3306 `(("Set for Current Session" custom-face-set)
3307 ,@(when (or custom-file user-init-file)
3308 '(("Save for Future Sessions" custom-face-save)))
3309 ("Undo Edits" custom-redraw
3310 (lambda (widget)
3311 (memq (widget-get widget :custom-state) '(modified changed))))
3312 ("Reset to Saved" custom-face-reset-saved
3313 (lambda (widget)
3314 (or (get (widget-value widget) 'saved-face)
3315 (get (widget-value widget) 'saved-face-comment))))
3316 ,@(when (or custom-file user-init-file)
3317 '(("Erase Customization" custom-face-reset-standard
3318 (lambda (widget)
3319 (get (widget-value widget) 'face-defface-spec)))))
3320 ("---" ignore ignore)
3321 ("Add Comment" custom-comment-show custom-comment-invisible-p)
3322 ("---" ignore ignore)
3323 ("For Current Display" custom-face-edit-selected
3324 (lambda (widget)
3325 (not (eq (widget-get widget :custom-form) 'selected))))
3326 ("For All Kinds of Displays" custom-face-edit-all
3327 (lambda (widget)
3328 (not (eq (widget-get widget :custom-form) 'all))))
3329 ("Show Lisp Expression" custom-face-edit-lisp
3330 (lambda (widget)
3331 (not (eq (widget-get widget :custom-form) 'lisp)))))
3332 "Alist of actions for the `custom-face' widget.
3333 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3334 the menu entry, ACTION is the function to call on the widget when the
3335 menu is selected, and FILTER is a predicate which takes a `custom-face'
3336 widget as an argument, and returns non-nil if ACTION is valid on that
3337 widget. If FILTER is nil, ACTION is always valid.")
3339 (defun custom-face-edit-selected (widget)
3340 "Edit selected attributes of the value of WIDGET."
3341 (widget-put widget :custom-state 'unknown)
3342 (widget-put widget :custom-form 'selected)
3343 (custom-redraw widget))
3345 (defun custom-face-edit-all (widget)
3346 "Edit all attributes of the value of WIDGET."
3347 (widget-put widget :custom-state 'unknown)
3348 (widget-put widget :custom-form 'all)
3349 (custom-redraw widget))
3351 (defun custom-face-edit-lisp (widget)
3352 "Edit the Lisp representation of the value of WIDGET."
3353 (widget-put widget :custom-state 'unknown)
3354 (widget-put widget :custom-form 'lisp)
3355 (custom-redraw widget))
3357 (defun custom-face-state-set (widget)
3358 "Set the state of WIDGET."
3359 (let* ((symbol (widget-value widget))
3360 (comment (get symbol 'face-comment))
3361 tmp temp
3362 (state
3363 (cond ((progn
3364 (setq tmp (get symbol 'customized-face))
3365 (setq temp (get symbol 'customized-face-comment))
3366 (or tmp temp))
3367 (if (equal temp comment)
3368 'set
3369 'changed))
3370 ((progn
3371 (setq tmp (get symbol 'saved-face))
3372 (setq temp (get symbol 'saved-face-comment))
3373 (or tmp temp))
3374 (if (equal temp comment)
3375 (cond
3376 ((eq 'user (caar (get symbol 'theme-face)))
3377 'saved)
3378 ((eq 'changed (caar (get symbol 'theme-face)))
3379 'changed)
3380 (t 'themed))
3381 'changed))
3382 ((get symbol 'face-defface-spec)
3383 (if (equal comment nil)
3384 'standard
3385 'changed))
3387 'rogue))))
3388 ;; If the user called set-face-attribute to change the default
3389 ;; for new frames, this face is "set outside of Customize".
3390 (if (and (not (eq state 'rogue))
3391 (get symbol 'face-modified))
3392 (setq state 'changed))
3393 (widget-put widget :custom-state state)))
3395 (defun custom-face-action (widget &optional event)
3396 "Show the menu for `custom-face' WIDGET.
3397 Optional EVENT is the location for the menu."
3398 (if (eq (widget-get widget :custom-state) 'hidden)
3399 (custom-toggle-hide widget)
3400 (let* ((completion-ignore-case t)
3401 (symbol (widget-get widget :value))
3402 (answer (widget-choose (concat "Operation on "
3403 (custom-unlispify-tag-name symbol))
3404 (custom-menu-filter custom-face-menu
3405 widget)
3406 event)))
3407 (if answer
3408 (funcall answer widget)))))
3410 (defun custom-face-set (widget)
3411 "Make the face attributes in WIDGET take effect."
3412 (let* ((symbol (widget-value widget))
3413 (child (car (widget-get widget :children)))
3414 (value (custom-post-filter-face-spec (widget-value child)))
3415 (comment-widget (widget-get widget :comment-widget))
3416 (comment (widget-value comment-widget)))
3417 (when (equal comment "")
3418 (setq comment nil)
3419 ;; Make the comment invisible by hand if it's empty
3420 (custom-comment-hide comment-widget))
3421 (put symbol 'customized-face value)
3422 (if (face-spec-choose value)
3423 (face-spec-set symbol value)
3424 ;; face-set-spec ignores empty attribute lists, so just give it
3425 ;; something harmless instead.
3426 (face-spec-set symbol '((t :foreground unspecified))))
3427 (custom-push-theme 'theme-face symbol 'user 'set value)
3428 (put symbol 'customized-face-comment comment)
3429 (put symbol 'face-comment comment)
3430 (custom-face-state-set widget)
3431 (custom-redraw-magic widget)))
3433 (defun custom-face-save (widget)
3434 "Save in `.emacs' the face attributes in WIDGET."
3435 (let* ((symbol (widget-value widget))
3436 (child (car (widget-get widget :children)))
3437 (value (custom-post-filter-face-spec (widget-value child)))
3438 (comment-widget (widget-get widget :comment-widget))
3439 (comment (widget-value comment-widget)))
3440 (when (equal comment "")
3441 (setq comment nil)
3442 ;; Make the comment invisible by hand if it's empty
3443 (custom-comment-hide comment-widget))
3444 (custom-push-theme 'theme-face symbol 'user 'set value)
3445 (if (face-spec-choose value)
3446 (face-spec-set symbol value)
3447 ;; face-set-spec ignores empty attribute lists, so just give it
3448 ;; something harmless instead.
3449 (face-spec-set symbol '((t :foreground unspecified))))
3450 (unless (eq (widget-get widget :custom-state) 'standard)
3451 (put symbol 'saved-face value))
3452 (put symbol 'customized-face nil)
3453 (put symbol 'face-comment comment)
3454 (put symbol 'customized-face-comment nil)
3455 (put symbol 'saved-face-comment comment)
3456 (custom-save-all)
3457 (custom-face-state-set widget)
3458 (custom-redraw-magic widget)))
3460 ;; For backward compatibility.
3461 (define-obsolete-function-alias 'custom-face-save-command 'custom-face-save
3462 "22.1")
3464 (defun custom-face-reset-saved (widget)
3465 "Restore WIDGET to the face's default attributes."
3466 (let* ((symbol (widget-value widget))
3467 (child (car (widget-get widget :children)))
3468 (value (get symbol 'saved-face))
3469 (comment (get symbol 'saved-face-comment))
3470 (comment-widget (widget-get widget :comment-widget)))
3471 (unless (or value comment)
3472 (error "No saved value for this face"))
3473 (put symbol 'customized-face nil)
3474 (put symbol 'customized-face-comment nil)
3475 (custom-push-theme 'theme-face symbol 'user 'set value)
3476 (face-spec-set symbol value)
3477 (put symbol 'face-comment comment)
3478 (widget-value-set child value)
3479 ;; This call manages the comment visibility
3480 (widget-value-set comment-widget (or comment ""))
3481 (custom-face-state-set widget)
3482 (custom-redraw-magic widget)))
3484 (defun custom-face-standard-value (widget)
3485 (get (widget-value widget) 'face-defface-spec))
3487 (defun custom-face-reset-standard (widget)
3488 "Restore WIDGET to the face's standard attribute values.
3489 This operation eliminates any saved attributes for the face,
3490 restoring it to the state of a face that has never been customized."
3491 (let* ((symbol (widget-value widget))
3492 (child (car (widget-get widget :children)))
3493 (value (get symbol 'face-defface-spec))
3494 (comment-widget (widget-get widget :comment-widget)))
3495 (unless value
3496 (error "No standard setting for this face"))
3497 (put symbol 'customized-face nil)
3498 (put symbol 'customized-face-comment nil)
3499 (custom-push-theme 'theme-face symbol 'user 'reset)
3500 (custom-theme-recalc-face symbol)
3501 (when (or (get symbol 'saved-face) (get symbol 'saved-face-comment))
3502 (put symbol 'saved-face nil)
3503 (put symbol 'saved-face-comment nil)
3504 (custom-save-all))
3505 (put symbol 'face-comment nil)
3506 (widget-value-set child value)
3507 ;; This call manages the comment visibility
3508 (widget-value-set comment-widget "")
3509 (custom-face-state-set widget)
3510 (custom-redraw-magic widget)))
3512 ;;; The `face' Widget.
3514 (defvar widget-face-prompt-value-history nil
3515 "History of input to `widget-face-prompt-value'.")
3517 (define-widget 'face 'symbol
3518 "A Lisp face name (with sample)."
3519 :format "%{%t%}: (%{sample%}) %v"
3520 :tag "Face"
3521 :value 'default
3522 :sample-face-get 'widget-face-sample-face-get
3523 :notify 'widget-face-notify
3524 :match (lambda (widget value) (facep value))
3525 :complete-function (lambda ()
3526 (interactive)
3527 (lisp-complete-symbol 'facep))
3528 :prompt-match 'facep
3529 :prompt-history 'widget-face-prompt-value-history
3530 :validate (lambda (widget)
3531 (unless (facep (widget-value widget))
3532 (widget-put widget
3533 :error (format "Invalid face: %S"
3534 (widget-value widget)))
3535 widget)))
3537 (defun widget-face-sample-face-get (widget)
3538 (let ((value (widget-value widget)))
3539 (if (facep value)
3540 value
3541 'default)))
3543 (defun widget-face-notify (widget child &optional event)
3544 "Update the sample, and notify the parent."
3545 (overlay-put (widget-get widget :sample-overlay)
3546 'face (widget-apply widget :sample-face-get))
3547 (widget-default-notify widget child event))
3550 ;;; The `hook' Widget.
3552 (define-widget 'hook 'list
3553 "A emacs lisp hook"
3554 :value-to-internal (lambda (widget value)
3555 (if (and value (symbolp value))
3556 (list value)
3557 value))
3558 :match (lambda (widget value)
3559 (or (symbolp value)
3560 (widget-group-match widget value)))
3561 ;; Avoid adding undefined functions to the hook, especially for
3562 ;; things like `find-file-hook' or even more basic ones, to avoid
3563 ;; chaos.
3564 :set (lambda (symbol value)
3565 (dolist (elt value)
3566 (if (fboundp elt)
3567 (add-hook symbol elt))))
3568 :convert-widget 'custom-hook-convert-widget
3569 :tag "Hook")
3571 (defun custom-hook-convert-widget (widget)
3572 ;; Handle `:options'.
3573 (let* ((options (widget-get widget :options))
3574 (other `(editable-list :inline t
3575 :entry-format "%i %d%v"
3576 (function :format " %v")))
3577 (args (if options
3578 (list `(checklist :inline t
3579 ,@(mapcar (lambda (entry)
3580 `(function-item ,entry))
3581 options))
3582 other)
3583 (list other))))
3584 (widget-put widget :args args)
3585 widget))
3587 ;;; The `custom-group-link' Widget.
3589 (define-widget 'custom-group-link 'link
3590 "Show parent in other window when activated."
3591 :button-face 'custom-link
3592 :mouse-face 'highlight
3593 :help-echo "Create customization buffer for this group."
3594 :action 'custom-group-link-action)
3596 (defun custom-group-link-action (widget &rest ignore)
3597 (customize-group (widget-value widget)))
3599 ;;; The `custom-group' Widget.
3601 (defcustom custom-group-tag-faces nil
3602 ;; In XEmacs, this ought to play games with font size.
3603 ;; Fixme: make it do so in Emacs.
3604 "Face used for group tags.
3605 The first member is used for level 1 groups, the second for level 2,
3606 and so forth. The remaining group tags are shown with `custom-group-tag'."
3607 :type '(repeat face)
3608 :group 'custom-faces)
3610 (defface custom-group-tag-1
3611 `((((class color)
3612 (background dark))
3613 (:foreground "pink" :weight bold :height 1.2 :inherit variable-pitch))
3614 (((min-colors 88) (class color)
3615 (background light))
3616 (:foreground "red1" :weight bold :height 1.2 :inherit variable-pitch))
3617 (((class color)
3618 (background light))
3619 (:foreground "red" :weight bold :height 1.2 :inherit variable-pitch))
3620 (t (:weight bold)))
3621 "Face used for group tags."
3622 :group 'custom-faces)
3623 ;; backward-compatibility alias
3624 (put 'custom-group-tag-face-1 'face-alias 'custom-group-tag-1)
3626 (defface custom-group-tag
3627 `((((class color)
3628 (background dark))
3629 (:foreground "light blue" :weight bold :height 1.2))
3630 (((min-colors 88) (class color)
3631 (background light))
3632 (:foreground "blue1" :weight bold :height 1.2))
3633 (((class color)
3634 (background light))
3635 (:foreground "blue" :weight bold :height 1.2))
3636 (t (:weight bold)))
3637 "Face used for low level group tags."
3638 :group 'custom-faces)
3639 ;; backward-compatibility alias
3640 (put 'custom-group-tag-face 'face-alias 'custom-group-tag)
3642 (define-widget 'custom-group 'custom
3643 "Customize group."
3644 :format "%v"
3645 :sample-face-get 'custom-group-sample-face-get
3646 :documentation-property 'group-documentation
3647 :help-echo "Set or reset all members of this group."
3648 :value-create 'custom-group-value-create
3649 :action 'custom-group-action
3650 :custom-category 'group
3651 :custom-set 'custom-group-set
3652 :custom-save 'custom-group-save
3653 :custom-reset-current 'custom-group-reset-current
3654 :custom-reset-saved 'custom-group-reset-saved
3655 :custom-reset-standard 'custom-group-reset-standard
3656 :custom-menu 'custom-group-menu-create)
3658 (defun custom-group-sample-face-get (widget)
3659 ;; Use :sample-face.
3660 (or (nth (1- (widget-get widget :custom-level)) custom-group-tag-faces)
3661 'custom-group-tag))
3663 (define-widget 'custom-group-visibility 'visibility
3664 "An indicator and manipulator for hidden group contents."
3665 :create 'custom-group-visibility-create)
3667 (defun custom-group-visibility-create (widget)
3668 (let ((visible (widget-value widget)))
3669 (if visible
3670 (insert "--------")))
3671 (widget-default-create widget))
3673 (defun custom-group-members (symbol groups-only)
3674 "Return SYMBOL's custom group members.
3675 If GROUPS-ONLY non-nil, return only those members that are groups."
3676 (if (not groups-only)
3677 (get symbol 'custom-group)
3678 (let (members)
3679 (dolist (entry (get symbol 'custom-group))
3680 (when (eq (nth 1 entry) 'custom-group)
3681 (push entry members)))
3682 (nreverse members))))
3684 (defun custom-group-value-create (widget)
3685 "Insert a customize group for WIDGET in the current buffer."
3686 (unless (eq (widget-get widget :custom-state) 'hidden)
3687 (custom-load-widget widget))
3688 (let* ((state (widget-get widget :custom-state))
3689 (level (widget-get widget :custom-level))
3690 ;; (indent (widget-get widget :indent))
3691 (prefix (widget-get widget :custom-prefix))
3692 (buttons (widget-get widget :buttons))
3693 (tag (widget-get widget :tag))
3694 (symbol (widget-value widget))
3695 (members (custom-group-members symbol
3696 (and (eq custom-buffer-style 'tree)
3697 custom-browse-only-groups))))
3698 (cond ((and (eq custom-buffer-style 'tree)
3699 (eq state 'hidden)
3700 (or members (custom-unloaded-widget-p widget)))
3701 (custom-browse-insert-prefix prefix)
3702 (push (widget-create-child-and-convert
3703 widget 'custom-browse-visibility
3704 ;; :tag-glyph "plus"
3705 :tag "+")
3706 buttons)
3707 (insert "-- ")
3708 ;; (widget-glyph-insert nil "-- " "horizontal")
3709 (push (widget-create-child-and-convert
3710 widget 'custom-browse-group-tag)
3711 buttons)
3712 (insert " " tag "\n")
3713 (widget-put widget :buttons buttons))
3714 ((and (eq custom-buffer-style 'tree)
3715 (zerop (length members)))
3716 (custom-browse-insert-prefix prefix)
3717 (insert "[ ]-- ")
3718 ;; (widget-glyph-insert nil "[ ]" "empty")
3719 ;; (widget-glyph-insert nil "-- " "horizontal")
3720 (push (widget-create-child-and-convert
3721 widget 'custom-browse-group-tag)
3722 buttons)
3723 (insert " " tag "\n")
3724 (widget-put widget :buttons buttons))
3725 ((eq custom-buffer-style 'tree)
3726 (custom-browse-insert-prefix prefix)
3727 (if (zerop (length members))
3728 (progn
3729 (custom-browse-insert-prefix prefix)
3730 (insert "[ ]-- ")
3731 ;; (widget-glyph-insert nil "[ ]" "empty")
3732 ;; (widget-glyph-insert nil "-- " "horizontal")
3733 (push (widget-create-child-and-convert
3734 widget 'custom-browse-group-tag)
3735 buttons)
3736 (insert " " tag "\n")
3737 (widget-put widget :buttons buttons))
3738 (push (widget-create-child-and-convert
3739 widget 'custom-browse-visibility
3740 ;; :tag-glyph "minus"
3741 :tag "-")
3742 buttons)
3743 (insert "-\\ ")
3744 ;; (widget-glyph-insert nil "-\\ " "top")
3745 (push (widget-create-child-and-convert
3746 widget 'custom-browse-group-tag)
3747 buttons)
3748 (insert " " tag "\n")
3749 (widget-put widget :buttons buttons)
3750 (message "Creating group...")
3751 (let* ((members (custom-sort-items members
3752 custom-browse-sort-alphabetically
3753 custom-browse-order-groups))
3754 (prefixes (widget-get widget :custom-prefixes))
3755 (custom-prefix-list (custom-prefix-add symbol prefixes))
3756 (extra-prefix (if (widget-get widget :custom-last)
3758 " | "))
3759 (prefix (concat prefix extra-prefix))
3760 children entry)
3761 (while members
3762 (setq entry (car members)
3763 members (cdr members))
3764 (push (widget-create-child-and-convert
3765 widget (nth 1 entry)
3766 :group widget
3767 :tag (custom-unlispify-tag-name (nth 0 entry))
3768 :custom-prefixes custom-prefix-list
3769 :custom-level (1+ level)
3770 :custom-last (null members)
3771 :value (nth 0 entry)
3772 :custom-prefix prefix)
3773 children))
3774 (widget-put widget :children (reverse children)))
3775 (message "Creating group...done")))
3776 ;; Nested style.
3777 ((eq state 'hidden)
3778 ;; Create level indicator.
3779 (unless (eq custom-buffer-style 'links)
3780 (insert-char ?\ (* custom-buffer-indent (1- level)))
3781 (insert "-- "))
3782 ;; Create tag.
3783 (let ((begin (point)))
3784 (insert tag)
3785 (widget-specify-sample widget begin (point)))
3786 (insert " group: ")
3787 ;; Create link/visibility indicator.
3788 (if (eq custom-buffer-style 'links)
3789 (push (widget-create-child-and-convert
3790 widget 'custom-group-link
3791 :tag "Go to Group"
3792 symbol)
3793 buttons)
3794 (push (widget-create-child-and-convert
3795 widget 'custom-group-visibility
3796 :help-echo "Show members of this group."
3797 :action 'custom-toggle-parent
3798 (not (eq state 'hidden)))
3799 buttons))
3800 (insert " \n")
3801 ;; Create magic button.
3802 (let ((magic (widget-create-child-and-convert
3803 widget 'custom-magic nil)))
3804 (widget-put widget :custom-magic magic)
3805 (push magic buttons))
3806 ;; Update buttons.
3807 (widget-put widget :buttons buttons)
3808 ;; Insert documentation.
3809 (if (and (eq custom-buffer-style 'links) (> level 1))
3810 (widget-put widget :documentation-indent 0))
3811 (widget-default-format-handler widget ?h))
3812 ;; Nested style.
3813 (t ;Visible.
3814 ;; Add parent groups references above the group.
3815 (if t ;;; This should test that the buffer
3816 ;;; was made to display a group.
3817 (when (eq level 1)
3818 (if (custom-add-parent-links widget
3819 "Go to parent group:")
3820 (insert "\n"))))
3821 ;; Create level indicator.
3822 (insert-char ?\ (* custom-buffer-indent (1- level)))
3823 (insert "/- ")
3824 ;; Create tag.
3825 (let ((start (point)))
3826 (insert tag)
3827 (widget-specify-sample widget start (point)))
3828 (insert " group: ")
3829 ;; Create visibility indicator.
3830 (unless (eq custom-buffer-style 'links)
3831 (insert "--------")
3832 (push (widget-create-child-and-convert
3833 widget 'visibility
3834 :help-echo "Hide members of this group."
3835 :action 'custom-toggle-parent
3836 (not (eq state 'hidden)))
3837 buttons)
3838 (insert " "))
3839 ;; Create more dashes.
3840 ;; Use 76 instead of 75 to compensate for the temporary "<"
3841 ;; added by `widget-insert'.
3842 (insert-char ?- (- 76 (current-column)
3843 (* custom-buffer-indent level)))
3844 (insert "\\\n")
3845 ;; Create magic button.
3846 (let ((magic (widget-create-child-and-convert
3847 widget 'custom-magic
3848 :indent 0
3849 nil)))
3850 (widget-put widget :custom-magic magic)
3851 (push magic buttons))
3852 ;; Update buttons.
3853 (widget-put widget :buttons buttons)
3854 ;; Insert documentation.
3855 (widget-default-format-handler widget ?h)
3856 ;; Parent groups.
3857 (if nil ;;; This should test that the buffer
3858 ;;; was not made to display a group.
3859 (when (eq level 1)
3860 (insert-char ?\ custom-buffer-indent)
3861 (custom-add-parent-links widget)))
3862 (custom-add-see-also widget
3863 (make-string (* custom-buffer-indent level)
3864 ?\ ))
3865 ;; Members.
3866 (message "Creating group...")
3867 (let* ((members (custom-sort-items members
3868 custom-buffer-sort-alphabetically
3869 custom-buffer-order-groups))
3870 (prefixes (widget-get widget :custom-prefixes))
3871 (custom-prefix-list (custom-prefix-add symbol prefixes))
3872 (length (length members))
3873 (count 0)
3874 (children (mapcar (lambda (entry)
3875 (widget-insert "\n")
3876 (message "\
3877 Creating group members... %2d%%"
3878 (/ (* 100.0 count) length))
3879 (setq count (1+ count))
3880 (prog1
3881 (widget-create-child-and-convert
3882 widget (nth 1 entry)
3883 :group widget
3884 :tag (custom-unlispify-tag-name
3885 (nth 0 entry))
3886 :custom-prefixes custom-prefix-list
3887 :custom-level (1+ level)
3888 :value (nth 0 entry))
3889 (unless (eq (preceding-char) ?\n)
3890 (widget-insert "\n"))))
3891 members)))
3892 (message "Creating group magic...")
3893 (mapc 'custom-magic-reset children)
3894 (message "Creating group state...")
3895 (widget-put widget :children children)
3896 (custom-group-state-update widget)
3897 (message "Creating group... done"))
3898 ;; End line
3899 (insert "\n")
3900 (insert-char ?\ (* custom-buffer-indent (1- level)))
3901 (insert "\\- " (widget-get widget :tag) " group end ")
3902 (insert-char ?- (- 75 (current-column) (* custom-buffer-indent level)))
3903 (insert "/\n")))))
3905 (defvar custom-group-menu
3906 `(("Set for Current Session" custom-group-set
3907 (lambda (widget)
3908 (eq (widget-get widget :custom-state) 'modified)))
3909 ,@(when (or custom-file user-init-file)
3910 '(("Save for Future Sessions" custom-group-save
3911 (lambda (widget)
3912 (memq (widget-get widget :custom-state) '(modified set))))))
3913 ("Undo Edits" custom-group-reset-current
3914 (lambda (widget)
3915 (memq (widget-get widget :custom-state) '(modified))))
3916 ("Reset to Saved" custom-group-reset-saved
3917 (lambda (widget)
3918 (memq (widget-get widget :custom-state) '(modified set))))
3919 ,@(when (or custom-file user-init-file)
3920 '(("Erase Customization" custom-group-reset-standard
3921 (lambda (widget)
3922 (memq (widget-get widget :custom-state) '(modified set saved)))))))
3923 "Alist of actions for the `custom-group' widget.
3924 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3925 the menu entry, ACTION is the function to call on the widget when the
3926 menu is selected, and FILTER is a predicate which takes a `custom-group'
3927 widget as an argument, and returns non-nil if ACTION is valid on that
3928 widget. If FILTER is nil, ACTION is always valid.")
3930 (defun custom-group-action (widget &optional event)
3931 "Show the menu for `custom-group' WIDGET.
3932 Optional EVENT is the location for the menu."
3933 (if (eq (widget-get widget :custom-state) 'hidden)
3934 (custom-toggle-hide widget)
3935 (let* ((completion-ignore-case t)
3936 (answer (widget-choose (concat "Operation on "
3937 (custom-unlispify-tag-name
3938 (widget-get widget :value)))
3939 (custom-menu-filter custom-group-menu
3940 widget)
3941 event)))
3942 (if answer
3943 (funcall answer widget)))))
3945 (defun custom-group-set (widget)
3946 "Set changes in all modified group members."
3947 (let ((children (widget-get widget :children)))
3948 (mapc (lambda (child)
3949 (when (eq (widget-get child :custom-state) 'modified)
3950 (widget-apply child :custom-set)))
3951 children )))
3953 (defun custom-group-save (widget)
3954 "Save all modified group members."
3955 (let ((children (widget-get widget :children)))
3956 (mapc (lambda (child)
3957 (when (memq (widget-get child :custom-state) '(modified set))
3958 (widget-apply child :custom-save)))
3959 children )))
3961 (defun custom-group-reset-current (widget)
3962 "Reset all modified group members."
3963 (let ((children (widget-get widget :children)))
3964 (mapc (lambda (child)
3965 (when (eq (widget-get child :custom-state) 'modified)
3966 (widget-apply child :custom-reset-current)))
3967 children )))
3969 (defun custom-group-reset-saved (widget)
3970 "Reset all modified or set group members."
3971 (let ((children (widget-get widget :children)))
3972 (mapc (lambda (child)
3973 (when (memq (widget-get child :custom-state) '(modified set))
3974 (widget-apply child :custom-reset-saved)))
3975 children )))
3977 (defun custom-group-reset-standard (widget)
3978 "Reset all modified, set, or saved group members."
3979 (let ((children (widget-get widget :children)))
3980 (mapc (lambda (child)
3981 (when (memq (widget-get child :custom-state)
3982 '(modified set saved))
3983 (widget-apply child :custom-reset-standard)))
3984 children )))
3986 (defun custom-group-state-update (widget)
3987 "Update magic."
3988 (unless (eq (widget-get widget :custom-state) 'hidden)
3989 (let* ((children (widget-get widget :children))
3990 (states (mapcar (lambda (child)
3991 (widget-get child :custom-state))
3992 children))
3993 (magics custom-magic-alist)
3994 (found 'standard))
3995 (while magics
3996 (let ((magic (car (car magics))))
3997 (if (and (not (eq magic 'hidden))
3998 (memq magic states))
3999 (setq found magic
4000 magics nil)
4001 (setq magics (cdr magics)))))
4002 (widget-put widget :custom-state found)))
4003 (custom-magic-reset widget))
4005 ;;; Reading and writing the custom file.
4007 ;;;###autoload
4008 (defcustom custom-file nil
4009 "File used for storing customization information.
4010 The default is nil, which means to use your init file
4011 as specified by `user-init-file'. If the value is not nil,
4012 it should be an absolute file name.
4014 You can set this option through Custom, if you carefully read the
4015 last paragraph below. However, usually it is simpler to write
4016 something like the following in your init file:
4018 \(setq custom-file \"~/.emacs-custom.el\")
4019 \(load custom-file)
4021 Note that both lines are necessary: the first line tells Custom to
4022 save all customizations in this file, but does not load it.
4024 When you change this variable outside Custom, look in the
4025 previous custom file \(usually your init file) for the
4026 forms `(custom-set-variables ...)' and `(custom-set-faces ...)',
4027 and copy them (whichever ones you find) to the new custom file.
4028 This will preserve your existing customizations.
4030 If you save this option using Custom, Custom will write all
4031 currently saved customizations, including the new one for this
4032 option itself, into the file you specify, overwriting any
4033 `custom-set-variables' and `custom-set-faces' forms already
4034 present in that file. It will not delete any customizations from
4035 the old custom file. You should do that manually if that is what you
4036 want. You also have to put something like `\(load \"CUSTOM-FILE\")
4037 in your init file, where CUSTOM-FILE is the actual name of the
4038 file. Otherwise, Emacs will not load the file when it starts up,
4039 and hence will not set `custom-file' to that file either."
4040 :type '(choice (const :tag "Your Emacs init file" nil)
4041 (file :format "%t:%v%d"
4042 :doc
4043 "Please read entire docstring below before setting \
4044 this through Custom.
4045 Click om \"More\" \(or position point there and press RETURN)
4046 if only the first line of the docstring is shown."))
4047 :group 'customize)
4049 (defun custom-file ()
4050 "Return the file name for saving customizations."
4051 (file-chase-links
4052 (or custom-file
4053 (let ((user-init-file user-init-file)
4054 (default-init-file
4055 (if (eq system-type 'ms-dos) "~/_emacs" "~/.emacs")))
4056 (when (null user-init-file)
4057 (if (or (file-exists-p default-init-file)
4058 (and (eq system-type 'windows-nt)
4059 (file-exists-p "~/_emacs")))
4060 ;; Started with -q, i.e. the file containing
4061 ;; Custom settings hasn't been read. Saving
4062 ;; settings there would overwrite other settings.
4063 (error "Saving settings from \"emacs -q\" would overwrite existing customizations"))
4064 (setq user-init-file default-init-file))
4065 user-init-file))))
4067 ;;;###autoload
4068 (defun custom-save-all ()
4069 "Save all customizations in `custom-file'."
4070 (let* ((filename (custom-file))
4071 (recentf-exclude (if recentf-mode
4072 (cons (concat "\\`"
4073 (regexp-quote (custom-file))
4074 "\\'")
4075 recentf-exclude)))
4076 (old-buffer (find-buffer-visiting filename)))
4077 (with-current-buffer (or old-buffer (find-file-noselect filename))
4078 (let ((inhibit-read-only t))
4079 (custom-save-variables)
4080 (custom-save-faces))
4081 (let ((file-precious-flag t))
4082 (save-buffer))
4083 (unless old-buffer
4084 (kill-buffer (current-buffer))))))
4086 ;;;###autoload
4087 (defun customize-save-customized ()
4088 "Save all user options which have been set in this session."
4089 (interactive)
4090 (mapatoms (lambda (symbol)
4091 (let ((face (get symbol 'customized-face))
4092 (value (get symbol 'customized-value))
4093 (face-comment (get symbol 'customized-face-comment))
4094 (variable-comment
4095 (get symbol 'customized-variable-comment)))
4096 (when face
4097 (put symbol 'saved-face face)
4098 (custom-push-theme 'theme-face symbol 'user 'set value)
4099 (put symbol 'customized-face nil))
4100 (when value
4101 (put symbol 'saved-value value)
4102 (custom-push-theme 'theme-value symbol 'user 'set value)
4103 (put symbol 'customized-value nil))
4104 (when variable-comment
4105 (put symbol 'saved-variable-comment variable-comment)
4106 (put symbol 'customized-variable-comment nil))
4107 (when face-comment
4108 (put symbol 'saved-face-comment face-comment)
4109 (put symbol 'customized-face-comment nil)))))
4110 ;; We really should update all custom buffers here.
4111 (custom-save-all))
4113 ;; Editing the custom file contents in a buffer.
4115 (defun custom-save-delete (symbol)
4116 "Delete all calls to SYMBOL from the contents of the current buffer.
4117 Leave point at the old location of the first such call,
4118 or (if there were none) at the end of the buffer.
4120 This function does not save the buffer."
4121 (goto-char (point-min))
4122 ;; Skip all whitespace and comments.
4123 (while (forward-comment 1))
4124 (or (eobp)
4125 (save-excursion (forward-sexp (buffer-size)))) ; Test for scan errors.
4126 (let (first)
4127 (catch 'found
4128 (while t ;; We exit this loop only via throw.
4129 ;; Skip all whitespace and comments.
4130 (while (forward-comment 1))
4131 (let ((start (point))
4132 (sexp (condition-case nil
4133 (read (current-buffer))
4134 (end-of-file (throw 'found nil)))))
4135 (when (and (listp sexp)
4136 (eq (car sexp) symbol))
4137 (delete-region start (point))
4138 (unless first
4139 (setq first (point)))))))
4140 (if first
4141 (goto-char first)
4142 ;; Move in front of local variables, otherwise long Custom
4143 ;; entries would make them ineffective.
4144 (let ((pos (point-max))
4145 (case-fold-search t))
4146 (save-excursion
4147 (goto-char (point-max))
4148 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
4149 'move)
4150 (when (search-forward "Local Variables:" nil t)
4151 (setq pos (line-beginning-position))))
4152 (goto-char pos)))))
4154 (defun custom-save-variables ()
4155 "Save all customized variables in `custom-file'."
4156 (save-excursion
4157 (custom-save-delete 'custom-set-variables)
4158 (let ((standard-output (current-buffer))
4159 (saved-list (make-list 1 0))
4160 sort-fold-case)
4161 ;; First create a sorted list of saved variables.
4162 (mapatoms
4163 (lambda (symbol)
4164 (if (and (get symbol 'saved-value)
4165 (eq 'user (car (car-safe (get symbol 'theme-value)))))
4166 (nconc saved-list (list symbol)))))
4167 (setq saved-list (sort (cdr saved-list) 'string<))
4168 (unless (bolp)
4169 (princ "\n"))
4170 (princ "(custom-set-variables
4171 ;; custom-set-variables was added by Custom.
4172 ;; If you edit it by hand, you could mess it up, so be careful.
4173 ;; Your init file should contain only one such instance.
4174 ;; If there is more than one, they won't work right.\n")
4175 (dolist (symbol saved-list)
4176 (let ((spec (car-safe (get symbol 'theme-value)))
4177 (value (get symbol 'saved-value))
4178 (requests (get symbol 'custom-requests))
4179 (now (not (or (custom-variable-p symbol)
4180 (and (not (boundp symbol))
4181 (not (eq (get symbol 'force-value)
4182 'rogue))))))
4183 (comment (get symbol 'saved-variable-comment)))
4184 ;; Check `requests'.
4185 (dolist (request requests)
4186 (when (and (symbolp request) (not (featurep request)))
4187 (message "Unknown requested feature: %s" request)
4188 (setq requests (delq request requests))))
4189 (when (or (and spec (eq (car spec) 'user))
4190 comment
4191 (and (null spec) (get symbol 'saved-value)))
4192 (unless (bolp)
4193 (princ "\n"))
4194 (princ " '(")
4195 (prin1 symbol)
4196 (princ " ")
4197 (prin1 (car value))
4198 (when (or now requests comment)
4199 (princ " ")
4200 (prin1 now)
4201 (when (or requests comment)
4202 (princ " ")
4203 (prin1 requests)
4204 (when comment
4205 (princ " ")
4206 (prin1 comment))))
4207 (princ ")"))))
4208 (if (bolp)
4209 (princ " "))
4210 (princ ")")
4211 (unless (looking-at "\n")
4212 (princ "\n")))))
4214 (defun custom-save-faces ()
4215 "Save all customized faces in `custom-file'."
4216 (save-excursion
4217 (custom-save-delete 'custom-reset-faces)
4218 (custom-save-delete 'custom-set-faces)
4219 (let ((standard-output (current-buffer))
4220 (saved-list (make-list 1 0))
4221 sort-fold-case)
4222 ;; First create a sorted list of saved faces.
4223 (mapatoms
4224 (lambda (symbol)
4225 (if (and (get symbol 'saved-face)
4226 (eq 'user (car (car-safe (get symbol 'theme-face)))))
4227 (nconc saved-list (list symbol)))))
4228 (setq saved-list (sort (cdr saved-list) 'string<))
4229 ;; The default face must be first, since it affects the others.
4230 (if (memq 'default saved-list)
4231 (setq saved-list (cons 'default (delq 'default saved-list))))
4232 (unless (bolp)
4233 (princ "\n"))
4234 (princ "(custom-set-faces
4235 ;; custom-set-faces was added by Custom.
4236 ;; If you edit it by hand, you could mess it up, so be careful.
4237 ;; Your init file should contain only one such instance.
4238 ;; If there is more than one, they won't work right.\n")
4239 (dolist (symbol saved-list)
4240 (let ((spec (car-safe (get symbol 'theme-face)))
4241 (value (get symbol 'saved-face))
4242 (now (not (or (get symbol 'face-defface-spec)
4243 (and (not (custom-facep symbol))
4244 (not (get symbol 'force-face))))))
4245 (comment (get symbol 'saved-face-comment)))
4246 (when (or (and spec (eq (nth 0 spec) 'user))
4247 comment
4248 (and (null spec) (get symbol 'saved-face)))
4249 ;; Don't print default face here.
4250 (unless (bolp)
4251 (princ "\n"))
4252 (princ " '(")
4253 (prin1 symbol)
4254 (princ " ")
4255 (prin1 value)
4256 (when (or now comment)
4257 (princ " ")
4258 (prin1 now)
4259 (when comment
4260 (princ " ")
4261 (prin1 comment)))
4262 (princ ")"))))
4263 (if (bolp)
4264 (princ " "))
4265 (princ ")")
4266 (unless (looking-at "\n")
4267 (princ "\n")))))
4269 ;;; The Customize Menu.
4271 ;;; Menu support
4273 (defcustom custom-menu-nesting 2
4274 "Maximum nesting in custom menus."
4275 :type 'integer
4276 :group 'custom-menu)
4278 (defun custom-face-menu-create (widget symbol)
4279 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
4280 (vector (custom-unlispify-menu-entry symbol)
4281 `(customize-face ',symbol)
4284 (defun custom-variable-menu-create (widget symbol)
4285 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
4286 (let ((type (get symbol 'custom-type)))
4287 (unless (listp type)
4288 (setq type (list type)))
4289 (if (and type (widget-get type :custom-menu))
4290 (widget-apply type :custom-menu symbol)
4291 (vector (custom-unlispify-menu-entry symbol)
4292 `(customize-variable ',symbol)
4293 t))))
4295 ;; Add checkboxes to boolean variable entries.
4296 (widget-put (get 'boolean 'widget-type)
4297 :custom-menu (lambda (widget symbol)
4298 (vector (custom-unlispify-menu-entry symbol)
4299 `(customize-variable ',symbol)
4300 ':style 'toggle
4301 ':selected symbol)))
4303 (defun custom-group-menu-create (widget symbol)
4304 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
4305 `( ,(custom-unlispify-menu-entry symbol t)
4306 :filter (lambda (&rest junk)
4307 (let ((menu (custom-menu-create ',symbol)))
4308 (if (consp menu) (cdr menu) menu)))))
4310 ;;;###autoload
4311 (defun custom-menu-create (symbol)
4312 "Create menu for customization group SYMBOL.
4313 The menu is in a format applicable to `easy-menu-define'."
4314 (let* ((item (vector (custom-unlispify-menu-entry symbol)
4315 `(customize-group ',symbol)
4316 t)))
4317 (if (and (or (not (boundp 'custom-menu-nesting))
4318 (>= custom-menu-nesting 0))
4319 (progn
4320 (custom-load-symbol symbol)
4321 (< (length (get symbol 'custom-group)) widget-menu-max-size)))
4322 (let ((custom-prefix-list (custom-prefix-add symbol
4323 custom-prefix-list))
4324 (members (custom-sort-items (get symbol 'custom-group)
4325 custom-menu-sort-alphabetically
4326 custom-menu-order-groups)))
4327 `(,(custom-unlispify-menu-entry symbol t)
4328 ,item
4329 "--"
4330 ,@(mapcar (lambda (entry)
4331 (widget-apply (if (listp (nth 1 entry))
4332 (nth 1 entry)
4333 (list (nth 1 entry)))
4334 :custom-menu (nth 0 entry)))
4335 members)))
4336 item)))
4338 ;;;###autoload
4339 (defun customize-menu-create (symbol &optional name)
4340 "Return a customize menu for customization group SYMBOL.
4341 If optional NAME is given, use that as the name of the menu.
4342 Otherwise the menu will be named `Customize'.
4343 The format is suitable for use with `easy-menu-define'."
4344 (unless name
4345 (setq name "Customize"))
4346 `(,name
4347 :filter (lambda (&rest junk)
4348 (let ((menu (custom-menu-create ',symbol)))
4349 (if (consp menu) (cdr menu) menu)))))
4351 ;;; The Custom Mode.
4353 (defvar custom-mode-map
4354 ;; This keymap should be dense, but a dense keymap would prevent inheriting
4355 ;; "\r" bindings from the parent map.
4356 ;; Actually, this misfeature of dense keymaps was fixed on 2001-11-26.
4357 (let ((map (make-keymap)))
4358 (set-keymap-parent map widget-keymap)
4359 (suppress-keymap map)
4360 (define-key map " " 'scroll-up)
4361 (define-key map "\177" 'scroll-down)
4362 (define-key map "\C-c\C-c" 'Custom-set)
4363 (define-key map "\C-x\C-s" 'Custom-save)
4364 (define-key map "q" 'Custom-buffer-done)
4365 (define-key map "u" 'Custom-goto-parent)
4366 (define-key map "n" 'widget-forward)
4367 (define-key map "p" 'widget-backward)
4368 (define-key map [mouse-1] 'widget-move-and-invoke)
4369 map)
4370 "Keymap for `custom-mode'.")
4372 (easy-menu-define Custom-mode-menu
4373 custom-mode-map
4374 "Menu used in customization buffers."
4375 `("Custom"
4376 ,(customize-menu-create 'customize)
4377 ["Set" Custom-set t]
4378 ["Save" Custom-save t]
4379 ["Undo Edits" Custom-reset-current t]
4380 ["Reset to Saved" Custom-reset-saved t]
4381 ["Erase Customization" Custom-reset-standard t]
4382 ["Info" (info "(emacs)Easy Customization") t]))
4384 (defvar custom-field-keymap
4385 (let ((map (copy-keymap widget-field-keymap)))
4386 (define-key map "\C-c\C-c" 'Custom-set)
4387 (define-key map "\C-x\C-s" 'Custom-save)
4388 map)
4389 "Keymap used inside editable fields in customization buffers.")
4391 (widget-put (get 'editable-field 'widget-type) :keymap custom-field-keymap)
4393 (defun Custom-goto-parent ()
4394 "Go to the parent group listed at the top of this buffer.
4395 If several parents are listed, go to the first of them."
4396 (interactive)
4397 (save-excursion
4398 (goto-char (point-min))
4399 (if (search-forward "\nGo to parent group: " nil t)
4400 (let* ((button (get-char-property (point) 'button))
4401 (parent (downcase (widget-get button :tag))))
4402 (customize-group parent)))))
4404 (defcustom custom-mode-hook nil
4405 "Hook called when entering Custom mode."
4406 :type 'hook
4407 :group 'custom-buffer )
4409 (defun custom-state-buffer-message (widget)
4410 (if (eq (widget-get (widget-get widget :parent) :custom-state) 'modified)
4411 (message "To install your edits, invoke [State] and choose the Set operation")))
4413 (defun custom-mode ()
4414 "Major mode for editing customization buffers.
4416 The following commands are available:
4418 \\<widget-keymap>\
4419 Move to next button, link or editable field. \\[widget-forward]
4420 Move to previous button, link or editable field. \\[advertised-widget-backward]
4421 \\<custom-field-keymap>\
4422 Complete content of editable text field. \\[widget-complete]
4423 \\<custom-mode-map>\
4424 Invoke button under the mouse pointer. \\[widget-move-and-invoke]
4425 Invoke button under point. \\[widget-button-press]
4426 Set all options from current text. \\[Custom-set]
4427 Make values in current text permanent. \\[Custom-save]
4428 Make text match actual option values. \\[Custom-reset-current]
4429 Reset options to permanent settings. \\[Custom-reset-saved]
4430 Erase customizations; set options
4431 and buffer text to the standard values. \\[Custom-reset-standard]
4433 Entry to this mode calls the value of `custom-mode-hook'
4434 if that value is non-nil."
4435 (kill-all-local-variables)
4436 (setq major-mode 'custom-mode
4437 mode-name "Custom")
4438 (use-local-map custom-mode-map)
4439 (easy-menu-add Custom-mode-menu)
4440 (make-local-variable 'custom-options)
4441 (make-local-variable 'custom-local-buffer)
4442 (make-local-variable 'widget-documentation-face)
4443 (setq widget-documentation-face 'custom-documentation)
4444 (make-local-variable 'widget-button-face)
4445 (setq widget-button-face custom-button)
4446 (set (make-local-variable 'widget-button-pressed-face) custom-button-pressed)
4447 (set (make-local-variable 'widget-mouse-face) custom-button-mouse)
4449 ;; When possible, use relief for buttons, not bracketing. This test
4450 ;; may not be optimal.
4451 (when custom-raised-buttons
4452 (set (make-local-variable 'widget-push-button-prefix) "")
4453 (set (make-local-variable 'widget-push-button-suffix) "")
4454 (set (make-local-variable 'widget-link-prefix) "")
4455 (set (make-local-variable 'widget-link-suffix) ""))
4456 (add-hook 'widget-edit-functions 'custom-state-buffer-message nil t)
4457 (run-mode-hooks 'custom-mode-hook))
4459 (put 'custom-mode 'mode-class 'special)
4461 (add-to-list
4462 'debug-ignored-errors
4463 "^No user options have changed defaults in recent Emacs versions$")
4465 ;;; The End.
4467 (provide 'cus-edit)
4469 ;; arch-tag: 64533aa4-1b1a-48c3-8812-f9dc718e8a6f
4470 ;;; cus-edit.el ends here