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