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