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