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