(describe-key-briefly): Compute interactive args
[emacs.git] / lisp / cus-edit.el
blobfeacc9adf0db1622ec1067ea761673d53cad3706
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 (custom-push-theme 'theme-value variable 'user 'set (custom-quote value))
936 (funcall (or (get variable 'custom-set) 'set-default) variable value)
937 (put variable 'customized-value (list (custom-quote value)))
938 (cond ((string= comment "")
939 (put variable 'variable-comment nil)
940 (put variable 'customized-variable-comment nil))
941 (comment
942 (put variable 'variable-comment comment)
943 (put variable 'customized-variable-comment comment)))
944 value)
946 ;;;###autoload
947 (defun customize-save-variable (variable value &optional comment)
948 "Set the default for VARIABLE to VALUE, and save it for future sessions.
949 Return VALUE.
951 If VARIABLE has a `custom-set' property, that is used for setting
952 VARIABLE, otherwise `set-default' is used.
954 The `customized-value' property of the VARIABLE will be set to a list
955 with a quoted VALUE as its sole list member.
957 If VARIABLE has a `variable-interactive' property, that is used as if
958 it were the arg to `interactive' (which see) to interactively read the value.
960 If VARIABLE has a `custom-type' property, it must be a widget and the
961 `:prompt-value' property of that widget will be used for reading the value.
963 If given a prefix (or a COMMENT argument), also prompt for a comment."
964 (interactive (custom-prompt-variable "Set and save variable: "
965 "Set and save value for %s as: "
966 current-prefix-arg))
967 (funcall (or (get variable 'custom-set) 'set-default) variable value)
968 (put variable 'saved-value (list (custom-quote value)))
969 (custom-push-theme 'theme-value variable 'user 'set (custom-quote value))
970 (cond ((string= comment "")
971 (put variable 'variable-comment nil)
972 (put variable 'saved-variable-comment nil))
973 (comment
974 (put variable 'variable-comment comment)
975 (put variable 'saved-variable-comment comment)))
976 (custom-save-all)
977 value)
979 ;;;###autoload
980 (defun customize ()
981 "Select a customization buffer which you can use to set user options.
982 User options are structured into \"groups\".
983 Initially the top-level group `Emacs' and its immediate subgroups
984 are shown; the contents of those subgroups are initially hidden."
985 (interactive)
986 (customize-group 'emacs))
988 ;;;###autoload
989 (defun customize-mode (mode)
990 "Customize options related to the current major mode.
991 If a prefix \\[universal-argument] was given (or if the current major mode has no known group),
992 then prompt for the MODE to customize."
993 (interactive
994 (list
995 (let ((completion-regexp-list '("-mode\\'"))
996 (group (custom-group-of-mode major-mode)))
997 (if (and group (not current-prefix-arg))
998 major-mode
999 (intern
1000 (completing-read (if group
1001 (format "Major mode (default %s): " major-mode)
1002 "Major mode: ")
1003 obarray
1004 'custom-group-of-mode
1005 t nil nil (if group (symbol-name major-mode))))))))
1006 (customize-group (custom-group-of-mode mode)))
1009 ;;;###autoload
1010 (defun customize-group (group)
1011 "Customize GROUP, which must be a customization group."
1012 (interactive
1013 (list (let ((completion-ignore-case t))
1014 (completing-read "Customize group (default emacs): "
1015 obarray
1016 (lambda (symbol)
1017 (or (and (get symbol 'custom-loads)
1018 (not (get symbol 'custom-autoload)))
1019 (get symbol 'custom-group)))
1020 t))))
1021 (when (stringp group)
1022 (if (string-equal "" group)
1023 (setq group 'emacs)
1024 (setq group (intern group))))
1025 (let ((name (format "*Customize Group: %s*"
1026 (custom-unlispify-tag-name group))))
1027 (if (get-buffer name)
1028 (pop-to-buffer name)
1029 (custom-buffer-create (list (list group 'custom-group))
1030 name
1031 (concat " for group "
1032 (custom-unlispify-tag-name group))))))
1034 ;;;###autoload
1035 (defun customize-group-other-window (group)
1036 "Customize GROUP, which must be a customization group."
1037 (interactive
1038 (list (let ((completion-ignore-case t))
1039 (completing-read "Customize group (default emacs): "
1040 obarray
1041 (lambda (symbol)
1042 (or (and (get symbol 'custom-loads)
1043 (not (get symbol 'custom-autoload)))
1044 (get symbol 'custom-group)))
1045 t))))
1046 (when (stringp group)
1047 (if (string-equal "" group)
1048 (setq group 'emacs)
1049 (setq group (intern group))))
1050 (let ((name (format "*Customize Group: %s*"
1051 (custom-unlispify-tag-name group))))
1052 (if (get-buffer name)
1053 (let (
1054 ;; Copied from `custom-buffer-create-other-window'.
1055 (pop-up-windows t)
1056 (same-window-buffer-names nil)
1057 (same-window-regexps nil))
1058 (pop-to-buffer name))
1059 (custom-buffer-create-other-window
1060 (list (list group 'custom-group))
1061 name
1062 (concat " for group "
1063 (custom-unlispify-tag-name group))))))
1065 ;;;###autoload
1066 (defalias 'customize-variable 'customize-option)
1068 ;;;###autoload
1069 (defun customize-option (symbol)
1070 "Customize SYMBOL, which must be a user option variable."
1071 (interactive (custom-variable-prompt))
1072 (let ((basevar (indirect-variable symbol)))
1073 (custom-buffer-create (list (list basevar 'custom-variable))
1074 (format "*Customize Option: %s*"
1075 (custom-unlispify-tag-name basevar)))
1076 (unless (eq symbol basevar)
1077 (message "`%s' is an alias for `%s'" symbol basevar))))
1079 ;;;###autoload
1080 (defalias 'customize-variable-other-window 'customize-option-other-window)
1082 ;;;###autoload
1083 (defun customize-option-other-window (symbol)
1084 "Customize SYMBOL, which must be a user option variable.
1085 Show the buffer in another window, but don't select it."
1086 (interactive (custom-variable-prompt))
1087 (let ((basevar (indirect-variable symbol)))
1088 (custom-buffer-create-other-window
1089 (list (list basevar 'custom-variable))
1090 (format "*Customize Option: %s*" (custom-unlispify-tag-name basevar)))
1091 (unless (eq symbol basevar)
1092 (message "`%s' is an alias for `%s'" symbol basevar))))
1094 (defvar customize-changed-options-previous-release "21.1"
1095 "Version for `customize-changed-options' to refer back to by default.")
1097 ;;;###autoload
1098 (defalias 'customize-changed 'customize-changed-options)
1100 ;;;###autoload
1101 (defun customize-changed-options (since-version)
1102 "Customize all settings whose meanings have changed in Emacs itself.
1103 This includes new user option variables and faces, and new
1104 customization groups, as well as older options and faces whose meanings
1105 or default values have changed since the previous major Emacs release.
1107 With argument SINCE-VERSION (a string), customize all settings
1108 that were added or redefined since that version."
1110 (interactive "sCustomize options changed, since version (default all versions): ")
1111 (if (equal since-version "")
1112 (setq since-version nil)
1113 (unless (condition-case nil
1114 (numberp (read since-version))
1115 (error nil))
1116 (signal 'wrong-type-argument (list 'numberp since-version))))
1117 (unless since-version
1118 (setq since-version customize-changed-options-previous-release))
1120 ;; Load the information for versions since since-version. We use
1121 ;; custom-load-symbol for this.
1122 (put 'custom-versions-load-alist 'custom-loads nil)
1123 (dolist (elt custom-versions-load-alist)
1124 (if (customize-version-lessp since-version (car elt))
1125 (dolist (load (cdr elt))
1126 (custom-add-load 'custom-versions-load-alist load))))
1127 (custom-load-symbol 'custom-versions-load-alist)
1128 (put 'custom-versions-load-alist 'custom-loads nil)
1130 (let (found)
1131 (mapatoms
1132 (lambda (symbol)
1133 (let ((version (get symbol 'custom-version)))
1134 (if version
1135 (when (customize-version-lessp since-version version)
1136 (if (or (get symbol 'custom-group)
1137 (get symbol 'group-documentation))
1138 (push (list symbol 'custom-group) found))
1139 (if (custom-variable-p symbol)
1140 (push (list symbol 'custom-variable) found))
1141 (if (custom-facep symbol)
1142 (push (list symbol 'custom-face) found)))))))
1143 (if found
1144 (custom-buffer-create (custom-sort-items found t 'first)
1145 "*Customize Changed Options*")
1146 (error "No user option defaults have been changed since Emacs %s"
1147 since-version))))
1149 (defun customize-version-lessp (version1 version2)
1150 ;; Why are the versions strings, and given that they are, why aren't
1151 ;; they converted to numbers and compared as such here? -- fx
1153 ;; In case someone made a mistake and left out the quotes
1154 ;; in the :version value.
1155 (if (numberp version2)
1156 (setq version2 (prin1-to-string version2)))
1157 (let (major1 major2 minor1 minor2)
1158 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version1)
1159 (setq major1 (read (or (match-string 1 version1)
1160 "0")))
1161 (setq minor1 (read (or (match-string 3 version1)
1162 "0")))
1163 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version2)
1164 (setq major2 (read (or (match-string 1 version2)
1165 "0")))
1166 (setq minor2 (read (or (match-string 3 version2)
1167 "0")))
1168 (or (< major1 major2)
1169 (and (= major1 major2)
1170 (< minor1 minor2)))))
1172 ;;;###autoload
1173 (defun customize-face (&optional face)
1174 "Customize FACE, which should be a face name or nil.
1175 If FACE is nil, customize all faces. If FACE is actually a
1176 face-alias, customize the face it is aliased to.
1178 Interactively, when point is on text which has a face specified,
1179 suggest to customize that face, if it's customizable."
1180 (interactive
1181 (list (read-face-name "Customize face" "all faces" t)))
1182 (if (member face '(nil ""))
1183 (setq face (face-list)))
1184 (if (and (listp face) (null (cdr face)))
1185 (setq face (car face)))
1186 (if (listp face)
1187 (custom-buffer-create (custom-sort-items
1188 (mapcar (lambda (s)
1189 (list s 'custom-face))
1190 face)
1191 t nil)
1192 "*Customize Faces*")
1193 ;; If FACE is actually an alias, customize the face it is aliased to.
1194 (if (get face 'face-alias)
1195 (setq face (get face 'face-alias)))
1196 (unless (facep face)
1197 (error "Invalid face %S" face))
1198 (custom-buffer-create (list (list face 'custom-face))
1199 (format "*Customize Face: %s*"
1200 (custom-unlispify-tag-name face)))))
1202 ;;;###autoload
1203 (defun customize-face-other-window (&optional face)
1204 "Show customization buffer for face FACE in other window.
1205 If FACE is actually a face-alias, customize the face it is aliased to.
1207 Interactively, when point is on text which has a face specified,
1208 suggest to customize that face, if it's customizable."
1209 (interactive
1210 (list (read-face-name "Customize face" "all faces" t)))
1211 (if (member face '(nil ""))
1212 (setq face (face-list)))
1213 (if (and (listp face) (null (cdr face)))
1214 (setq face (car face)))
1215 (if (listp face)
1216 (custom-buffer-create-other-window
1217 (custom-sort-items
1218 (mapcar (lambda (s)
1219 (list s 'custom-face))
1220 face)
1221 t nil)
1222 "*Customize Faces*")
1223 (if (get face 'face-alias)
1224 (setq face (get face 'face-alias)))
1225 (unless (facep face)
1226 (error "Invalid face %S" face))
1227 (custom-buffer-create-other-window
1228 (list (list face 'custom-face))
1229 (format "*Customize Face: %s*"
1230 (custom-unlispify-tag-name face)))))
1232 ;;;###autoload
1233 (defun customize-customized ()
1234 "Customize all user options set since the last save in this session."
1235 (interactive)
1236 (let ((found nil))
1237 (mapatoms (lambda (symbol)
1238 (and (or (get symbol 'customized-face)
1239 (get symbol 'customized-face-comment))
1240 (custom-facep symbol)
1241 (push (list symbol 'custom-face) found))
1242 (and (or (get symbol 'customized-value)
1243 (get symbol 'customized-variable-comment))
1244 (boundp symbol)
1245 (push (list symbol 'custom-variable) found))))
1246 (if (not found)
1247 (error "No customized user options")
1248 (custom-buffer-create (custom-sort-items found t nil)
1249 "*Customize Customized*"))))
1251 ;;;###autoload
1252 (defun customize-rogue ()
1253 "Customize all user variables modified outside customize."
1254 (interactive)
1255 (let ((found nil))
1256 (mapatoms (lambda (symbol)
1257 (let ((cval (or (get symbol 'customized-value)
1258 (get symbol 'saved-value)
1259 (get symbol 'standard-value))))
1260 (when (and cval ;Declared with defcustom.
1261 (default-boundp symbol) ;Has a value.
1262 (not (equal (eval (car cval))
1263 ;; Which does not match customize.
1264 (default-value symbol))))
1265 (push (list symbol 'custom-variable) found)))))
1266 (if (not found)
1267 (error "No rogue user options")
1268 (custom-buffer-create (custom-sort-items found t nil)
1269 "*Customize Rogue*"))))
1270 ;;;###autoload
1271 (defun customize-saved ()
1272 "Customize all already saved user options."
1273 (interactive)
1274 (let ((found nil))
1275 (mapatoms (lambda (symbol)
1276 (and (or (get symbol 'saved-face)
1277 (get symbol 'saved-face-comment))
1278 (custom-facep symbol)
1279 (push (list symbol 'custom-face) found))
1280 (and (or (get symbol 'saved-value)
1281 (get symbol 'saved-variable-comment))
1282 (boundp symbol)
1283 (push (list symbol 'custom-variable) found))))
1284 (if (not found )
1285 (error "No saved user options")
1286 (custom-buffer-create (custom-sort-items found t nil)
1287 "*Customize Saved*"))))
1289 ;;;###autoload
1290 (defun customize-apropos (regexp &optional all)
1291 "Customize all loaded options, faces and groups matching REGEXP.
1292 If ALL is `options', include only options.
1293 If ALL is `faces', include only faces.
1294 If ALL is `groups', include only groups.
1295 If ALL is t (interactively, with prefix arg), include variables
1296 that are not customizable options, as well as faces and groups
1297 \(but we recommend using `apropos-variable' instead)."
1298 (interactive "sCustomize regexp: \nP")
1299 (let ((found nil))
1300 (mapatoms (lambda (symbol)
1301 (when (string-match regexp (symbol-name symbol))
1302 (when (and (not (memq all '(faces options)))
1303 (get symbol 'custom-group))
1304 (push (list symbol 'custom-group) found))
1305 (when (and (not (memq all '(options groups)))
1306 (custom-facep symbol))
1307 (push (list symbol 'custom-face) found))
1308 (when (and (not (memq all '(groups faces)))
1309 (boundp symbol)
1310 (eq (indirect-variable symbol) symbol)
1311 (or (get symbol 'saved-value)
1312 (custom-variable-p symbol)
1313 (and (not (memq all '(nil options)))
1314 (get symbol 'variable-documentation))))
1315 (push (list symbol 'custom-variable) found)))))
1316 (if (not found)
1317 (error "No matches")
1318 (custom-buffer-create (custom-sort-items found t
1319 custom-buffer-order-groups)
1320 "*Customize Apropos*"))))
1322 ;;;###autoload
1323 (defun customize-apropos-options (regexp &optional arg)
1324 "Customize all loaded customizable options matching REGEXP.
1325 With prefix arg, include variables that are not customizable options
1326 \(but we recommend using `apropos-variable' instead)."
1327 (interactive "sCustomize regexp: \nP")
1328 (customize-apropos regexp (or arg 'options)))
1330 ;;;###autoload
1331 (defun customize-apropos-faces (regexp)
1332 "Customize all loaded faces matching REGEXP."
1333 (interactive "sCustomize regexp: \n")
1334 (customize-apropos regexp 'faces))
1336 ;;;###autoload
1337 (defun customize-apropos-groups (regexp)
1338 "Customize all loaded groups matching REGEXP."
1339 (interactive "sCustomize regexp: \n")
1340 (customize-apropos regexp 'groups))
1342 ;;; Buffer.
1344 (defcustom custom-buffer-style 'links
1345 "Control the presentation style for customization buffers.
1346 The value should be a symbol, one of:
1348 brackets: groups nest within each other with big horizontal brackets.
1349 links: groups have links to subgroups."
1350 :type '(radio (const brackets)
1351 (const links))
1352 :group 'custom-buffer)
1354 (defcustom custom-buffer-done-kill nil
1355 "*Non-nil means exiting a Custom buffer should kill it."
1356 :type 'boolean
1357 :version "22.1"
1358 :group 'custom-buffer)
1360 (defcustom custom-buffer-indent 3
1361 "Number of spaces to indent nested groups."
1362 :type 'integer
1363 :group 'custom-buffer)
1365 (defun custom-get-fresh-buffer (name)
1366 "Get a fresh new buffer with name NAME.
1367 If the buffer already exist, clean it up to be like new.
1368 Beware: it's not quite like new. Good enough for custom, but maybe
1369 not for everybody."
1370 ;; To be more complete, we should also kill all permanent-local variables,
1371 ;; but it's not needed for custom.
1372 (let ((buf (get-buffer name)))
1373 (when (and buf (buffer-local-value 'buffer-file-name buf))
1374 ;; This will check if the file is not saved.
1375 (kill-buffer buf)
1376 (setq buf nil))
1377 (if (null buf)
1378 (get-buffer-create name)
1379 (with-current-buffer buf
1380 (kill-all-local-variables)
1381 (run-hooks 'kill-buffer-hook)
1382 ;; Delete overlays before erasing the buffer so the overlay hooks
1383 ;; don't get run spuriously when we erase the buffer.
1384 (let ((ols (overlay-lists)))
1385 (dolist (ol (nconc (car ols) (cdr ols)))
1386 (delete-overlay ol)))
1387 (erase-buffer)
1388 buf))))
1390 ;;;###autoload
1391 (defun custom-buffer-create (options &optional name description)
1392 "Create a buffer containing OPTIONS.
1393 Optional NAME is the name of the buffer.
1394 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1395 SYMBOL is a customization option, and WIDGET is a widget for editing
1396 that option."
1397 (pop-to-buffer (custom-get-fresh-buffer (or name "*Customization*")))
1398 (custom-buffer-create-internal options description))
1400 ;;;###autoload
1401 (defun custom-buffer-create-other-window (options &optional name description)
1402 "Create a buffer containing OPTIONS, and display it in another window.
1403 The result includes selecting that window.
1404 Optional NAME is the name of the buffer.
1405 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1406 SYMBOL is a customization option, and WIDGET is a widget for editing
1407 that option."
1408 (unless name (setq name "*Customization*"))
1409 (let ((pop-up-windows t)
1410 (same-window-buffer-names nil)
1411 (same-window-regexps nil))
1412 (pop-to-buffer (custom-get-fresh-buffer name))
1413 (custom-buffer-create-internal options description)))
1415 (defcustom custom-reset-button-menu nil
1416 "If non-nil, only show a single reset button in customize buffers.
1417 This button will have a menu with all three reset operations."
1418 :type 'boolean
1419 :group 'custom-buffer)
1421 (defcustom custom-buffer-verbose-help t
1422 "If non-nil, include explanatory text in the customization buffer."
1423 :type 'boolean
1424 :group 'custom-buffer)
1426 (defun Custom-buffer-done (&rest ignore)
1427 "Exit current Custom buffer according to `custom-buffer-done-kill'."
1428 (interactive)
1429 (quit-window custom-buffer-done-kill))
1431 (defvar custom-button nil
1432 "Face used for buttons in customization buffers.")
1434 (defvar custom-button-mouse nil
1435 "Mouse face used for buttons in customization buffers.")
1437 (defvar custom-button-pressed nil
1438 "Face used for pressed buttons in customization buffers.")
1440 (defcustom custom-raised-buttons (not (equal (face-valid-attribute-values :box)
1441 '(("unspecified" . unspecified))))
1442 "If non-nil, indicate active buttons in a `raised-button' style.
1443 Otherwise use brackets."
1444 :type 'boolean
1445 :version "21.1"
1446 :group 'custom-buffer
1447 :set (lambda (variable value)
1448 (custom-set-default variable value)
1449 (setq custom-button
1450 (if value 'custom-button 'custom-button-unraised))
1451 (setq custom-button-mouse
1452 (if value 'custom-button-mouse 'highlight))
1453 (setq custom-button-pressed
1454 (if value
1455 'custom-button-pressed
1456 'custom-button-pressed-unraised))))
1458 (defun custom-buffer-create-internal (options &optional description)
1459 (custom-mode)
1460 (if custom-buffer-verbose-help
1461 (progn
1462 (widget-insert "This is a customization buffer")
1463 (if description
1464 (widget-insert description))
1465 (widget-insert (format ".
1466 %s buttons; type RET or click mouse-1 to actuate one.
1467 Editing a setting changes only the text in the buffer.
1468 Use the setting's State button to set it or save changes in it.
1469 Saving a change normally works by editing your Emacs init file.
1470 See "
1471 (if custom-raised-buttons
1472 "`Raised' text indicates"
1473 "Square brackets indicate")))
1474 (widget-create 'custom-manual
1475 :tag "Custom file"
1476 "(emacs)Saving Customizations")
1477 (widget-insert
1478 " for information on how to save in a different file.\n
1479 See ")
1480 (widget-create 'custom-manual
1481 :tag "Help"
1482 :help-echo "Read the online help."
1483 "(emacs)Easy Customization")
1484 (widget-insert " for more information.\n\n")
1485 (widget-insert "Operate on all settings in this buffer that \
1486 are not marked HIDDEN:\n "))
1487 (widget-insert " "))
1488 (widget-create 'push-button
1489 :tag "Set for Current Session"
1490 :help-echo "\
1491 Make your editing in this buffer take effect for this session."
1492 :action (lambda (widget &optional event)
1493 (Custom-set)))
1494 (if (not custom-buffer-verbose-help)
1495 (progn
1496 (widget-insert " ")
1497 (widget-create 'custom-manual
1498 :tag "Help"
1499 :help-echo "Read the online help."
1500 "(emacs)Easy Customization")))
1501 (when (or custom-file user-init-file)
1502 (widget-insert " ")
1503 (widget-create 'push-button
1504 :tag "Save for Future Sessions"
1505 :help-echo "\
1506 Make your editing in this buffer take effect for future Emacs sessions.
1507 This updates your Emacs initialization file or creates a new one."
1508 :action (lambda (widget &optional event)
1509 (Custom-save))))
1510 (if custom-reset-button-menu
1511 (progn
1512 (widget-insert " ")
1513 (widget-create 'push-button
1514 :tag "Reset buffer"
1515 :help-echo "Show a menu with reset operations."
1516 :mouse-down-action (lambda (&rest junk) t)
1517 :action (lambda (widget &optional event)
1518 (custom-reset event))))
1519 (widget-insert "\n ")
1520 (widget-create 'push-button
1521 :tag "Undo Edits"
1522 :help-echo "\
1523 Reset all edited text in this buffer to reflect current values."
1524 :action 'Custom-reset-current)
1525 (widget-insert " ")
1526 (widget-create 'push-button
1527 :tag "Reset to Saved"
1528 :help-echo "\
1529 Reset all settings in this buffer to their saved values."
1530 :action 'Custom-reset-saved)
1531 (widget-insert " ")
1532 (when (or custom-file user-init-file)
1533 (widget-create 'push-button
1534 :tag "Erase Customization"
1535 :help-echo "\
1536 Un-customize all settings in this buffer and save them with standard values."
1537 :action 'Custom-reset-standard)))
1538 (widget-insert " ")
1539 (widget-create 'push-button
1540 :tag "Finish"
1541 :help-echo
1542 (lambda (&rest ignore)
1543 (if custom-buffer-done-kill
1544 "Kill this buffer"
1545 "Bury this buffer"))
1546 :action #'Custom-buffer-done)
1547 (widget-insert "\n\n")
1548 (message "Creating customization items...")
1549 (buffer-disable-undo)
1550 (setq custom-options
1551 (if (= (length options) 1)
1552 (mapcar (lambda (entry)
1553 (widget-create (nth 1 entry)
1554 :documentation-shown t
1555 :custom-state 'unknown
1556 :tag (custom-unlispify-tag-name
1557 (nth 0 entry))
1558 :value (nth 0 entry)))
1559 options)
1560 (let ((count 0)
1561 (length (length options)))
1562 (mapcar (lambda (entry)
1563 (prog2
1564 (message "Creating customization items ...%2d%%"
1565 (/ (* 100.0 count) length))
1566 (widget-create (nth 1 entry)
1567 :tag (custom-unlispify-tag-name
1568 (nth 0 entry))
1569 :value (nth 0 entry))
1570 (setq count (1+ count))
1571 (unless (eq (preceding-char) ?\n)
1572 (widget-insert "\n"))
1573 (widget-insert "\n")))
1574 options))))
1575 (unless (eq (preceding-char) ?\n)
1576 (widget-insert "\n"))
1577 (message "Creating customization items ...done")
1578 (message "Resetting customization items...")
1579 (unless (eq custom-buffer-style 'tree)
1580 (mapc 'custom-magic-reset custom-options))
1581 (message "Resetting customization items...done")
1582 (message "Creating customization setup...")
1583 (widget-setup)
1584 (buffer-enable-undo)
1585 (goto-char (point-min))
1586 (message "Creating customization setup...done"))
1588 ;;; The Tree Browser.
1590 ;;;###autoload
1591 (defun customize-browse (&optional group)
1592 "Create a tree browser for the customize hierarchy."
1593 (interactive)
1594 (unless group
1595 (setq group 'emacs))
1596 (let ((name "*Customize Browser*"))
1597 (pop-to-buffer (custom-get-fresh-buffer name)))
1598 (custom-mode)
1599 (widget-insert (format "\
1600 %s buttons; type RET or click mouse-1
1601 on a button to invoke its action.
1602 Invoke [+] to expand a group, and [-] to collapse an expanded group.\n"
1603 (if custom-raised-buttons
1604 "`Raised' text indicates"
1605 "Square brackets indicate")))
1608 (if custom-browse-only-groups
1609 (widget-insert "\
1610 Invoke the [Group] button below to edit that item in another window.\n\n")
1611 (widget-insert "Invoke the ")
1612 (widget-create 'item
1613 :format "%t"
1614 :tag "[Group]"
1615 :tag-glyph "folder")
1616 (widget-insert ", ")
1617 (widget-create 'item
1618 :format "%t"
1619 :tag "[Face]"
1620 :tag-glyph "face")
1621 (widget-insert ", and ")
1622 (widget-create 'item
1623 :format "%t"
1624 :tag "[Option]"
1625 :tag-glyph "option")
1626 (widget-insert " buttons below to edit that
1627 item in another window.\n\n"))
1628 (let ((custom-buffer-style 'tree))
1629 (widget-create 'custom-group
1630 :custom-last t
1631 :custom-state 'unknown
1632 :tag (custom-unlispify-tag-name group)
1633 :value group))
1634 (widget-setup)
1635 (goto-char (point-min)))
1637 (define-widget 'custom-browse-visibility 'item
1638 "Control visibility of items in the customize tree browser."
1639 :format "%[[%t]%]"
1640 :action 'custom-browse-visibility-action)
1642 (defun custom-browse-visibility-action (widget &rest ignore)
1643 (let ((custom-buffer-style 'tree))
1644 (custom-toggle-parent widget)))
1646 (define-widget 'custom-browse-group-tag 'custom-group-link
1647 "Show parent in other window when activated."
1648 :tag "Group"
1649 :tag-glyph "folder"
1650 :action 'custom-browse-group-tag-action)
1652 (defun custom-browse-group-tag-action (widget &rest ignore)
1653 (let ((parent (widget-get widget :parent)))
1654 (customize-group-other-window (widget-value parent))))
1656 (define-widget 'custom-browse-variable-tag 'custom-group-link
1657 "Show parent in other window when activated."
1658 :tag "Option"
1659 :tag-glyph "option"
1660 :action 'custom-browse-variable-tag-action)
1662 (defun custom-browse-variable-tag-action (widget &rest ignore)
1663 (let ((parent (widget-get widget :parent)))
1664 (customize-variable-other-window (widget-value parent))))
1666 (define-widget 'custom-browse-face-tag 'custom-group-link
1667 "Show parent in other window when activated."
1668 :tag "Face"
1669 :tag-glyph "face"
1670 :action 'custom-browse-face-tag-action)
1672 (defun custom-browse-face-tag-action (widget &rest ignore)
1673 (let ((parent (widget-get widget :parent)))
1674 (customize-face-other-window (widget-value parent))))
1676 (defconst custom-browse-alist '((" " "space")
1677 (" | " "vertical")
1678 ("-\\ " "top")
1679 (" |-" "middle")
1680 (" `-" "bottom")))
1682 (defun custom-browse-insert-prefix (prefix)
1683 "Insert PREFIX. On XEmacs convert it to line graphics."
1684 ;; Fixme: do graphics.
1685 (if nil ; (string-match "XEmacs" emacs-version)
1686 (progn
1687 (insert "*")
1688 (while (not (string-equal prefix ""))
1689 (let ((entry (substring prefix 0 3)))
1690 (setq prefix (substring prefix 3))
1691 (let ((overlay (make-overlay (1- (point)) (point) nil t nil))
1692 (name (nth 1 (assoc entry custom-browse-alist))))
1693 (overlay-put overlay 'end-glyph (widget-glyph-find name entry))
1694 (overlay-put overlay 'start-open t)
1695 (overlay-put overlay 'end-open t)))))
1696 (insert prefix)))
1698 ;;; Modification of Basic Widgets.
1700 ;; We add extra properties to the basic widgets needed here. This is
1701 ;; fine, as long as we are careful to stay within out own namespace.
1703 ;; We want simple widgets to be displayed by default, but complex
1704 ;; widgets to be hidden.
1706 (widget-put (get 'item 'widget-type) :custom-show t)
1707 (widget-put (get 'editable-field 'widget-type)
1708 :custom-show (lambda (widget value)
1709 (let ((pp (pp-to-string value)))
1710 (cond ((string-match "\n" pp)
1711 nil)
1712 ((> (length pp) 40)
1713 nil)
1714 (t t)))))
1715 (widget-put (get 'menu-choice 'widget-type) :custom-show t)
1717 ;;; The `custom-manual' Widget.
1719 (define-widget 'custom-manual 'info-link
1720 "Link to the manual entry for this customization option."
1721 :help-echo "Read the manual entry for this option."
1722 :button-face 'custom-link
1723 :mouse-face 'highlight
1724 :pressed-face 'highlight
1725 :tag "Manual")
1727 ;;; The `custom-magic' Widget.
1729 (defgroup custom-magic-faces nil
1730 "Faces used by the magic button."
1731 :group 'custom-faces
1732 :group 'custom-buffer)
1734 (defface custom-invalid '((((class color))
1735 (:foreground "yellow1" :background "red1"))
1737 (:weight bold :slant italic :underline t)))
1738 "Face used when the customize item is invalid."
1739 :group 'custom-magic-faces)
1740 ;; backward-compatibility alias
1741 (put 'custom-invalid-face 'face-alias 'custom-invalid)
1743 (defface custom-rogue '((((class color))
1744 (:foreground "pink" :background "black"))
1746 (:underline t)))
1747 "Face used when the customize item is not defined for customization."
1748 :group 'custom-magic-faces)
1749 ;; backward-compatibility alias
1750 (put 'custom-rogue-face 'face-alias 'custom-rogue)
1752 (defface custom-modified '((((min-colors 88) (class color))
1753 (:foreground "white" :background "blue1"))
1754 (((class color))
1755 (:foreground "white" :background "blue"))
1757 (:slant italic :bold)))
1758 "Face used when the customize item has been modified."
1759 :group 'custom-magic-faces)
1760 ;; backward-compatibility alias
1761 (put 'custom-modified-face 'face-alias 'custom-modified)
1763 (defface custom-set '((((min-colors 88) (class color))
1764 (:foreground "blue1" :background "white"))
1765 (((class color))
1766 (:foreground "blue" :background "white"))
1768 (:slant italic)))
1769 "Face used when the customize item has been set."
1770 :group 'custom-magic-faces)
1771 ;; backward-compatibility alias
1772 (put 'custom-set-face 'face-alias 'custom-set)
1774 (defface custom-changed '((((min-colors 88) (class color))
1775 (:foreground "white" :background "blue1"))
1776 (((class color))
1777 (:foreground "white" :background "blue"))
1779 (:slant italic)))
1780 "Face used when the customize item has been changed."
1781 :group 'custom-magic-faces)
1782 ;; backward-compatibility alias
1783 (put 'custom-changed-face 'face-alias 'custom-changed)
1785 (defface custom-themed '((((min-colors 88) (class color))
1786 (:foreground "white" :background "blue1"))
1787 (((class color))
1788 (:foreground "white" :background "blue"))
1790 (:slant italic)))
1791 "Face used when the customize item has been set by a theme."
1792 :group 'custom-magic-faces)
1794 (defface custom-saved '((t (:underline t)))
1795 "Face used when the customize item has been saved."
1796 :group 'custom-magic-faces)
1797 ;; backward-compatibility alias
1798 (put 'custom-saved-face 'face-alias 'custom-saved)
1800 (defconst custom-magic-alist
1801 '((nil "#" underline "\
1802 UNINITIALIZED, you should not see this.")
1803 (unknown "?" italic "\
1804 UNKNOWN, you should not see this.")
1805 (hidden "-" default "\
1806 HIDDEN, invoke \"Show\" in the previous line to show." "\
1807 group now hidden, invoke \"Show\", above, to show contents.")
1808 (invalid "x" custom-invalid "\
1809 INVALID, the displayed value cannot be set.")
1810 (modified "*" custom-modified "\
1811 EDITED, shown value does not take effect until you set or save it." "\
1812 something in this group has been edited but not set.")
1813 (set "+" custom-set "\
1814 SET for current session only." "\
1815 something in this group has been set but not saved.")
1816 (changed ":" custom-changed "\
1817 CHANGED outside Customize; operating on it here may be unreliable." "\
1818 something in this group has been changed outside customize.")
1819 (saved "!" custom-saved "\
1820 SAVED and set." "\
1821 something in this group has been set and saved.")
1822 (themed "o" custom-themed "\
1823 THEMED." "\
1824 visible group members are all at standard values.")
1825 (rogue "@" custom-rogue "\
1826 NO CUSTOMIZATION DATA; not intended to be customized." "\
1827 something in this group is not prepared for customization.")
1828 (standard " " nil "\
1829 STANDARD." "\
1830 visible group members are all at standard values."))
1831 "Alist of customize option states.
1832 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1834 STATE is one of the following symbols:
1836 `nil'
1837 For internal use, should never occur.
1838 `unknown'
1839 For internal use, should never occur.
1840 `hidden'
1841 This item is not being displayed.
1842 `invalid'
1843 This item is modified, but has an invalid form.
1844 `modified'
1845 This item is modified, and has a valid form.
1846 `set'
1847 This item has been set but not saved.
1848 `changed'
1849 The current value of this item has been changed outside Customize.
1850 `saved'
1851 This item is marked for saving.
1852 `rogue'
1853 This item has no customization information.
1854 `standard'
1855 This item is unchanged from the standard setting.
1857 MAGIC is a string used to present that state.
1859 FACE is a face used to present the state.
1861 ITEM-DESC is a string describing the state for options.
1863 GROUP-DESC is a string describing the state for groups. If this is
1864 left out, ITEM-DESC will be used.
1866 The string %c in either description will be replaced with the
1867 category of the item. These are `group'. `option', and `face'.
1869 The list should be sorted most significant first.")
1871 (defcustom custom-magic-show 'long
1872 "If non-nil, show textual description of the state.
1873 If `long', show a full-line description, not just one word."
1874 :type '(choice (const :tag "no" nil)
1875 (const long)
1876 (other :tag "short" short))
1877 :group 'custom-buffer)
1879 (defcustom custom-magic-show-hidden '(option face)
1880 "Control whether the State button is shown for hidden items.
1881 The value should be a list with the custom categories where the State
1882 button should be visible. Possible categories are `group', `option',
1883 and `face'."
1884 :type '(set (const group) (const option) (const face))
1885 :group 'custom-buffer)
1887 (defcustom custom-magic-show-button nil
1888 "Show a \"magic\" button indicating the state of each customization option."
1889 :type 'boolean
1890 :group 'custom-buffer)
1892 (define-widget 'custom-magic 'default
1893 "Show and manipulate state for a customization option."
1894 :format "%v"
1895 :action 'widget-parent-action
1896 :notify 'ignore
1897 :value-get 'ignore
1898 :value-create 'custom-magic-value-create
1899 :value-delete 'widget-children-value-delete)
1901 (defun widget-magic-mouse-down-action (widget &optional event)
1902 ;; Non-nil unless hidden.
1903 (not (eq (widget-get (widget-get (widget-get widget :parent) :parent)
1904 :custom-state)
1905 'hidden)))
1907 (defun custom-magic-value-create (widget)
1908 "Create compact status report for WIDGET."
1909 (let* ((parent (widget-get widget :parent))
1910 (state (widget-get parent :custom-state))
1911 (hidden (eq state 'hidden))
1912 (entry (assq state custom-magic-alist))
1913 (magic (nth 1 entry))
1914 (face (nth 2 entry))
1915 (category (widget-get parent :custom-category))
1916 (text (or (and (eq category 'group)
1917 (nth 4 entry))
1918 (nth 3 entry)))
1919 (form (widget-get parent :custom-form))
1920 children)
1921 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text)
1922 (setq text (concat (match-string 1 text)
1923 (symbol-name category)
1924 (match-string 2 text))))
1925 (when (and custom-magic-show
1926 (or (not hidden)
1927 (memq category custom-magic-show-hidden)))
1928 (insert " ")
1929 (when (and (eq category 'group)
1930 (not (and (eq custom-buffer-style 'links)
1931 (> (widget-get parent :custom-level) 1))))
1932 (insert-char ?\ (* custom-buffer-indent
1933 (widget-get parent :custom-level))))
1934 (push (widget-create-child-and-convert
1935 widget 'choice-item
1936 :help-echo "Change the state of this item."
1937 :format (if hidden "%t" "%[%t%]")
1938 :button-prefix 'widget-push-button-prefix
1939 :button-suffix 'widget-push-button-suffix
1940 :mouse-down-action 'widget-magic-mouse-down-action
1941 :tag "State")
1942 children)
1943 (insert ": ")
1944 (let ((start (point)))
1945 (if (eq custom-magic-show 'long)
1946 (insert text)
1947 (insert (symbol-name state)))
1948 (cond ((eq form 'lisp)
1949 (insert " (lisp)"))
1950 ((eq form 'mismatch)
1951 (insert " (mismatch)")))
1952 (put-text-property start (point) 'face 'custom-state))
1953 (insert "\n"))
1954 (when (and (eq category 'group)
1955 (not (and (eq custom-buffer-style 'links)
1956 (> (widget-get parent :custom-level) 1))))
1957 (insert-char ?\ (* custom-buffer-indent
1958 (widget-get parent :custom-level))))
1959 (when custom-magic-show-button
1960 (when custom-magic-show
1961 (let ((indent (widget-get parent :indent)))
1962 (when indent
1963 (insert-char ? indent))))
1964 (push (widget-create-child-and-convert
1965 widget 'choice-item
1966 :mouse-down-action 'widget-magic-mouse-down-action
1967 :button-face face
1968 :button-prefix ""
1969 :button-suffix ""
1970 :help-echo "Change the state."
1971 :format (if hidden "%t" "%[%t%]")
1972 :tag (if (memq form '(lisp mismatch))
1973 (concat "(" magic ")")
1974 (concat "[" magic "]")))
1975 children)
1976 (insert " "))
1977 (widget-put widget :children children)))
1979 (defun custom-magic-reset (widget)
1980 "Redraw the :custom-magic property of WIDGET."
1981 (let ((magic (widget-get widget :custom-magic)))
1982 (widget-value-set magic (widget-value magic))))
1984 ;;; The `custom' Widget.
1986 (defface custom-button
1987 '((((type x w32 mac) (class color)) ; Like default modeline
1988 (:box (:line-width 2 :style released-button)
1989 :background "lightgrey" :foreground "black"))
1991 nil))
1992 "Face for custom buffer buttons if `custom-raised-buttons' is non-nil."
1993 :version "21.1"
1994 :group 'custom-faces)
1995 ;; backward-compatibility alias
1996 (put 'custom-button-face 'face-alias 'custom-button)
1998 (defface custom-button-mouse
1999 '((((type x w32 mac) (class color))
2000 (:box (:line-width 2 :style released-button)
2001 :background "grey90" :foreground "black"))
2003 nil))
2004 "Mouse face for custom buffer buttons if `custom-raised-buttons' is non-nil."
2005 :version "22.1"
2006 :group 'custom-faces)
2008 (defface custom-button-unraised
2009 '((t :inherit underline))
2010 "Face for custom buffer buttons if `custom-raised-buttons' is nil."
2011 :version "22.1"
2012 :group 'custom-faces)
2014 (setq custom-button
2015 (if custom-raised-buttons 'custom-button 'custom-button-unraised))
2017 (setq custom-button-mouse
2018 (if custom-raised-buttons 'custom-button-mouse 'highlight))
2020 (defface custom-button-pressed
2021 '((((type x w32 mac) (class color))
2022 (:box (:line-width 2 :style pressed-button)
2023 :background "lightgrey" :foreground "black"))
2025 (:inverse-video t)))
2026 "Face for pressed custom buttons if `custom-raised-buttons' is non-nil."
2027 :version "21.1"
2028 :group 'custom-faces)
2029 ;; backward-compatibility alias
2030 (put 'custom-button-pressed-face 'face-alias 'custom-button-pressed)
2032 (defface custom-button-pressed-unraised
2033 '((default :inherit custom-button-unraised)
2034 (((class color) (background light)) :foreground "magenta4")
2035 (((class color) (background dark)) :foreground "violet"))
2036 "Face for pressed custom buttons if `custom-raised-buttons' is nil."
2037 :version "22.1"
2038 :group 'custom-faces)
2040 (setq custom-button-pressed
2041 (if custom-raised-buttons
2042 'custom-button-pressed
2043 'custom-button-pressed-unraised))
2045 (defface custom-documentation nil
2046 "Face used for documentation strings in customization buffers."
2047 :group 'custom-faces)
2048 ;; backward-compatibility alias
2049 (put 'custom-documentation-face 'face-alias 'custom-documentation)
2051 (defface custom-state '((((class color)
2052 (background dark))
2053 (:foreground "lime green"))
2054 (((class color)
2055 (background light))
2056 (:foreground "dark green"))
2057 (t nil))
2058 "Face used for State descriptions in the customize buffer."
2059 :group 'custom-faces)
2060 ;; backward-compatibility alias
2061 (put 'custom-state-face 'face-alias 'custom-state)
2063 (defface custom-link
2064 '((t :inherit link))
2065 "Face for links in customization buffers."
2066 :version "22.1"
2067 :group 'custom-faces)
2069 (define-widget 'custom 'default
2070 "Customize a user option."
2071 :format "%v"
2072 :convert-widget 'custom-convert-widget
2073 :notify 'custom-notify
2074 :custom-prefix ""
2075 :custom-level 1
2076 :custom-state 'hidden
2077 :documentation-property 'widget-subclass-responsibility
2078 :value-create 'widget-subclass-responsibility
2079 :value-delete 'widget-children-value-delete
2080 :value-get 'widget-value-value-get
2081 :validate 'widget-children-validate
2082 :match (lambda (widget value) (symbolp value)))
2084 (defun custom-convert-widget (widget)
2085 "Initialize :value and :tag from :args in WIDGET."
2086 (let ((args (widget-get widget :args)))
2087 (when args
2088 (widget-put widget :value (widget-apply widget
2089 :value-to-internal (car args)))
2090 (widget-put widget :tag (custom-unlispify-tag-name (car args)))
2091 (widget-put widget :args nil)))
2092 widget)
2094 (defun custom-notify (widget &rest args)
2095 "Keep track of changes."
2096 (let ((state (widget-get widget :custom-state)))
2097 (unless (eq state 'modified)
2098 (unless (memq state '(nil unknown hidden))
2099 (widget-put widget :custom-state 'modified))
2100 (custom-magic-reset widget)
2101 (apply 'widget-default-notify widget args))))
2103 (defun custom-redraw (widget)
2104 "Redraw WIDGET with current settings."
2105 (let ((line (count-lines (point-min) (point)))
2106 (column (current-column))
2107 (pos (point))
2108 (from (marker-position (widget-get widget :from)))
2109 (to (marker-position (widget-get widget :to))))
2110 (save-excursion
2111 (widget-value-set widget (widget-value widget))
2112 (custom-redraw-magic widget))
2113 (when (and (>= pos from) (<= pos to))
2114 (condition-case nil
2115 (progn
2116 (if (> column 0)
2117 (goto-line line)
2118 (goto-line (1+ line)))
2119 (move-to-column column))
2120 (error nil)))))
2122 (defun custom-redraw-magic (widget)
2123 "Redraw WIDGET state with current settings."
2124 (while widget
2125 (let ((magic (widget-get widget :custom-magic)))
2126 (cond (magic
2127 (widget-value-set magic (widget-value magic))
2128 (when (setq widget (widget-get widget :group))
2129 (custom-group-state-update widget)))
2131 (setq widget nil)))))
2132 (widget-setup))
2134 (defun custom-show (widget value)
2135 "Non-nil if WIDGET should be shown with VALUE by default."
2136 (let ((show (widget-get widget :custom-show)))
2137 (cond ((null show)
2138 nil)
2139 ((eq t show)
2142 (funcall show widget value)))))
2144 (defun custom-load-widget (widget)
2145 "Load all dependencies for WIDGET."
2146 (custom-load-symbol (widget-value widget)))
2148 (defun custom-unloaded-symbol-p (symbol)
2149 "Return non-nil if the dependencies of SYMBOL have not yet been loaded."
2150 (let ((found nil)
2151 (loads (get symbol 'custom-loads))
2152 load)
2153 (while loads
2154 (setq load (car loads)
2155 loads (cdr loads))
2156 (cond ((symbolp load)
2157 (unless (featurep load)
2158 (setq found t)))
2159 ((assoc load load-history))
2160 ((assoc (locate-library load) load-history)
2161 (message nil))
2163 (setq found t))))
2164 found))
2166 (defun custom-unloaded-widget-p (widget)
2167 "Return non-nil if the dependencies of WIDGET have not yet been loaded."
2168 (custom-unloaded-symbol-p (widget-value widget)))
2170 (defun custom-toggle-hide (widget)
2171 "Toggle visibility of WIDGET."
2172 (custom-load-widget widget)
2173 (let ((state (widget-get widget :custom-state)))
2174 (cond ((memq state '(invalid modified))
2175 (error "There are unset changes"))
2176 ((eq state 'hidden)
2177 (widget-put widget :custom-state 'unknown))
2179 (widget-put widget :documentation-shown nil)
2180 (widget-put widget :custom-state 'hidden)))
2181 (custom-redraw widget)
2182 (widget-setup)))
2184 (defun custom-toggle-parent (widget &rest ignore)
2185 "Toggle visibility of parent of WIDGET."
2186 (custom-toggle-hide (widget-get widget :parent)))
2188 (defun custom-add-see-also (widget &optional prefix)
2189 "Add `See also ...' to WIDGET if there are any links.
2190 Insert PREFIX first if non-nil."
2191 (let* ((symbol (widget-get widget :value))
2192 (links (get symbol 'custom-links))
2193 (many (> (length links) 2))
2194 (buttons (widget-get widget :buttons))
2195 (indent (widget-get widget :indent)))
2196 (when links
2197 (when indent
2198 (insert-char ?\ indent))
2199 (when prefix
2200 (insert prefix))
2201 (insert "See also ")
2202 (while links
2203 (push (widget-create-child-and-convert
2204 widget (car links)
2205 :button-face 'custom-link
2206 :mouse-face 'highlight
2207 :pressed-face 'highlight)
2208 buttons)
2209 (setq links (cdr links))
2210 (cond ((null links)
2211 (insert ".\n"))
2212 ((null (cdr links))
2213 (if many
2214 (insert ", and ")
2215 (insert " and ")))
2217 (insert ", "))))
2218 (widget-put widget :buttons buttons))))
2220 (defun custom-add-parent-links (widget &optional initial-string)
2221 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
2222 The value is non-nil if any parents were found.
2223 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
2224 (let ((name (widget-value widget))
2225 (type (widget-type widget))
2226 (buttons (widget-get widget :buttons))
2227 (start (point))
2228 (parents nil))
2229 (insert (or initial-string "Parent groups:"))
2230 (mapatoms (lambda (symbol)
2231 (when (member (list name type) (get symbol 'custom-group))
2232 (insert " ")
2233 (push (widget-create-child-and-convert
2234 widget 'custom-group-link
2235 :tag (custom-unlispify-tag-name symbol)
2236 symbol)
2237 buttons)
2238 (setq parents (cons symbol parents)))))
2239 (and (null (get name 'custom-links)) ;No links of its own.
2240 (= (length parents) 1) ;A single parent.
2241 (let* ((links (delq nil (mapcar (lambda (w)
2242 (unless (eq (widget-type w)
2243 'custom-group-link)
2245 (get (car parents) 'custom-links))))
2246 (many (> (length links) 2)))
2247 (when links
2248 (insert "\nParent documentation: ")
2249 (while links
2250 (push (widget-create-child-and-convert
2251 widget (car links)
2252 :button-face 'custom-link
2253 :mouse-face 'highlight
2254 :pressed-face 'highlight)
2255 buttons)
2256 (setq links (cdr links))
2257 (cond ((null links)
2258 (insert ".\n"))
2259 ((null (cdr links))
2260 (if many
2261 (insert ", and ")
2262 (insert " and ")))
2264 (insert ", ")))))))
2265 (if parents
2266 (insert "\n")
2267 (delete-region start (point)))
2268 (widget-put widget :buttons buttons)
2269 parents))
2271 ;;; The `custom-comment' Widget.
2273 ;; like the editable field
2274 (defface custom-comment '((((type tty))
2275 :background "yellow3"
2276 :foreground "black")
2277 (((class grayscale color)
2278 (background light))
2279 :background "gray85")
2280 (((class grayscale color)
2281 (background dark))
2282 :background "dim gray")
2284 :slant italic))
2285 "Face used for comments on variables or faces"
2286 :version "21.1"
2287 :group 'custom-faces)
2288 ;; backward-compatibility alias
2289 (put 'custom-comment-face 'face-alias 'custom-comment)
2291 ;; like font-lock-comment-face
2292 (defface custom-comment-tag
2293 '((((class color) (background dark)) (:foreground "gray80"))
2294 (((class color) (background light)) (:foreground "blue4"))
2295 (((class grayscale) (background light))
2296 (:foreground "DimGray" :weight bold :slant italic))
2297 (((class grayscale) (background dark))
2298 (:foreground "LightGray" :weight bold :slant italic))
2299 (t (:weight bold)))
2300 "Face used for variables or faces comment tags"
2301 :group 'custom-faces)
2302 ;; backward-compatibility alias
2303 (put 'custom-comment-tag-face 'face-alias 'custom-comment-tag)
2305 (define-widget 'custom-comment 'string
2306 "User comment."
2307 :tag "Comment"
2308 :help-echo "Edit a comment here."
2309 :sample-face 'custom-comment-tag-face
2310 :value-face 'custom-comment-face
2311 :shown nil
2312 :create 'custom-comment-create)
2314 (defun custom-comment-create (widget)
2315 (let* ((null-comment (equal "" (widget-value widget))))
2316 (if (or (widget-get (widget-get widget :parent) :comment-shown)
2317 (not null-comment))
2318 (widget-default-create widget)
2319 ;; `widget-default-delete' expects markers in these slots --
2320 ;; maybe it shouldn't.
2321 (widget-put widget :from (point-marker))
2322 (widget-put widget :to (point-marker)))))
2324 (defun custom-comment-hide (widget)
2325 (widget-put (widget-get widget :parent) :comment-shown nil))
2327 ;; Those functions are for the menu. WIDGET is NOT the comment widget. It's
2328 ;; the global custom one
2329 (defun custom-comment-show (widget)
2330 (widget-put widget :comment-shown t)
2331 (custom-redraw widget)
2332 (widget-setup))
2334 (defun custom-comment-invisible-p (widget)
2335 (let ((val (widget-value (widget-get widget :comment-widget))))
2336 (and (equal "" val)
2337 (not (widget-get widget :comment-shown)))))
2339 ;;; The `custom-variable' Widget.
2341 ;; When this was underlined blue, users confused it with a
2342 ;; Mosaic-style hyperlink...
2343 (defface custom-variable-tag
2344 `((((class color)
2345 (background dark))
2346 (:foreground "light blue" :weight bold :height 1.2 :inherit variable-pitch))
2347 (((min-colors 88) (class color)
2348 (background light))
2349 (:foreground "blue1" :weight bold :height 1.2 :inherit variable-pitch))
2350 (((class color)
2351 (background light))
2352 (:foreground "blue" :weight bold :height 1.2 :inherit variable-pitch))
2353 (t (:weight bold)))
2354 "Face used for unpushable variable tags."
2355 :group 'custom-faces)
2356 ;; backward-compatibility alias
2357 (put 'custom-variable-tag-face 'face-alias 'custom-variable-tag)
2359 (defface custom-variable-button '((t (:underline t :weight bold)))
2360 "Face used for pushable variable tags."
2361 :group 'custom-faces)
2362 ;; backward-compatibility alias
2363 (put 'custom-variable-button-face 'face-alias 'custom-variable-button)
2365 (defcustom custom-variable-default-form 'edit
2366 "Default form of displaying variable values."
2367 :type '(choice (const edit)
2368 (const lisp))
2369 :group 'custom-buffer
2370 :version "20.3")
2372 (defun custom-variable-documentation (variable)
2373 "Return documentation of VARIABLE for use in Custom buffer.
2374 Normally just return the docstring. But if VARIABLE automatically
2375 becomes buffer local when set, append a message to that effect."
2376 (if (and (local-variable-if-set-p variable)
2377 (or (not (local-variable-p variable))
2378 (with-temp-buffer
2379 (local-variable-if-set-p variable))))
2380 (concat (documentation-property variable 'variable-documentation)
2382 This variable automatically becomes buffer-local when set outside Custom.
2383 However, setting it through Custom sets the default value.")
2384 (documentation-property variable 'variable-documentation)))
2386 (define-widget 'custom-variable 'custom
2387 "Customize variable."
2388 :format "%v"
2389 :help-echo "Set or reset this variable."
2390 :documentation-property #'custom-variable-documentation
2391 :custom-category 'option
2392 :custom-state nil
2393 :custom-menu 'custom-variable-menu-create
2394 :custom-form nil ; defaults to value of `custom-variable-default-form'
2395 :value-create 'custom-variable-value-create
2396 :action 'custom-variable-action
2397 :custom-set 'custom-variable-set
2398 :custom-save 'custom-variable-save
2399 :custom-reset-current 'custom-redraw
2400 :custom-reset-saved 'custom-variable-reset-saved
2401 :custom-reset-standard 'custom-variable-reset-standard
2402 :custom-standard-value 'custom-variable-standard-value)
2404 (defun custom-variable-type (symbol)
2405 "Return a widget suitable for editing the value of SYMBOL.
2406 If SYMBOL has a `custom-type' property, use that.
2407 Otherwise, look up symbol in `custom-guess-type-alist'."
2408 (let* ((type (or (get symbol 'custom-type)
2409 (and (not (get symbol 'standard-value))
2410 (custom-guess-type symbol))
2411 'sexp))
2412 (options (get symbol 'custom-options))
2413 (tmp (if (listp type)
2414 (copy-sequence type)
2415 (list type))))
2416 (when options
2417 (widget-put tmp :options options))
2418 tmp))
2420 (defun custom-variable-value-create (widget)
2421 "Here is where you edit the variable's value."
2422 (custom-load-widget widget)
2423 (unless (widget-get widget :custom-form)
2424 (widget-put widget :custom-form custom-variable-default-form))
2425 (let* ((buttons (widget-get widget :buttons))
2426 (children (widget-get widget :children))
2427 (form (widget-get widget :custom-form))
2428 (state (widget-get widget :custom-state))
2429 (symbol (widget-get widget :value))
2430 (tag (widget-get widget :tag))
2431 (type (custom-variable-type symbol))
2432 (conv (widget-convert type))
2433 (get (or (get symbol 'custom-get) 'default-value))
2434 (prefix (widget-get widget :custom-prefix))
2435 (last (widget-get widget :custom-last))
2436 (value (if (default-boundp symbol)
2437 (funcall get symbol)
2438 (widget-get conv :value))))
2439 ;; If the widget is new, the child determines whether it is hidden.
2440 (cond (state)
2441 ((custom-show type value)
2442 (setq state 'unknown))
2444 (setq state 'hidden)))
2445 ;; If we don't know the state, see if we need to edit it in lisp form.
2446 (when (eq state 'unknown)
2447 (unless (widget-apply conv :match value)
2448 ;; (widget-apply (widget-convert type) :match value)
2449 (setq form 'mismatch)))
2450 ;; Now we can create the child widget.
2451 (cond ((eq custom-buffer-style 'tree)
2452 (insert prefix (if last " `--- " " |--- "))
2453 (push (widget-create-child-and-convert
2454 widget 'custom-browse-variable-tag)
2455 buttons)
2456 (insert " " tag "\n")
2457 (widget-put widget :buttons buttons))
2458 ((eq state 'hidden)
2459 ;; Indicate hidden value.
2460 (push (widget-create-child-and-convert
2461 widget 'item
2462 :format "%{%t%}: "
2463 :sample-face 'custom-variable-tag-face
2464 :tag tag
2465 :parent widget)
2466 buttons)
2467 (push (widget-create-child-and-convert
2468 widget 'visibility
2469 :help-echo "Show the value of this option."
2470 :off "Show Value"
2471 :action 'custom-toggle-parent
2472 nil)
2473 buttons))
2474 ((memq form '(lisp mismatch))
2475 ;; In lisp mode edit the saved value when possible.
2476 (let* ((value (cond ((get symbol 'saved-value)
2477 (car (get symbol 'saved-value)))
2478 ((get symbol 'standard-value)
2479 (car (get symbol 'standard-value)))
2480 ((default-boundp symbol)
2481 (custom-quote (funcall get symbol)))
2483 (custom-quote (widget-get conv :value))))))
2484 (insert (symbol-name symbol) ": ")
2485 (push (widget-create-child-and-convert
2486 widget 'visibility
2487 :help-echo "Hide the value of this option."
2488 :on "Hide Value"
2489 :off "Show Value"
2490 :action 'custom-toggle-parent
2492 buttons)
2493 (insert " ")
2494 (push (widget-create-child-and-convert
2495 widget 'sexp
2496 :button-face 'custom-variable-button-face
2497 :format "%v"
2498 :tag (symbol-name symbol)
2499 :parent widget
2500 :value value)
2501 children)))
2503 ;; Edit mode.
2504 (let* ((format (widget-get type :format))
2505 tag-format value-format)
2506 (unless (string-match ":" format)
2507 (error "Bad format"))
2508 (setq tag-format (substring format 0 (match-end 0)))
2509 (setq value-format (substring format (match-end 0)))
2510 (push (widget-create-child-and-convert
2511 widget 'item
2512 :format tag-format
2513 :action 'custom-tag-action
2514 :help-echo "Change value of this option."
2515 :mouse-down-action 'custom-tag-mouse-down-action
2516 :button-face 'custom-variable-button-face
2517 :sample-face 'custom-variable-tag-face
2518 tag)
2519 buttons)
2520 (insert " ")
2521 (push (widget-create-child-and-convert
2522 widget 'visibility
2523 :help-echo "Hide the value of this option."
2524 :on "Hide Value"
2525 :off "Show Value"
2526 :action 'custom-toggle-parent
2528 buttons)
2529 (push (widget-create-child-and-convert
2530 widget type
2531 :format value-format
2532 :value value)
2533 children))))
2534 (unless (eq custom-buffer-style 'tree)
2535 (unless (eq (preceding-char) ?\n)
2536 (widget-insert "\n"))
2537 ;; Create the magic button.
2538 (let ((magic (widget-create-child-and-convert
2539 widget 'custom-magic nil)))
2540 (widget-put widget :custom-magic magic)
2541 (push magic buttons))
2542 ;; ### NOTE: this is ugly!!!! I need to update the :buttons property
2543 ;; before the call to `widget-default-format-handler'. Otherwise, I
2544 ;; loose my current `buttons'. This function shouldn't be called like
2545 ;; this anyway. The doc string widget should be added like the others.
2546 ;; --dv
2547 (widget-put widget :buttons buttons)
2548 (insert "\n")
2549 ;; Insert documentation.
2550 (widget-default-format-handler widget ?h)
2552 ;; The comment field
2553 (unless (eq state 'hidden)
2554 (let* ((comment (get symbol 'variable-comment))
2555 (comment-widget
2556 (widget-create-child-and-convert
2557 widget 'custom-comment
2558 :parent widget
2559 :value (or comment ""))))
2560 (widget-put widget :comment-widget comment-widget)
2561 ;; Don't push it !!! Custom assumes that the first child is the
2562 ;; value one.
2563 (setq children (append children (list comment-widget)))))
2564 ;; Update the rest of the properties properties.
2565 (widget-put widget :custom-form form)
2566 (widget-put widget :children children)
2567 ;; Now update the state.
2568 (if (eq state 'hidden)
2569 (widget-put widget :custom-state state)
2570 (custom-variable-state-set widget))
2571 ;; See also.
2572 (unless (eq state 'hidden)
2573 (when (eq (widget-get widget :custom-level) 1)
2574 (custom-add-parent-links widget))
2575 (custom-add-see-also widget)))))
2577 (defun custom-tag-action (widget &rest args)
2578 "Pass :action to first child of WIDGET's parent."
2579 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
2580 :action args))
2582 (defun custom-tag-mouse-down-action (widget &rest args)
2583 "Pass :mouse-down-action to first child of WIDGET's parent."
2584 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
2585 :mouse-down-action args))
2587 (defun custom-variable-state-set (widget)
2588 "Set the state of WIDGET."
2589 (let* ((symbol (widget-value widget))
2590 (get (or (get symbol 'custom-get) 'default-value))
2591 (value (if (default-boundp symbol)
2592 (funcall get symbol)
2593 (widget-get widget :value)))
2594 (comment (get symbol 'variable-comment))
2596 temp
2597 (state (cond ((progn (setq tmp (get symbol 'customized-value))
2598 (setq temp
2599 (get symbol 'customized-variable-comment))
2600 (or tmp temp))
2601 (if (condition-case nil
2602 (and (equal value (eval (car tmp)))
2603 (equal comment temp))
2604 (error nil))
2605 'set
2606 'changed))
2607 ((progn (setq tmp (get symbol 'theme-value))
2608 (setq temp (get symbol 'saved-variable-comment))
2609 (or tmp temp))
2610 (if (condition-case nil
2611 (and (equal comment temp)
2612 (equal value
2613 (eval
2614 (car (custom-variable-theme-value
2615 symbol)))))
2616 (error nil))
2617 (cond
2618 ((eq (caar tmp) 'user) 'saved)
2619 ((eq (caar tmp) 'changed) 'changed)
2620 (t 'themed))
2621 'changed))
2622 ((setq tmp (get symbol 'standard-value))
2623 (if (condition-case nil
2624 (and (equal value (eval (car tmp)))
2625 (equal comment nil))
2626 (error nil))
2627 'standard
2628 'changed))
2629 (t 'rogue))))
2630 (widget-put widget :custom-state state)))
2632 (defun custom-variable-standard-value (widget)
2633 (get (widget-value widget) 'standard-value))
2635 (defvar custom-variable-menu
2636 `(("Set for Current Session" custom-variable-set
2637 (lambda (widget)
2638 (eq (widget-get widget :custom-state) 'modified)))
2639 ,@(when (or custom-file user-init-file)
2640 '(("Save for Future Sessions" custom-variable-save
2641 (lambda (widget)
2642 (memq (widget-get widget :custom-state)
2643 '(modified set changed rogue))))))
2644 ("Undo Edits" custom-redraw
2645 (lambda (widget)
2646 (and (default-boundp (widget-value widget))
2647 (memq (widget-get widget :custom-state) '(modified changed)))))
2648 ("Reset to Saved" custom-variable-reset-saved
2649 (lambda (widget)
2650 (and (or (get (widget-value widget) 'saved-value)
2651 (get (widget-value widget) 'saved-variable-comment))
2652 (memq (widget-get widget :custom-state)
2653 '(modified set changed rogue)))))
2654 ,@(when (or custom-file user-init-file)
2655 '(("Erase Customization" custom-variable-reset-standard
2656 (lambda (widget)
2657 (and (get (widget-value widget) 'standard-value)
2658 (memq (widget-get widget :custom-state)
2659 '(modified set changed saved rogue)))))))
2660 ("Set to Backup Value" custom-variable-reset-backup
2661 (lambda (widget)
2662 (get (widget-value widget) 'backup-value)))
2663 ("---" ignore ignore)
2664 ("Add Comment" custom-comment-show custom-comment-invisible-p)
2665 ("---" ignore ignore)
2666 ("Show Current Value" custom-variable-edit
2667 (lambda (widget)
2668 (eq (widget-get widget :custom-form) 'lisp)))
2669 ("Show Saved Lisp Expression" custom-variable-edit-lisp
2670 (lambda (widget)
2671 (eq (widget-get widget :custom-form) 'edit))))
2672 "Alist of actions for the `custom-variable' widget.
2673 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2674 the menu entry, ACTION is the function to call on the widget when the
2675 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2676 widget as an argument, and returns non-nil if ACTION is valid on that
2677 widget. If FILTER is nil, ACTION is always valid.")
2679 (defun custom-variable-action (widget &optional event)
2680 "Show the menu for `custom-variable' WIDGET.
2681 Optional EVENT is the location for the menu."
2682 (if (eq (widget-get widget :custom-state) 'hidden)
2683 (custom-toggle-hide widget)
2684 (unless (eq (widget-get widget :custom-state) 'modified)
2685 (custom-variable-state-set widget))
2686 (custom-redraw-magic widget)
2687 (let* ((completion-ignore-case t)
2688 (answer (widget-choose (concat "Operation on "
2689 (custom-unlispify-tag-name
2690 (widget-get widget :value)))
2691 (custom-menu-filter custom-variable-menu
2692 widget)
2693 event)))
2694 (if answer
2695 (funcall answer widget)))))
2697 (defun custom-variable-edit (widget)
2698 "Edit value of WIDGET."
2699 (widget-put widget :custom-state 'unknown)
2700 (widget-put widget :custom-form 'edit)
2701 (custom-redraw widget))
2703 (defun custom-variable-edit-lisp (widget)
2704 "Edit the Lisp representation of the value of WIDGET."
2705 (widget-put widget :custom-state 'unknown)
2706 (widget-put widget :custom-form 'lisp)
2707 (custom-redraw widget))
2709 (defun custom-variable-set (widget)
2710 "Set the current value for the variable being edited by WIDGET."
2711 (let* ((form (widget-get widget :custom-form))
2712 (state (widget-get widget :custom-state))
2713 (child (car (widget-get widget :children)))
2714 (symbol (widget-value widget))
2715 (set (or (get symbol 'custom-set) 'set-default))
2716 (comment-widget (widget-get widget :comment-widget))
2717 (comment (widget-value comment-widget))
2718 val)
2719 (cond ((eq state 'hidden)
2720 (error "Cannot set hidden variable"))
2721 ((setq val (widget-apply child :validate))
2722 (goto-char (widget-get val :from))
2723 (error "%s" (widget-get val :error)))
2724 ((memq form '(lisp mismatch))
2725 (when (equal comment "")
2726 (setq comment nil)
2727 ;; Make the comment invisible by hand if it's empty
2728 (custom-comment-hide comment-widget))
2729 (custom-variable-backup-value widget)
2730 (custom-push-theme 'theme-value symbol 'user
2731 'set (custom-quote (widget-value child)))
2732 (funcall set symbol (eval (setq val (widget-value child))))
2733 (put symbol 'customized-value (list val))
2734 (put symbol 'variable-comment comment)
2735 (put symbol 'customized-variable-comment comment))
2737 (when (equal comment "")
2738 (setq comment nil)
2739 ;; Make the comment invisible by hand if it's empty
2740 (custom-comment-hide comment-widget))
2741 (custom-variable-backup-value widget)
2742 (custom-push-theme 'theme-value symbol 'user
2743 'set (custom-quote (widget-value child)))
2744 (funcall set symbol (setq val (widget-value child)))
2745 (put symbol 'customized-value (list (custom-quote val)))
2746 (put symbol 'variable-comment comment)
2747 (put symbol 'customized-variable-comment comment)))
2748 (custom-variable-state-set widget)
2749 (custom-redraw-magic widget)))
2751 (defun custom-variable-save (widget)
2752 "Set and save the value for the variable being edited by WIDGET."
2753 (let* ((form (widget-get widget :custom-form))
2754 (state (widget-get widget :custom-state))
2755 (child (car (widget-get widget :children)))
2756 (symbol (widget-value widget))
2757 (set (or (get symbol 'custom-set) 'set-default))
2758 (comment-widget (widget-get widget :comment-widget))
2759 (comment (widget-value comment-widget))
2760 val)
2761 (cond ((eq state 'hidden)
2762 (error "Cannot set hidden variable"))
2763 ((setq val (widget-apply child :validate))
2764 (goto-char (widget-get val :from))
2765 (error "Saving %s: %s" symbol (widget-get val :error)))
2766 ((memq form '(lisp mismatch))
2767 (when (equal comment "")
2768 (setq comment nil)
2769 ;; Make the comment invisible by hand if it's empty
2770 (custom-comment-hide comment-widget))
2771 (put symbol 'saved-value (list (widget-value child)))
2772 (custom-push-theme 'theme-value symbol 'user
2773 'set (custom-quote (widget-value child)))
2774 (funcall set symbol (eval (widget-value child)))
2775 (put symbol 'variable-comment comment)
2776 (put symbol 'saved-variable-comment comment))
2778 (when (equal comment "")
2779 (setq comment nil)
2780 ;; Make the comment invisible by hand if it's empty
2781 (custom-comment-hide comment-widget))
2782 (put symbol 'saved-value
2783 (list (custom-quote (widget-value child))))
2784 (custom-push-theme 'theme-value symbol 'user
2785 'set (custom-quote (widget-value child)))
2786 (funcall set symbol (widget-value child))
2787 (put symbol 'variable-comment comment)
2788 (put symbol 'saved-variable-comment comment)))
2789 (put symbol 'customized-value nil)
2790 (put symbol 'customized-variable-comment nil)
2791 (custom-save-all)
2792 (custom-variable-state-set widget)
2793 (custom-redraw-magic widget)))
2795 (defun custom-variable-reset-saved (widget)
2796 "Restore the saved value for the variable being edited by WIDGET.
2797 This also updates the buffer to show that value.
2798 The value that was current before this operation
2799 becomes the backup value, so you can get it again."
2800 (let* ((symbol (widget-value widget))
2801 (set (or (get symbol 'custom-set) 'set-default))
2802 (value (get symbol 'saved-value))
2803 (comment (get symbol 'saved-variable-comment)))
2804 (cond ((or value comment)
2805 (put symbol 'variable-comment comment)
2806 (custom-variable-backup-value widget)
2807 (custom-push-theme 'theme-value symbol 'user 'set (car-safe value))
2808 (condition-case nil
2809 (funcall set symbol (eval (car value)))
2810 (error nil)))
2812 (error "No saved value for %s" symbol)))
2813 (put symbol 'customized-value nil)
2814 (put symbol 'customized-variable-comment nil)
2815 (widget-put widget :custom-state 'unknown)
2816 ;; This call will possibly make the comment invisible
2817 (custom-redraw widget)))
2819 (defun custom-variable-reset-standard (widget)
2820 "Restore the standard setting for the variable being edited by WIDGET.
2821 This operation eliminates any saved setting for the variable,
2822 restoring it to the state of a variable that has never been customized.
2823 The value that was current before this operation
2824 becomes the backup value, so you can get it again."
2825 (let* ((symbol (widget-value widget)))
2826 (if (get symbol 'standard-value)
2827 (custom-variable-backup-value widget)
2828 (error "No standard setting known for %S" symbol))
2829 (put symbol 'variable-comment nil)
2830 (put symbol 'customized-value nil)
2831 (put symbol 'customized-variable-comment nil)
2832 (custom-push-theme 'theme-value symbol 'user 'reset)
2833 (custom-theme-recalc-variable symbol)
2834 (when (or (get symbol 'saved-value) (get symbol 'saved-variable-comment))
2835 (put symbol 'saved-value nil)
2836 (put symbol 'saved-variable-comment nil)
2837 (custom-save-all))
2838 (widget-put widget :custom-state 'unknown)
2839 ;; This call will possibly make the comment invisible
2840 (custom-redraw widget)))
2842 (defun custom-variable-backup-value (widget)
2843 "Back up the current value for WIDGET's variable.
2844 The backup value is kept in the car of the `backup-value' property."
2845 (let* ((symbol (widget-value widget))
2846 (get (or (get symbol 'custom-get) 'default-value))
2847 (type (custom-variable-type symbol))
2848 (conv (widget-convert type))
2849 (value (if (default-boundp symbol)
2850 (funcall get symbol)
2851 (widget-get conv :value))))
2852 (put symbol 'backup-value (list value))))
2854 (defun custom-variable-reset-backup (widget)
2855 "Restore the backup value for the variable being edited by WIDGET.
2856 The value that was current before this operation
2857 becomes the backup value, so you can use this operation repeatedly
2858 to switch between two values."
2859 (let* ((symbol (widget-value widget))
2860 (set (or (get symbol 'custom-set) 'set-default))
2861 (value (get symbol 'backup-value))
2862 (comment-widget (widget-get widget :comment-widget))
2863 (comment (widget-value comment-widget)))
2864 (if value
2865 (progn
2866 (custom-variable-backup-value widget)
2867 (custom-push-theme 'theme-value symbol 'user 'set value)
2868 (condition-case nil
2869 (funcall set symbol (car value))
2870 (error nil)))
2871 (error "No backup value for %s" symbol))
2872 (put symbol 'customized-value (list (car value)))
2873 (put symbol 'variable-comment comment)
2874 (put symbol 'customized-variable-comment comment)
2875 (custom-variable-state-set widget)
2876 ;; This call will possibly make the comment invisible
2877 (custom-redraw widget)))
2879 ;;; The `custom-face-edit' Widget.
2881 (define-widget 'custom-face-edit 'checklist
2882 "Edit face attributes."
2883 :format "%t: %v"
2884 :tag "Attributes"
2885 :extra-offset 13
2886 :button-args '(:help-echo "Control whether this attribute has any effect.")
2887 :value-to-internal 'custom-face-edit-fix-value
2888 :match (lambda (widget value)
2889 (widget-checklist-match widget
2890 (custom-face-edit-fix-value widget value)))
2891 :convert-widget 'custom-face-edit-convert-widget
2892 :args (mapcar (lambda (att)
2893 (list 'group
2894 :inline t
2895 :sibling-args (widget-get (nth 1 att) :sibling-args)
2896 (list 'const :format "" :value (nth 0 att))
2897 (nth 1 att)))
2898 custom-face-attributes))
2900 (defun custom-face-edit-fix-value (widget value)
2901 "Ignoring WIDGET, convert :bold and :italic in VALUE to new form.
2902 Also change :reverse-video to :inverse-video."
2903 (if (listp value)
2904 (let (result)
2905 (while value
2906 (let ((key (car value))
2907 (val (car (cdr value))))
2908 (cond ((eq key :italic)
2909 (push :slant result)
2910 (push (if val 'italic 'normal) result))
2911 ((eq key :bold)
2912 (push :weight result)
2913 (push (if val 'bold 'normal) result))
2914 ((eq key :reverse-video)
2915 (push :inverse-video result)
2916 (push val result))
2918 (push key result)
2919 (push val result))))
2920 (setq value (cdr (cdr value))))
2921 (setq result (nreverse result))
2922 result)
2923 value))
2925 (defun custom-face-edit-convert-widget (widget)
2926 "Convert :args as widget types in WIDGET."
2927 (widget-put
2928 widget
2929 :args (mapcar (lambda (arg)
2930 (widget-convert arg
2931 :deactivate 'custom-face-edit-deactivate
2932 :activate 'custom-face-edit-activate
2933 :delete 'custom-face-edit-delete))
2934 (widget-get widget :args)))
2935 widget)
2937 (defun custom-face-edit-deactivate (widget)
2938 "Make face widget WIDGET inactive for user modifications."
2939 (unless (widget-get widget :inactive)
2940 (let ((tag (custom-face-edit-attribute-tag widget))
2941 (from (copy-marker (widget-get widget :from)))
2942 (value (widget-value widget))
2943 (inhibit-read-only t)
2944 (inhibit-modification-hooks t))
2945 (save-excursion
2946 (goto-char from)
2947 (widget-default-delete widget)
2948 (insert tag ": *\n")
2949 (widget-put widget :inactive
2950 (cons value (cons from (- (point) from))))))))
2952 (defun custom-face-edit-activate (widget)
2953 "Make face widget WIDGET inactive for user modifications."
2954 (let ((inactive (widget-get widget :inactive))
2955 (inhibit-read-only t)
2956 (inhibit-modification-hooks t))
2957 (when (consp inactive)
2958 (save-excursion
2959 (goto-char (car (cdr inactive)))
2960 (delete-region (point) (+ (point) (cdr (cdr inactive))))
2961 (widget-put widget :inactive nil)
2962 (widget-apply widget :create)
2963 (widget-value-set widget (car inactive))
2964 (widget-setup)))))
2966 (defun custom-face-edit-delete (widget)
2967 "Remove WIDGET from the buffer."
2968 (let ((inactive (widget-get widget :inactive))
2969 (inhibit-read-only t)
2970 (inhibit-modification-hooks t))
2971 (if (not inactive)
2972 ;; Widget is alive, we don't have to do anything special
2973 (widget-default-delete widget)
2974 ;; WIDGET is already deleted because we did so to inactivate it;
2975 ;; now just get rid of the label we put in its place.
2976 (delete-region (car (cdr inactive))
2977 (+ (car (cdr inactive)) (cdr (cdr inactive))))
2978 (widget-put widget :inactive nil))))
2981 (defun custom-face-edit-attribute-tag (widget)
2982 "Returns the first :tag property in WIDGET or one of its children."
2983 (let ((tag (widget-get widget :tag)))
2984 (or (and (not (equal tag "")) tag)
2985 (let ((children (widget-get widget :children)))
2986 (while (and (null tag) children)
2987 (setq tag (custom-face-edit-attribute-tag (pop children))))
2988 tag))))
2990 ;;; The `custom-display' Widget.
2992 (define-widget 'custom-display 'menu-choice
2993 "Select a display type."
2994 :tag "Display"
2995 :value t
2996 :help-echo "Specify frames where the face attributes should be used."
2997 :args '((const :tag "all" t)
2998 (const :tag "defaults" default)
2999 (checklist
3000 :offset 0
3001 :extra-offset 9
3002 :args ((group :sibling-args (:help-echo "\
3003 Only match the specified window systems.")
3004 (const :format "Type: "
3005 type)
3006 (checklist :inline t
3007 :offset 0
3008 (const :format "X "
3009 :sibling-args (:help-echo "\
3010 The X11 Window System.")
3012 (const :format "PM "
3013 :sibling-args (:help-echo "\
3014 OS/2 Presentation Manager.")
3016 (const :format "W32 "
3017 :sibling-args (:help-echo "\
3018 Windows NT/9X.")
3019 w32)
3020 (const :format "MAC "
3021 :sibling-args (:help-echo "\
3022 Macintosh OS.")
3023 mac)
3024 (const :format "DOS "
3025 :sibling-args (:help-echo "\
3026 Plain MS-DOS.")
3028 (const :format "TTY%n"
3029 :sibling-args (:help-echo "\
3030 Plain text terminals.")
3031 tty)))
3032 (group :sibling-args (:help-echo "\
3033 Only match the frames with the specified color support.")
3034 (const :format "Class: "
3035 class)
3036 (checklist :inline t
3037 :offset 0
3038 (const :format "Color "
3039 :sibling-args (:help-echo "\
3040 Match color frames.")
3041 color)
3042 (const :format "Grayscale "
3043 :sibling-args (:help-echo "\
3044 Match grayscale frames.")
3045 grayscale)
3046 (const :format "Monochrome%n"
3047 :sibling-args (:help-echo "\
3048 Match frames with no color support.")
3049 mono)))
3050 (group :sibling-args (:help-echo "\
3051 The minimum number of colors the frame should support.")
3052 (const :format "" min-colors)
3053 (integer :tag "Minimum number of colors" ))
3054 (group :sibling-args (:help-echo "\
3055 Only match frames with the specified intensity.")
3056 (const :format "\
3057 Background brightness: "
3058 background)
3059 (checklist :inline t
3060 :offset 0
3061 (const :format "Light "
3062 :sibling-args (:help-echo "\
3063 Match frames with light backgrounds.")
3064 light)
3065 (const :format "Dark\n"
3066 :sibling-args (:help-echo "\
3067 Match frames with dark backgrounds.")
3068 dark)))
3069 (group :sibling-args (:help-echo "\
3070 Only match frames that support the specified face attributes.")
3071 (const :format "Supports attributes:" supports)
3072 (custom-face-edit :inline t :format "%n%v"))))))
3074 ;;; The `custom-face' Widget.
3076 (defface custom-face-tag
3077 `((t (:weight bold :height 1.2 :inherit variable-pitch)))
3078 "Face used for face tags."
3079 :group 'custom-faces)
3080 ;; backward-compatibility alias
3081 (put 'custom-face-tag-face 'face-alias 'custom-face-tag)
3083 (defcustom custom-face-default-form 'selected
3084 "Default form of displaying face definition."
3085 :type '(choice (const all)
3086 (const selected)
3087 (const lisp))
3088 :group 'custom-buffer
3089 :version "20.3")
3091 (define-widget 'custom-face 'custom
3092 "Customize face."
3093 :sample-face 'custom-face-tag-face
3094 :help-echo "Set or reset this face."
3095 :documentation-property #'face-doc-string
3096 :value-create 'custom-face-value-create
3097 :action 'custom-face-action
3098 :custom-category 'face
3099 :custom-form nil ; defaults to value of `custom-face-default-form'
3100 :custom-set 'custom-face-set
3101 :custom-save 'custom-face-save
3102 :custom-reset-current 'custom-redraw
3103 :custom-reset-saved 'custom-face-reset-saved
3104 :custom-reset-standard 'custom-face-reset-standard
3105 :custom-standard-value 'custom-face-standard-value
3106 :custom-menu 'custom-face-menu-create)
3108 (define-widget 'custom-face-all 'editable-list
3109 "An editable list of display specifications and attributes."
3110 :entry-format "%i %d %v"
3111 :insert-button-args '(:help-echo "Insert new display specification here.")
3112 :append-button-args '(:help-echo "Append new display specification here.")
3113 :delete-button-args '(:help-echo "Delete this display specification.")
3114 :args '((group :format "%v" custom-display custom-face-edit)))
3116 (defconst custom-face-all (widget-convert 'custom-face-all)
3117 "Converted version of the `custom-face-all' widget.")
3119 (define-widget 'custom-display-unselected 'item
3120 "A display specification that doesn't match the selected display."
3121 :match 'custom-display-unselected-match)
3123 (defun custom-display-unselected-match (widget value)
3124 "Non-nil if VALUE is an unselected display specification."
3125 (not (face-spec-set-match-display value (selected-frame))))
3127 (define-widget 'custom-face-selected 'group
3128 "Edit the attributes of the selected display in a face specification."
3129 :args '((choice :inline t
3130 (group :tag "With Defaults" :inline t
3131 (group (const :tag "" default)
3132 (custom-face-edit :tag " Default\n Attributes"))
3133 (repeat :format ""
3134 :inline t
3135 (group custom-display-unselected sexp))
3136 (group (sexp :format "")
3137 (custom-face-edit :tag " Overriding\n Attributes"))
3138 (repeat :format ""
3139 :inline t
3140 sexp))
3141 (group :tag "No Defaults" :inline t
3142 (repeat :format ""
3143 :inline t
3144 (group custom-display-unselected sexp))
3145 (group (sexp :format "")
3146 (custom-face-edit :tag "\n Attributes"))
3147 (repeat :format ""
3148 :inline t
3149 sexp)))))
3153 (defconst custom-face-selected (widget-convert 'custom-face-selected)
3154 "Converted version of the `custom-face-selected' widget.")
3156 (defun custom-filter-face-spec (spec filter-index &optional default-filter)
3157 "Return a canonicalized version of SPEC using.
3158 FILTER-INDEX is the index in the entry for each attribute in
3159 `custom-face-attributes' at which the appropriate filter function can be
3160 found, and DEFAULT-FILTER is the filter to apply for attributes that
3161 don't specify one."
3162 (mapcar (lambda (entry)
3163 ;; Filter a single face-spec entry
3164 (let ((tests (car entry))
3165 (unfiltered-attrs
3166 ;; Handle both old- and new-style attribute syntax
3167 (if (listp (car (cdr entry)))
3168 (car (cdr entry))
3169 (cdr entry)))
3170 (filtered-attrs nil))
3171 ;; Filter each face attribute
3172 (while unfiltered-attrs
3173 (let* ((attr (pop unfiltered-attrs))
3174 (pre-filtered-value (pop unfiltered-attrs))
3175 (filter
3176 (or (nth filter-index (assq attr custom-face-attributes))
3177 default-filter))
3178 (filtered-value
3179 (if filter
3180 (funcall filter pre-filtered-value)
3181 pre-filtered-value)))
3182 (push filtered-value filtered-attrs)
3183 (push attr filtered-attrs)))
3185 (list tests filtered-attrs)))
3186 spec))
3188 (defun custom-pre-filter-face-spec (spec)
3189 "Return SPEC changed as necessary for editing by the face customization widget.
3190 SPEC must be a full face spec."
3191 (custom-filter-face-spec spec 2))
3193 (defun custom-post-filter-face-spec (spec)
3194 "Return the customized SPEC in a form suitable for setting the face."
3195 (custom-filter-face-spec spec 3))
3197 (defun custom-face-value-create (widget)
3198 "Create a list of the display specifications for WIDGET."
3199 (let ((buttons (widget-get widget :buttons))
3200 children
3201 (symbol (widget-get widget :value))
3202 (tag (widget-get widget :tag))
3203 (state (widget-get widget :custom-state))
3204 (begin (point))
3205 (is-last (widget-get widget :custom-last))
3206 (prefix (widget-get widget :custom-prefix)))
3207 (unless tag
3208 (setq tag (prin1-to-string symbol)))
3209 (cond ((eq custom-buffer-style 'tree)
3210 (insert prefix (if is-last " `--- " " |--- "))
3211 (push (widget-create-child-and-convert
3212 widget 'custom-browse-face-tag)
3213 buttons)
3214 (insert " " tag "\n")
3215 (widget-put widget :buttons buttons))
3217 ;; Create tag.
3218 (insert tag)
3219 (widget-specify-sample widget begin (point))
3220 (if (eq custom-buffer-style 'face)
3221 (insert " ")
3222 (if (string-match "face\\'" tag)
3223 (insert ":")
3224 (insert " face: ")))
3225 ;; Sample.
3226 (push (widget-create-child-and-convert widget 'item
3227 :format "(%{%t%})"
3228 :sample-face symbol
3229 :tag "sample")
3230 buttons)
3231 ;; Visibility.
3232 (insert " ")
3233 (push (widget-create-child-and-convert
3234 widget 'visibility
3235 :help-echo "Hide or show this face."
3236 :on "Hide Face"
3237 :off "Show Face"
3238 :action 'custom-toggle-parent
3239 (not (eq state 'hidden)))
3240 buttons)
3241 ;; Magic.
3242 (insert "\n")
3243 (let ((magic (widget-create-child-and-convert
3244 widget 'custom-magic nil)))
3245 (widget-put widget :custom-magic magic)
3246 (push magic buttons))
3247 ;; Update buttons.
3248 (widget-put widget :buttons buttons)
3249 ;; Insert documentation.
3250 (widget-default-format-handler widget ?h)
3251 ;; The comment field
3252 (unless (eq state 'hidden)
3253 (let* ((comment (get symbol 'face-comment))
3254 (comment-widget
3255 (widget-create-child-and-convert
3256 widget 'custom-comment
3257 :parent widget
3258 :value (or comment ""))))
3259 (widget-put widget :comment-widget comment-widget)
3260 (push comment-widget children)))
3261 ;; See also.
3262 (unless (eq state 'hidden)
3263 (when (eq (widget-get widget :custom-level) 1)
3264 (custom-add-parent-links widget))
3265 (custom-add-see-also widget))
3266 ;; Editor.
3267 (unless (eq (preceding-char) ?\n)
3268 (insert "\n"))
3269 (unless (eq state 'hidden)
3270 (message "Creating face editor...")
3271 (custom-load-widget widget)
3272 (unless (widget-get widget :custom-form)
3273 (widget-put widget :custom-form custom-face-default-form))
3274 (let* ((symbol (widget-value widget))
3275 (spec (or (get symbol 'customized-face)
3276 (get symbol 'saved-face)
3277 (get symbol 'face-defface-spec)
3278 ;; Attempt to construct it.
3279 (list (list t (custom-face-attributes-get
3280 symbol (selected-frame))))))
3281 (form (widget-get widget :custom-form))
3282 (indent (widget-get widget :indent))
3283 edit)
3284 ;; If the user has changed this face in some other way,
3285 ;; edit it as the user has specified it.
3286 (if (not (face-spec-match-p symbol spec (selected-frame)))
3287 (setq spec (list (list t (face-attr-construct symbol (selected-frame))))))
3288 (setq spec (custom-pre-filter-face-spec spec))
3289 (setq edit (widget-create-child-and-convert
3290 widget
3291 (cond ((and (eq form 'selected)
3292 (widget-apply custom-face-selected
3293 :match spec))
3294 (when indent (insert-char ?\ indent))
3295 'custom-face-selected)
3296 ((and (not (eq form 'lisp))
3297 (widget-apply custom-face-all
3298 :match spec))
3299 'custom-face-all)
3301 (when indent (insert-char ?\ indent))
3302 'sexp))
3303 :value spec))
3304 (custom-face-state-set widget)
3305 (push edit children)
3306 (widget-put widget :children children))
3307 (message "Creating face editor...done"))))))
3309 (defvar custom-face-menu
3310 `(("Set for Current Session" custom-face-set)
3311 ,@(when (or custom-file user-init-file)
3312 '(("Save for Future Sessions" custom-face-save)))
3313 ("Undo Edits" custom-redraw
3314 (lambda (widget)
3315 (memq (widget-get widget :custom-state) '(modified changed))))
3316 ("Reset to Saved" custom-face-reset-saved
3317 (lambda (widget)
3318 (or (get (widget-value widget) 'saved-face)
3319 (get (widget-value widget) 'saved-face-comment))))
3320 ,@(when (or custom-file user-init-file)
3321 '(("Erase Customization" custom-face-reset-standard
3322 (lambda (widget)
3323 (get (widget-value widget) 'face-defface-spec)))))
3324 ("---" ignore ignore)
3325 ("Add Comment" custom-comment-show custom-comment-invisible-p)
3326 ("---" ignore ignore)
3327 ("For Current Display" custom-face-edit-selected
3328 (lambda (widget)
3329 (not (eq (widget-get widget :custom-form) 'selected))))
3330 ("For All Kinds of Displays" custom-face-edit-all
3331 (lambda (widget)
3332 (not (eq (widget-get widget :custom-form) 'all))))
3333 ("Show Lisp Expression" custom-face-edit-lisp
3334 (lambda (widget)
3335 (not (eq (widget-get widget :custom-form) 'lisp)))))
3336 "Alist of actions for the `custom-face' widget.
3337 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3338 the menu entry, ACTION is the function to call on the widget when the
3339 menu is selected, and FILTER is a predicate which takes a `custom-face'
3340 widget as an argument, and returns non-nil if ACTION is valid on that
3341 widget. If FILTER is nil, ACTION is always valid.")
3343 (defun custom-face-edit-selected (widget)
3344 "Edit selected attributes of the value of WIDGET."
3345 (widget-put widget :custom-state 'unknown)
3346 (widget-put widget :custom-form 'selected)
3347 (custom-redraw widget))
3349 (defun custom-face-edit-all (widget)
3350 "Edit all attributes of the value of WIDGET."
3351 (widget-put widget :custom-state 'unknown)
3352 (widget-put widget :custom-form 'all)
3353 (custom-redraw widget))
3355 (defun custom-face-edit-lisp (widget)
3356 "Edit the Lisp representation of the value of WIDGET."
3357 (widget-put widget :custom-state 'unknown)
3358 (widget-put widget :custom-form 'lisp)
3359 (custom-redraw widget))
3361 (defun custom-face-state-set (widget)
3362 "Set the state of WIDGET."
3363 (let* ((symbol (widget-value widget))
3364 (comment (get symbol 'face-comment))
3365 tmp temp
3366 (state
3367 (cond ((progn
3368 (setq tmp (get symbol 'customized-face))
3369 (setq temp (get symbol 'customized-face-comment))
3370 (or tmp temp))
3371 (if (equal temp comment)
3372 'set
3373 'changed))
3374 ((progn
3375 (setq tmp (get symbol 'saved-face))
3376 (setq temp (get symbol 'saved-face-comment))
3377 (or tmp temp))
3378 (if (equal temp comment)
3379 (cond
3380 ((eq 'user (caar (get symbol 'theme-face)))
3381 'saved)
3382 ((eq 'changed (caar (get symbol 'theme-face)))
3383 'changed)
3384 (t 'themed))
3385 'changed))
3386 ((get symbol 'face-defface-spec)
3387 (if (equal comment nil)
3388 'standard
3389 'changed))
3391 'rogue))))
3392 ;; If the user called set-face-attribute to change the default
3393 ;; for new frames, this face is "set outside of Customize".
3394 (if (and (not (eq state 'rogue))
3395 (get symbol 'face-modified))
3396 (setq state 'changed))
3397 (widget-put widget :custom-state state)))
3399 (defun custom-face-action (widget &optional event)
3400 "Show the menu for `custom-face' WIDGET.
3401 Optional EVENT is the location for the menu."
3402 (if (eq (widget-get widget :custom-state) 'hidden)
3403 (custom-toggle-hide widget)
3404 (let* ((completion-ignore-case t)
3405 (symbol (widget-get widget :value))
3406 (answer (widget-choose (concat "Operation on "
3407 (custom-unlispify-tag-name symbol))
3408 (custom-menu-filter custom-face-menu
3409 widget)
3410 event)))
3411 (if answer
3412 (funcall answer widget)))))
3414 (defun custom-face-set (widget)
3415 "Make the face attributes in WIDGET take effect."
3416 (let* ((symbol (widget-value widget))
3417 (child (car (widget-get widget :children)))
3418 (value (custom-post-filter-face-spec (widget-value child)))
3419 (comment-widget (widget-get widget :comment-widget))
3420 (comment (widget-value comment-widget)))
3421 (when (equal comment "")
3422 (setq comment nil)
3423 ;; Make the comment invisible by hand if it's empty
3424 (custom-comment-hide comment-widget))
3425 (put symbol 'customized-face value)
3426 (if (face-spec-choose value)
3427 (face-spec-set symbol value)
3428 ;; face-set-spec ignores empty attribute lists, so just give it
3429 ;; something harmless instead.
3430 (face-spec-set symbol '((t :foreground unspecified))))
3431 (custom-push-theme 'theme-face symbol 'user 'set value)
3432 (put symbol 'customized-face-comment comment)
3433 (put symbol 'face-comment comment)
3434 (custom-face-state-set widget)
3435 (custom-redraw-magic widget)))
3437 (defun custom-face-save (widget)
3438 "Save in `.emacs' the face attributes in WIDGET."
3439 (let* ((symbol (widget-value widget))
3440 (child (car (widget-get widget :children)))
3441 (value (custom-post-filter-face-spec (widget-value child)))
3442 (comment-widget (widget-get widget :comment-widget))
3443 (comment (widget-value comment-widget)))
3444 (when (equal comment "")
3445 (setq comment nil)
3446 ;; Make the comment invisible by hand if it's empty
3447 (custom-comment-hide comment-widget))
3448 (custom-push-theme 'theme-face symbol 'user 'set value)
3449 (if (face-spec-choose value)
3450 (face-spec-set symbol value)
3451 ;; face-set-spec ignores empty attribute lists, so just give it
3452 ;; something harmless instead.
3453 (face-spec-set symbol '((t :foreground unspecified))))
3454 (unless (eq (widget-get widget :custom-state) 'standard)
3455 (put symbol 'saved-face value))
3456 (put symbol 'customized-face nil)
3457 (put symbol 'face-comment comment)
3458 (put symbol 'customized-face-comment nil)
3459 (put symbol 'saved-face-comment comment)
3460 (custom-save-all)
3461 (custom-face-state-set widget)
3462 (custom-redraw-magic widget)))
3464 ;; For backward compatibility.
3465 (define-obsolete-function-alias 'custom-face-save-command 'custom-face-save
3466 "22.1")
3468 (defun custom-face-reset-saved (widget)
3469 "Restore WIDGET to the face's default attributes."
3470 (let* ((symbol (widget-value widget))
3471 (child (car (widget-get widget :children)))
3472 (value (get symbol 'saved-face))
3473 (comment (get symbol 'saved-face-comment))
3474 (comment-widget (widget-get widget :comment-widget)))
3475 (unless (or value comment)
3476 (error "No saved value for this face"))
3477 (put symbol 'customized-face nil)
3478 (put symbol 'customized-face-comment nil)
3479 (custom-push-theme 'theme-face symbol 'user 'set value)
3480 (face-spec-set symbol value)
3481 (put symbol 'face-comment comment)
3482 (widget-value-set child value)
3483 ;; This call manages the comment visibility
3484 (widget-value-set comment-widget (or comment ""))
3485 (custom-face-state-set widget)
3486 (custom-redraw-magic widget)))
3488 (defun custom-face-standard-value (widget)
3489 (get (widget-value widget) 'face-defface-spec))
3491 (defun custom-face-reset-standard (widget)
3492 "Restore WIDGET to the face's standard attribute values.
3493 This operation eliminates any saved attributes for the face,
3494 restoring it to the state of a face that has never been customized."
3495 (let* ((symbol (widget-value widget))
3496 (child (car (widget-get widget :children)))
3497 (value (get symbol 'face-defface-spec))
3498 (comment-widget (widget-get widget :comment-widget)))
3499 (unless value
3500 (error "No standard setting for this face"))
3501 (put symbol 'customized-face nil)
3502 (put symbol 'customized-face-comment nil)
3503 (custom-push-theme 'theme-face symbol 'user 'reset)
3504 (custom-theme-recalc-face symbol)
3505 (when (or (get symbol 'saved-face) (get symbol 'saved-face-comment))
3506 (put symbol 'saved-face nil)
3507 (put symbol 'saved-face-comment nil)
3508 (custom-save-all))
3509 (put symbol 'face-comment nil)
3510 (widget-value-set child value)
3511 ;; This call manages the comment visibility
3512 (widget-value-set comment-widget "")
3513 (custom-face-state-set widget)
3514 (custom-redraw-magic widget)))
3516 ;;; The `face' Widget.
3518 (defvar widget-face-prompt-value-history nil
3519 "History of input to `widget-face-prompt-value'.")
3521 (define-widget 'face 'symbol
3522 "A Lisp face name (with sample)."
3523 :format "%{%t%}: (%{sample%}) %v"
3524 :tag "Face"
3525 :value 'default
3526 :sample-face-get 'widget-face-sample-face-get
3527 :notify 'widget-face-notify
3528 :match (lambda (widget value) (facep value))
3529 :complete-function (lambda ()
3530 (interactive)
3531 (lisp-complete-symbol 'facep))
3532 :prompt-match 'facep
3533 :prompt-history 'widget-face-prompt-value-history
3534 :validate (lambda (widget)
3535 (unless (facep (widget-value widget))
3536 (widget-put widget
3537 :error (format "Invalid face: %S"
3538 (widget-value widget)))
3539 widget)))
3541 (defun widget-face-sample-face-get (widget)
3542 (let ((value (widget-value widget)))
3543 (if (facep value)
3544 value
3545 'default)))
3547 (defun widget-face-notify (widget child &optional event)
3548 "Update the sample, and notify the parent."
3549 (overlay-put (widget-get widget :sample-overlay)
3550 'face (widget-apply widget :sample-face-get))
3551 (widget-default-notify widget child event))
3554 ;;; The `hook' Widget.
3556 (define-widget 'hook 'list
3557 "A emacs lisp hook"
3558 :value-to-internal (lambda (widget value)
3559 (if (and value (symbolp value))
3560 (list value)
3561 value))
3562 :match (lambda (widget value)
3563 (or (symbolp value)
3564 (widget-group-match widget value)))
3565 ;; Avoid adding undefined functions to the hook, especially for
3566 ;; things like `find-file-hook' or even more basic ones, to avoid
3567 ;; chaos.
3568 :set (lambda (symbol value)
3569 (dolist (elt value)
3570 (if (fboundp elt)
3571 (add-hook symbol elt))))
3572 :convert-widget 'custom-hook-convert-widget
3573 :tag "Hook")
3575 (defun custom-hook-convert-widget (widget)
3576 ;; Handle `:options'.
3577 (let* ((options (widget-get widget :options))
3578 (other `(editable-list :inline t
3579 :entry-format "%i %d%v"
3580 (function :format " %v")))
3581 (args (if options
3582 (list `(checklist :inline t
3583 ,@(mapcar (lambda (entry)
3584 `(function-item ,entry))
3585 options))
3586 other)
3587 (list other))))
3588 (widget-put widget :args args)
3589 widget))
3591 ;;; The `custom-group-link' Widget.
3593 (define-widget 'custom-group-link 'link
3594 "Show parent in other window when activated."
3595 :button-face 'custom-link
3596 :mouse-face 'highlight
3597 :pressed-face 'highlight
3598 :help-echo "Create customization buffer for this group."
3599 :action 'custom-group-link-action)
3601 (defun custom-group-link-action (widget &rest ignore)
3602 (customize-group (widget-value widget)))
3604 ;;; The `custom-group' Widget.
3606 (defcustom custom-group-tag-faces nil
3607 ;; In XEmacs, this ought to play games with font size.
3608 ;; Fixme: make it do so in Emacs.
3609 "Face used for group tags.
3610 The first member is used for level 1 groups, the second for level 2,
3611 and so forth. The remaining group tags are shown with `custom-group-tag'."
3612 :type '(repeat face)
3613 :group 'custom-faces)
3615 (defface custom-group-tag-1
3616 `((((class color)
3617 (background dark))
3618 (:foreground "pink" :weight bold :height 1.2 :inherit variable-pitch))
3619 (((min-colors 88) (class color)
3620 (background light))
3621 (:foreground "red1" :weight bold :height 1.2 :inherit variable-pitch))
3622 (((class color)
3623 (background light))
3624 (:foreground "red" :weight bold :height 1.2 :inherit variable-pitch))
3625 (t (:weight bold)))
3626 "Face used for group tags."
3627 :group 'custom-faces)
3628 ;; backward-compatibility alias
3629 (put 'custom-group-tag-face-1 'face-alias 'custom-group-tag-1)
3631 (defface custom-group-tag
3632 `((((class color)
3633 (background dark))
3634 (:foreground "light blue" :weight bold :height 1.2))
3635 (((min-colors 88) (class color)
3636 (background light))
3637 (:foreground "blue1" :weight bold :height 1.2))
3638 (((class color)
3639 (background light))
3640 (:foreground "blue" :weight bold :height 1.2))
3641 (t (:weight bold)))
3642 "Face used for low level group tags."
3643 :group 'custom-faces)
3644 ;; backward-compatibility alias
3645 (put 'custom-group-tag-face 'face-alias 'custom-group-tag)
3647 (define-widget 'custom-group 'custom
3648 "Customize group."
3649 :format "%v"
3650 :sample-face-get 'custom-group-sample-face-get
3651 :documentation-property 'group-documentation
3652 :help-echo "Set or reset all members of this group."
3653 :value-create 'custom-group-value-create
3654 :action 'custom-group-action
3655 :custom-category 'group
3656 :custom-set 'custom-group-set
3657 :custom-save 'custom-group-save
3658 :custom-reset-current 'custom-group-reset-current
3659 :custom-reset-saved 'custom-group-reset-saved
3660 :custom-reset-standard 'custom-group-reset-standard
3661 :custom-menu 'custom-group-menu-create)
3663 (defun custom-group-sample-face-get (widget)
3664 ;; Use :sample-face.
3665 (or (nth (1- (widget-get widget :custom-level)) custom-group-tag-faces)
3666 'custom-group-tag))
3668 (define-widget 'custom-group-visibility 'visibility
3669 "An indicator and manipulator for hidden group contents."
3670 :create 'custom-group-visibility-create)
3672 (defun custom-group-visibility-create (widget)
3673 (let ((visible (widget-value widget)))
3674 (if visible
3675 (insert "--------")))
3676 (widget-default-create widget))
3678 (defun custom-group-members (symbol groups-only)
3679 "Return SYMBOL's custom group members.
3680 If GROUPS-ONLY non-nil, return only those members that are groups."
3681 (if (not groups-only)
3682 (get symbol 'custom-group)
3683 (let (members)
3684 (dolist (entry (get symbol 'custom-group))
3685 (when (eq (nth 1 entry) 'custom-group)
3686 (push entry members)))
3687 (nreverse members))))
3689 (defun custom-group-value-create (widget)
3690 "Insert a customize group for WIDGET in the current buffer."
3691 (unless (eq (widget-get widget :custom-state) 'hidden)
3692 (custom-load-widget widget))
3693 (let* ((state (widget-get widget :custom-state))
3694 (level (widget-get widget :custom-level))
3695 ;; (indent (widget-get widget :indent))
3696 (prefix (widget-get widget :custom-prefix))
3697 (buttons (widget-get widget :buttons))
3698 (tag (widget-get widget :tag))
3699 (symbol (widget-value widget))
3700 (members (custom-group-members symbol
3701 (and (eq custom-buffer-style 'tree)
3702 custom-browse-only-groups))))
3703 (cond ((and (eq custom-buffer-style 'tree)
3704 (eq state 'hidden)
3705 (or members (custom-unloaded-widget-p widget)))
3706 (custom-browse-insert-prefix prefix)
3707 (push (widget-create-child-and-convert
3708 widget 'custom-browse-visibility
3709 ;; :tag-glyph "plus"
3710 :tag "+")
3711 buttons)
3712 (insert "-- ")
3713 ;; (widget-glyph-insert nil "-- " "horizontal")
3714 (push (widget-create-child-and-convert
3715 widget 'custom-browse-group-tag)
3716 buttons)
3717 (insert " " tag "\n")
3718 (widget-put widget :buttons buttons))
3719 ((and (eq custom-buffer-style 'tree)
3720 (zerop (length members)))
3721 (custom-browse-insert-prefix prefix)
3722 (insert "[ ]-- ")
3723 ;; (widget-glyph-insert nil "[ ]" "empty")
3724 ;; (widget-glyph-insert nil "-- " "horizontal")
3725 (push (widget-create-child-and-convert
3726 widget 'custom-browse-group-tag)
3727 buttons)
3728 (insert " " tag "\n")
3729 (widget-put widget :buttons buttons))
3730 ((eq custom-buffer-style 'tree)
3731 (custom-browse-insert-prefix prefix)
3732 (if (zerop (length members))
3733 (progn
3734 (custom-browse-insert-prefix prefix)
3735 (insert "[ ]-- ")
3736 ;; (widget-glyph-insert nil "[ ]" "empty")
3737 ;; (widget-glyph-insert nil "-- " "horizontal")
3738 (push (widget-create-child-and-convert
3739 widget 'custom-browse-group-tag)
3740 buttons)
3741 (insert " " tag "\n")
3742 (widget-put widget :buttons buttons))
3743 (push (widget-create-child-and-convert
3744 widget 'custom-browse-visibility
3745 ;; :tag-glyph "minus"
3746 :tag "-")
3747 buttons)
3748 (insert "-\\ ")
3749 ;; (widget-glyph-insert nil "-\\ " "top")
3750 (push (widget-create-child-and-convert
3751 widget 'custom-browse-group-tag)
3752 buttons)
3753 (insert " " tag "\n")
3754 (widget-put widget :buttons buttons)
3755 (message "Creating group...")
3756 (let* ((members (custom-sort-items members
3757 custom-browse-sort-alphabetically
3758 custom-browse-order-groups))
3759 (prefixes (widget-get widget :custom-prefixes))
3760 (custom-prefix-list (custom-prefix-add symbol prefixes))
3761 (extra-prefix (if (widget-get widget :custom-last)
3763 " | "))
3764 (prefix (concat prefix extra-prefix))
3765 children entry)
3766 (while members
3767 (setq entry (car members)
3768 members (cdr members))
3769 (push (widget-create-child-and-convert
3770 widget (nth 1 entry)
3771 :group widget
3772 :tag (custom-unlispify-tag-name (nth 0 entry))
3773 :custom-prefixes custom-prefix-list
3774 :custom-level (1+ level)
3775 :custom-last (null members)
3776 :value (nth 0 entry)
3777 :custom-prefix prefix)
3778 children))
3779 (widget-put widget :children (reverse children)))
3780 (message "Creating group...done")))
3781 ;; Nested style.
3782 ((eq state 'hidden)
3783 ;; Create level indicator.
3784 (unless (eq custom-buffer-style 'links)
3785 (insert-char ?\ (* custom-buffer-indent (1- level)))
3786 (insert "-- "))
3787 ;; Create tag.
3788 (let ((begin (point)))
3789 (insert tag)
3790 (widget-specify-sample widget begin (point)))
3791 (insert " group: ")
3792 ;; Create link/visibility indicator.
3793 (if (eq custom-buffer-style 'links)
3794 (push (widget-create-child-and-convert
3795 widget 'custom-group-link
3796 :tag "Go to Group"
3797 symbol)
3798 buttons)
3799 (push (widget-create-child-and-convert
3800 widget 'custom-group-visibility
3801 :help-echo "Show members of this group."
3802 :action 'custom-toggle-parent
3803 (not (eq state 'hidden)))
3804 buttons))
3805 (insert " \n")
3806 ;; Create magic button.
3807 (let ((magic (widget-create-child-and-convert
3808 widget 'custom-magic nil)))
3809 (widget-put widget :custom-magic magic)
3810 (push magic buttons))
3811 ;; Update buttons.
3812 (widget-put widget :buttons buttons)
3813 ;; Insert documentation.
3814 (if (and (eq custom-buffer-style 'links) (> level 1))
3815 (widget-put widget :documentation-indent 0))
3816 (widget-default-format-handler widget ?h))
3817 ;; Nested style.
3818 (t ;Visible.
3819 ;; Add parent groups references above the group.
3820 (if t ;;; This should test that the buffer
3821 ;;; was made to display a group.
3822 (when (eq level 1)
3823 (if (custom-add-parent-links widget
3824 "Go to parent group:")
3825 (insert "\n"))))
3826 ;; Create level indicator.
3827 (insert-char ?\ (* custom-buffer-indent (1- level)))
3828 (insert "/- ")
3829 ;; Create tag.
3830 (let ((start (point)))
3831 (insert tag)
3832 (widget-specify-sample widget start (point)))
3833 (insert " group: ")
3834 ;; Create visibility indicator.
3835 (unless (eq custom-buffer-style 'links)
3836 (insert "--------")
3837 (push (widget-create-child-and-convert
3838 widget 'visibility
3839 :help-echo "Hide members of this group."
3840 :action 'custom-toggle-parent
3841 (not (eq state 'hidden)))
3842 buttons)
3843 (insert " "))
3844 ;; Create more dashes.
3845 ;; Use 76 instead of 75 to compensate for the temporary "<"
3846 ;; added by `widget-insert'.
3847 (insert-char ?- (- 76 (current-column)
3848 (* custom-buffer-indent level)))
3849 (insert "\\\n")
3850 ;; Create magic button.
3851 (let ((magic (widget-create-child-and-convert
3852 widget 'custom-magic
3853 :indent 0
3854 nil)))
3855 (widget-put widget :custom-magic magic)
3856 (push magic buttons))
3857 ;; Update buttons.
3858 (widget-put widget :buttons buttons)
3859 ;; Insert documentation.
3860 (widget-default-format-handler widget ?h)
3861 ;; Parent groups.
3862 (if nil ;;; This should test that the buffer
3863 ;;; was not made to display a group.
3864 (when (eq level 1)
3865 (insert-char ?\ custom-buffer-indent)
3866 (custom-add-parent-links widget)))
3867 (custom-add-see-also widget
3868 (make-string (* custom-buffer-indent level)
3869 ?\ ))
3870 ;; Members.
3871 (message "Creating group...")
3872 (let* ((members (custom-sort-items members
3873 custom-buffer-sort-alphabetically
3874 custom-buffer-order-groups))
3875 (prefixes (widget-get widget :custom-prefixes))
3876 (custom-prefix-list (custom-prefix-add symbol prefixes))
3877 (length (length members))
3878 (count 0)
3879 (children (mapcar (lambda (entry)
3880 (widget-insert "\n")
3881 (message "\
3882 Creating group members... %2d%%"
3883 (/ (* 100.0 count) length))
3884 (setq count (1+ count))
3885 (prog1
3886 (widget-create-child-and-convert
3887 widget (nth 1 entry)
3888 :group widget
3889 :tag (custom-unlispify-tag-name
3890 (nth 0 entry))
3891 :custom-prefixes custom-prefix-list
3892 :custom-level (1+ level)
3893 :value (nth 0 entry))
3894 (unless (eq (preceding-char) ?\n)
3895 (widget-insert "\n"))))
3896 members)))
3897 (message "Creating group magic...")
3898 (mapc 'custom-magic-reset children)
3899 (message "Creating group state...")
3900 (widget-put widget :children children)
3901 (custom-group-state-update widget)
3902 (message "Creating group... done"))
3903 ;; End line
3904 (insert "\n")
3905 (insert-char ?\ (* custom-buffer-indent (1- level)))
3906 (insert "\\- " (widget-get widget :tag) " group end ")
3907 (insert-char ?- (- 75 (current-column) (* custom-buffer-indent level)))
3908 (insert "/\n")))))
3910 (defvar custom-group-menu
3911 `(("Set for Current Session" custom-group-set
3912 (lambda (widget)
3913 (eq (widget-get widget :custom-state) 'modified)))
3914 ,@(when (or custom-file user-init-file)
3915 '(("Save for Future Sessions" custom-group-save
3916 (lambda (widget)
3917 (memq (widget-get widget :custom-state) '(modified set))))))
3918 ("Undo Edits" custom-group-reset-current
3919 (lambda (widget)
3920 (memq (widget-get widget :custom-state) '(modified))))
3921 ("Reset to Saved" custom-group-reset-saved
3922 (lambda (widget)
3923 (memq (widget-get widget :custom-state) '(modified set))))
3924 ,@(when (or custom-file user-init-file)
3925 '(("Erase Customization" custom-group-reset-standard
3926 (lambda (widget)
3927 (memq (widget-get widget :custom-state) '(modified set saved)))))))
3928 "Alist of actions for the `custom-group' widget.
3929 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3930 the menu entry, ACTION is the function to call on the widget when the
3931 menu is selected, and FILTER is a predicate which takes a `custom-group'
3932 widget as an argument, and returns non-nil if ACTION is valid on that
3933 widget. If FILTER is nil, ACTION is always valid.")
3935 (defun custom-group-action (widget &optional event)
3936 "Show the menu for `custom-group' WIDGET.
3937 Optional EVENT is the location for the menu."
3938 (if (eq (widget-get widget :custom-state) 'hidden)
3939 (custom-toggle-hide widget)
3940 (let* ((completion-ignore-case t)
3941 (answer (widget-choose (concat "Operation on "
3942 (custom-unlispify-tag-name
3943 (widget-get widget :value)))
3944 (custom-menu-filter custom-group-menu
3945 widget)
3946 event)))
3947 (if answer
3948 (funcall answer widget)))))
3950 (defun custom-group-set (widget)
3951 "Set changes in all modified group members."
3952 (let ((children (widget-get widget :children)))
3953 (mapc (lambda (child)
3954 (when (eq (widget-get child :custom-state) 'modified)
3955 (widget-apply child :custom-set)))
3956 children )))
3958 (defun custom-group-save (widget)
3959 "Save all modified group members."
3960 (let ((children (widget-get widget :children)))
3961 (mapc (lambda (child)
3962 (when (memq (widget-get child :custom-state) '(modified set))
3963 (widget-apply child :custom-save)))
3964 children )))
3966 (defun custom-group-reset-current (widget)
3967 "Reset all modified group members."
3968 (let ((children (widget-get widget :children)))
3969 (mapc (lambda (child)
3970 (when (eq (widget-get child :custom-state) 'modified)
3971 (widget-apply child :custom-reset-current)))
3972 children )))
3974 (defun custom-group-reset-saved (widget)
3975 "Reset all modified or set group members."
3976 (let ((children (widget-get widget :children)))
3977 (mapc (lambda (child)
3978 (when (memq (widget-get child :custom-state) '(modified set))
3979 (widget-apply child :custom-reset-saved)))
3980 children )))
3982 (defun custom-group-reset-standard (widget)
3983 "Reset all modified, set, or saved group members."
3984 (let ((children (widget-get widget :children)))
3985 (mapc (lambda (child)
3986 (when (memq (widget-get child :custom-state)
3987 '(modified set saved))
3988 (widget-apply child :custom-reset-standard)))
3989 children )))
3991 (defun custom-group-state-update (widget)
3992 "Update magic."
3993 (unless (eq (widget-get widget :custom-state) 'hidden)
3994 (let* ((children (widget-get widget :children))
3995 (states (mapcar (lambda (child)
3996 (widget-get child :custom-state))
3997 children))
3998 (magics custom-magic-alist)
3999 (found 'standard))
4000 (while magics
4001 (let ((magic (car (car magics))))
4002 (if (and (not (eq magic 'hidden))
4003 (memq magic states))
4004 (setq found magic
4005 magics nil)
4006 (setq magics (cdr magics)))))
4007 (widget-put widget :custom-state found)))
4008 (custom-magic-reset widget))
4010 ;;; Reading and writing the custom file.
4012 ;;;###autoload
4013 (defcustom custom-file nil
4014 "File used for storing customization information.
4015 The default is nil, which means to use your init file
4016 as specified by `user-init-file'. If the value is not nil,
4017 it should be an absolute file name.
4019 You can set this option through Custom, if you carefully read the
4020 last paragraph below. However, usually it is simpler to write
4021 something like the following in your init file:
4023 \(setq custom-file \"~/.emacs-custom.el\")
4024 \(load custom-file)
4026 Note that both lines are necessary: the first line tells Custom to
4027 save all customizations in this file, but does not load it.
4029 When you change this variable outside Custom, look in the
4030 previous custom file \(usually your init file) for the
4031 forms `(custom-set-variables ...)' and `(custom-set-faces ...)',
4032 and copy them (whichever ones you find) to the new custom file.
4033 This will preserve your existing customizations.
4035 If you save this option using Custom, Custom will write all
4036 currently saved customizations, including the new one for this
4037 option itself, into the file you specify, overwriting any
4038 `custom-set-variables' and `custom-set-faces' forms already
4039 present in that file. It will not delete any customizations from
4040 the old custom file. You should do that manually if that is what you
4041 want. You also have to put something like `\(load \"CUSTOM-FILE\")
4042 in your init file, where CUSTOM-FILE is the actual name of the
4043 file. Otherwise, Emacs will not load the file when it starts up,
4044 and hence will not set `custom-file' to that file either."
4045 :type '(choice (const :tag "Your Emacs init file" nil)
4046 (file :format "%t:%v%d"
4047 :doc
4048 "Please read entire docstring below before setting \
4049 this through Custom.
4050 Click om \"More\" \(or position point there and press RETURN)
4051 if only the first line of the docstring is shown."))
4052 :group 'customize)
4054 (defun custom-file ()
4055 "Return the file name for saving customizations."
4056 (file-chase-links
4057 (or custom-file
4058 (let ((user-init-file user-init-file)
4059 (default-init-file
4060 (if (eq system-type 'ms-dos) "~/_emacs" "~/.emacs")))
4061 (when (null user-init-file)
4062 (if (or (file-exists-p default-init-file)
4063 (and (eq system-type 'windows-nt)
4064 (file-exists-p "~/_emacs")))
4065 ;; Started with -q, i.e. the file containing
4066 ;; Custom settings hasn't been read. Saving
4067 ;; settings there would overwrite other settings.
4068 (error "Saving settings from \"emacs -q\" would overwrite existing customizations"))
4069 (setq user-init-file default-init-file))
4070 user-init-file))))
4072 ;;;###autoload
4073 (defun custom-save-all ()
4074 "Save all customizations in `custom-file'."
4075 (let* ((filename (custom-file))
4076 (recentf-exclude (if recentf-mode
4077 (cons (concat "\\`"
4078 (regexp-quote (custom-file))
4079 "\\'")
4080 recentf-exclude)))
4081 (old-buffer (find-buffer-visiting filename)))
4082 (with-current-buffer (or old-buffer (find-file-noselect filename))
4083 (let ((inhibit-read-only t))
4084 (custom-save-variables)
4085 (custom-save-faces))
4086 (let ((file-precious-flag t))
4087 (save-buffer))
4088 (unless old-buffer
4089 (kill-buffer (current-buffer))))))
4091 ;;;###autoload
4092 (defun customize-save-customized ()
4093 "Save all user options which have been set in this session."
4094 (interactive)
4095 (mapatoms (lambda (symbol)
4096 (let ((face (get symbol 'customized-face))
4097 (value (get symbol 'customized-value))
4098 (face-comment (get symbol 'customized-face-comment))
4099 (variable-comment
4100 (get symbol 'customized-variable-comment)))
4101 (when face
4102 (put symbol 'saved-face face)
4103 (custom-push-theme 'theme-face symbol 'user 'set value)
4104 (put symbol 'customized-face nil))
4105 (when value
4106 (put symbol 'saved-value value)
4107 (custom-push-theme 'theme-value symbol 'user 'set value)
4108 (put symbol 'customized-value nil))
4109 (when variable-comment
4110 (put symbol 'saved-variable-comment variable-comment)
4111 (put symbol 'customized-variable-comment nil))
4112 (when face-comment
4113 (put symbol 'saved-face-comment face-comment)
4114 (put symbol 'customized-face-comment nil)))))
4115 ;; We really should update all custom buffers here.
4116 (custom-save-all))
4118 ;; Editing the custom file contents in a buffer.
4120 (defun custom-save-delete (symbol)
4121 "Delete all calls to SYMBOL from the contents of the current buffer.
4122 Leave point at the old location of the first such call,
4123 or (if there were none) at the end of the buffer.
4125 This function does not save the buffer."
4126 (goto-char (point-min))
4127 ;; Skip all whitespace and comments.
4128 (while (forward-comment 1))
4129 (or (eobp)
4130 (save-excursion (forward-sexp (buffer-size)))) ; Test for scan errors.
4131 (let (first)
4132 (catch 'found
4133 (while t ;; We exit this loop only via throw.
4134 ;; Skip all whitespace and comments.
4135 (while (forward-comment 1))
4136 (let ((start (point))
4137 (sexp (condition-case nil
4138 (read (current-buffer))
4139 (end-of-file (throw 'found nil)))))
4140 (when (and (listp sexp)
4141 (eq (car sexp) symbol))
4142 (delete-region start (point))
4143 (unless first
4144 (setq first (point)))))))
4145 (if first
4146 (goto-char first)
4147 ;; Move in front of local variables, otherwise long Custom
4148 ;; entries would make them ineffective.
4149 (let ((pos (point-max))
4150 (case-fold-search t))
4151 (save-excursion
4152 (goto-char (point-max))
4153 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
4154 'move)
4155 (when (search-forward "Local Variables:" nil t)
4156 (setq pos (line-beginning-position))))
4157 (goto-char pos)))))
4159 (defun custom-save-variables ()
4160 "Save all customized variables in `custom-file'."
4161 (save-excursion
4162 (custom-save-delete 'custom-set-variables)
4163 (let ((standard-output (current-buffer))
4164 (saved-list (make-list 1 0))
4165 sort-fold-case)
4166 ;; First create a sorted list of saved variables.
4167 (mapatoms
4168 (lambda (symbol)
4169 (if (and (get symbol 'saved-value)
4170 ;; ignore theme values
4171 (or (null (get symbol 'theme-value))
4172 (eq 'user (caar (get symbol 'theme-value)))))
4173 (nconc saved-list (list symbol)))))
4174 (setq saved-list (sort (cdr saved-list) 'string<))
4175 (unless (bolp)
4176 (princ "\n"))
4177 (princ "(custom-set-variables
4178 ;; custom-set-variables was added by Custom.
4179 ;; If you edit it by hand, you could mess it up, so be careful.
4180 ;; Your init file should contain only one such instance.
4181 ;; If there is more than one, they won't work right.\n")
4182 (dolist (symbol saved-list)
4183 (let ((spec (car-safe (get symbol 'theme-value)))
4184 (value (get symbol 'saved-value))
4185 (requests (get symbol 'custom-requests))
4186 (now (not (or (custom-variable-p symbol)
4187 (and (not (boundp symbol))
4188 (not (eq (get symbol 'force-value)
4189 'rogue))))))
4190 (comment (get symbol 'saved-variable-comment)))
4191 ;; Check `requests'.
4192 (dolist (request requests)
4193 (when (and (symbolp request) (not (featurep request)))
4194 (message "Unknown requested feature: %s" request)
4195 (setq requests (delq request requests))))
4196 (when (or (and spec (eq (car spec) 'user))
4197 comment
4198 (and (null spec) (get symbol 'saved-value)))
4199 (unless (bolp)
4200 (princ "\n"))
4201 (princ " '(")
4202 (prin1 symbol)
4203 (princ " ")
4204 (prin1 (car value))
4205 (when (or now requests comment)
4206 (princ " ")
4207 (prin1 now)
4208 (when (or requests comment)
4209 (princ " ")
4210 (prin1 requests)
4211 (when comment
4212 (princ " ")
4213 (prin1 comment))))
4214 (princ ")"))))
4215 (if (bolp)
4216 (princ " "))
4217 (princ ")")
4218 (unless (looking-at "\n")
4219 (princ "\n")))))
4221 (defun custom-save-faces ()
4222 "Save all customized faces in `custom-file'."
4223 (save-excursion
4224 (custom-save-delete 'custom-reset-faces)
4225 (custom-save-delete 'custom-set-faces)
4226 (let ((standard-output (current-buffer))
4227 (saved-list (make-list 1 0))
4228 sort-fold-case)
4229 ;; First create a sorted list of saved faces.
4230 (mapatoms
4231 (lambda (symbol)
4232 (if (and (get symbol 'saved-face)
4233 (eq 'user (car (car-safe (get symbol 'theme-face)))))
4234 (nconc saved-list (list symbol)))))
4235 (setq saved-list (sort (cdr saved-list) 'string<))
4236 ;; The default face must be first, since it affects the others.
4237 (if (memq 'default saved-list)
4238 (setq saved-list (cons 'default (delq 'default saved-list))))
4239 (unless (bolp)
4240 (princ "\n"))
4241 (princ "(custom-set-faces
4242 ;; custom-set-faces was added by Custom.
4243 ;; If you edit it by hand, you could mess it up, so be careful.
4244 ;; Your init file should contain only one such instance.
4245 ;; If there is more than one, they won't work right.\n")
4246 (dolist (symbol saved-list)
4247 (let ((spec (car-safe (get symbol 'theme-face)))
4248 (value (get symbol 'saved-face))
4249 (now (not (or (get symbol 'face-defface-spec)
4250 (and (not (custom-facep symbol))
4251 (not (get symbol 'force-face))))))
4252 (comment (get symbol 'saved-face-comment)))
4253 (when (or (and spec (eq (nth 0 spec) 'user))
4254 comment
4255 (and (null spec) (get symbol 'saved-face)))
4256 ;; Don't print default face here.
4257 (unless (bolp)
4258 (princ "\n"))
4259 (princ " '(")
4260 (prin1 symbol)
4261 (princ " ")
4262 (prin1 value)
4263 (when (or now comment)
4264 (princ " ")
4265 (prin1 now)
4266 (when comment
4267 (princ " ")
4268 (prin1 comment)))
4269 (princ ")"))))
4270 (if (bolp)
4271 (princ " "))
4272 (princ ")")
4273 (unless (looking-at "\n")
4274 (princ "\n")))))
4276 ;;; The Customize Menu.
4278 ;;; Menu support
4280 (defcustom custom-menu-nesting 2
4281 "Maximum nesting in custom menus."
4282 :type 'integer
4283 :group 'custom-menu)
4285 (defun custom-face-menu-create (widget symbol)
4286 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
4287 (vector (custom-unlispify-menu-entry symbol)
4288 `(customize-face ',symbol)
4291 (defun custom-variable-menu-create (widget symbol)
4292 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
4293 (let ((type (get symbol 'custom-type)))
4294 (unless (listp type)
4295 (setq type (list type)))
4296 (if (and type (widget-get type :custom-menu))
4297 (widget-apply type :custom-menu symbol)
4298 (vector (custom-unlispify-menu-entry symbol)
4299 `(customize-variable ',symbol)
4300 t))))
4302 ;; Add checkboxes to boolean variable entries.
4303 (widget-put (get 'boolean 'widget-type)
4304 :custom-menu (lambda (widget symbol)
4305 (vector (custom-unlispify-menu-entry symbol)
4306 `(customize-variable ',symbol)
4307 ':style 'toggle
4308 ':selected symbol)))
4310 (defun custom-group-menu-create (widget symbol)
4311 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
4312 `( ,(custom-unlispify-menu-entry symbol t)
4313 :filter (lambda (&rest junk)
4314 (let ((menu (custom-menu-create ',symbol)))
4315 (if (consp menu) (cdr menu) menu)))))
4317 ;;;###autoload
4318 (defun custom-menu-create (symbol)
4319 "Create menu for customization group SYMBOL.
4320 The menu is in a format applicable to `easy-menu-define'."
4321 (let* ((item (vector (custom-unlispify-menu-entry symbol)
4322 `(customize-group ',symbol)
4323 t)))
4324 (if (and (or (not (boundp 'custom-menu-nesting))
4325 (>= custom-menu-nesting 0))
4326 (progn
4327 (custom-load-symbol symbol)
4328 (< (length (get symbol 'custom-group)) widget-menu-max-size)))
4329 (let ((custom-prefix-list (custom-prefix-add symbol
4330 custom-prefix-list))
4331 (members (custom-sort-items (get symbol 'custom-group)
4332 custom-menu-sort-alphabetically
4333 custom-menu-order-groups)))
4334 `(,(custom-unlispify-menu-entry symbol t)
4335 ,item
4336 "--"
4337 ,@(mapcar (lambda (entry)
4338 (widget-apply (if (listp (nth 1 entry))
4339 (nth 1 entry)
4340 (list (nth 1 entry)))
4341 :custom-menu (nth 0 entry)))
4342 members)))
4343 item)))
4345 ;;;###autoload
4346 (defun customize-menu-create (symbol &optional name)
4347 "Return a customize menu for customization group SYMBOL.
4348 If optional NAME is given, use that as the name of the menu.
4349 Otherwise the menu will be named `Customize'.
4350 The format is suitable for use with `easy-menu-define'."
4351 (unless name
4352 (setq name "Customize"))
4353 `(,name
4354 :filter (lambda (&rest junk)
4355 (let ((menu (custom-menu-create ',symbol)))
4356 (if (consp menu) (cdr menu) menu)))))
4358 ;;; The Custom Mode.
4360 (defvar custom-mode-map
4361 ;; This keymap should be dense, but a dense keymap would prevent inheriting
4362 ;; "\r" bindings from the parent map.
4363 ;; Actually, this misfeature of dense keymaps was fixed on 2001-11-26.
4364 (let ((map (make-keymap)))
4365 (set-keymap-parent map widget-keymap)
4366 (suppress-keymap map)
4367 (define-key map " " 'scroll-up)
4368 (define-key map "\177" 'scroll-down)
4369 (define-key map "\C-c\C-c" 'Custom-set)
4370 (define-key map "\C-x\C-s" 'Custom-save)
4371 (define-key map "q" 'Custom-buffer-done)
4372 (define-key map "u" 'Custom-goto-parent)
4373 (define-key map "n" 'widget-forward)
4374 (define-key map "p" 'widget-backward)
4375 map)
4376 "Keymap for `custom-mode'.")
4378 (easy-menu-define Custom-mode-menu
4379 custom-mode-map
4380 "Menu used in customization buffers."
4381 `("Custom"
4382 ,(customize-menu-create 'customize)
4383 ["Set" Custom-set t]
4384 ["Save" Custom-save t]
4385 ["Undo Edits" Custom-reset-current t]
4386 ["Reset to Saved" Custom-reset-saved t]
4387 ["Erase Customization" Custom-reset-standard t]
4388 ["Info" (info "(emacs)Easy Customization") t]))
4390 (defvar custom-field-keymap
4391 (let ((map (copy-keymap widget-field-keymap)))
4392 (define-key map "\C-c\C-c" 'Custom-set)
4393 (define-key map "\C-x\C-s" 'Custom-save)
4394 map)
4395 "Keymap used inside editable fields in customization buffers.")
4397 (widget-put (get 'editable-field 'widget-type) :keymap custom-field-keymap)
4399 (defun Custom-goto-parent ()
4400 "Go to the parent group listed at the top of this buffer.
4401 If several parents are listed, go to the first of them."
4402 (interactive)
4403 (save-excursion
4404 (goto-char (point-min))
4405 (if (search-forward "\nGo to parent group: " nil t)
4406 (let* ((button (get-char-property (point) 'button))
4407 (parent (downcase (widget-get button :tag))))
4408 (customize-group parent)))))
4410 (defcustom custom-mode-hook nil
4411 "Hook called when entering Custom mode."
4412 :type 'hook
4413 :group 'custom-buffer )
4415 (defun custom-state-buffer-message (widget)
4416 (if (eq (widget-get (widget-get widget :parent) :custom-state) 'modified)
4417 (message "To install your edits, invoke [State] and choose the Set operation")))
4419 (defun custom-mode ()
4420 "Major mode for editing customization buffers.
4422 The following commands are available:
4424 \\<widget-keymap>\
4425 Move to next button, link or editable field. \\[widget-forward]
4426 Move to previous button, link or editable field. \\[advertised-widget-backward]
4427 \\<custom-field-keymap>\
4428 Complete content of editable text field. \\[widget-complete]
4429 \\<custom-mode-map>\
4430 Invoke button under the mouse pointer. \\[widget-button-click]
4431 Invoke button under point. \\[widget-button-press]
4432 Set all options from current text. \\[Custom-set]
4433 Make values in current text permanent. \\[Custom-save]
4434 Make text match actual option values. \\[Custom-reset-current]
4435 Reset options to permanent settings. \\[Custom-reset-saved]
4436 Erase customizations; set options
4437 and buffer text to the standard values. \\[Custom-reset-standard]
4439 Entry to this mode calls the value of `custom-mode-hook'
4440 if that value is non-nil."
4441 (kill-all-local-variables)
4442 (setq major-mode 'custom-mode
4443 mode-name "Custom")
4444 (use-local-map custom-mode-map)
4445 (easy-menu-add Custom-mode-menu)
4446 (make-local-variable 'custom-options)
4447 (make-local-variable 'custom-local-buffer)
4448 (make-local-variable 'widget-documentation-face)
4449 (setq widget-documentation-face 'custom-documentation)
4450 (make-local-variable 'widget-button-face)
4451 (setq widget-button-face custom-button)
4452 (set (make-local-variable 'widget-button-pressed-face) custom-button-pressed)
4453 (set (make-local-variable 'widget-mouse-face) custom-button-mouse)
4455 ;; When possible, use relief for buttons, not bracketing. This test
4456 ;; may not be optimal.
4457 (when custom-raised-buttons
4458 (set (make-local-variable 'widget-push-button-prefix) "")
4459 (set (make-local-variable 'widget-push-button-suffix) "")
4460 (set (make-local-variable 'widget-link-prefix) "")
4461 (set (make-local-variable 'widget-link-suffix) ""))
4462 (add-hook 'widget-edit-functions 'custom-state-buffer-message nil t)
4463 (run-mode-hooks 'custom-mode-hook))
4465 (put 'custom-mode 'mode-class 'special)
4467 (add-to-list
4468 'debug-ignored-errors
4469 "^No user options have changed defaults in recent Emacs versions$")
4471 ;;; The End.
4473 (provide 'cus-edit)
4475 ;; arch-tag: 64533aa4-1b1a-48c3-8812-f9dc718e8a6f
4476 ;;; cus-edit.el ends here