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