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