]> code.delx.au - gnu-emacs/blob - lisp/cus-edit.el
Merge from emacs--rel--22
[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 2, or (at your option)
15 ;; any later version.
16
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
26
27 ;;; Commentary:
28 ;;
29 ;; This file implements the code to create and edit customize buffers.
30 ;;
31 ;; See `custom.el'.
32
33 ;; No commands should have names starting with `custom-' because
34 ;; that interferes with completion. Use `customize-' for commands
35 ;; that the user will run with M-x, and `Custom-' for interactive commands.
36
37 ;; The identity of a customize option is represented by a Lisp symbol.
38 ;; The following values are associated with an option.
39
40 ;; 0. The current value.
41
42 ;; This is the value of the option as seen by "the rest of Emacs".
43
44 ;; Usually extracted by 'default-value', but can be extracted with
45 ;; different means if the option symbol has the 'custom-get'
46 ;; property. Similarly, set-default (or the 'custom-set' property)
47 ;; can set it.
48
49 ;; 1. The widget value.
50
51 ;; This is the value shown in the widget in a customize buffer.
52
53 ;; 2. The customized value.
54
55 ;; This is the last value given to the option through customize.
56
57 ;; It is stored in the 'customized-value' property of the option, in a
58 ;; cons-cell whose car evaluates to the customized value.
59
60 ;; 3. The saved value.
61
62 ;; This is last value saved from customize.
63
64 ;; It is stored in the 'saved-value' property of the option, in a
65 ;; cons-cell whose car evaluates to the saved value.
66
67 ;; 4. The standard value.
68
69 ;; This is the value given in the 'defcustom' declaration.
70
71 ;; It is stored in the 'standard-value' property of the option, in a
72 ;; cons-cell whose car evaluates to the standard value.
73
74 ;; 5. The "think" value.
75
76 ;; This is what customize thinks the current value should be.
77
78 ;; This is the customized value, if any such value exists, otherwise
79 ;; the saved value, if that exists, and as a last resort the standard
80 ;; value.
81
82 ;; The reason for storing values unevaluated: This is so you can have
83 ;; values that depend on the environment. For example, you can have a
84 ;; variable that has one value when Emacs is running under a window
85 ;; system, and another value on a tty. Since the evaluation is only done
86 ;; when the variable is first initialized, this is only relevant for the
87 ;; saved (and standard) values, but affect others values for
88 ;; compatibility.
89
90 ;; You can see (and modify and save) this unevaluated value by selecting
91 ;; "Show Saved Lisp Expression" from the Lisp interface. This will
92 ;; give you the unevaluated saved value, if any, otherwise the
93 ;; unevaluated standard value.
94
95 ;; The possible states for a customize widget are:
96
97 ;; 0. unknown
98
99 ;; The state has not been determined yet.
100
101 ;; 1. modified
102
103 ;; The widget value is different from the current value.
104
105 ;; 2. changed
106
107 ;; The current value is different from the "think" value.
108
109 ;; 3. set
110
111 ;; The "think" value is the customized value.
112
113 ;; 4. saved
114
115 ;; The "think" value is the saved value.
116
117 ;; 5. standard
118
119 ;; The "think" value is the standard value.
120
121 ;; 6. rogue
122
123 ;; There is no standard value. This means that the variable was
124 ;; not defined with defcustom, nor handled in cus-start.el. Most
125 ;; standard interactive Custom commands do not let you create a
126 ;; Custom buffer containing such variables. However, such Custom
127 ;; buffers can be created, for instance, by calling
128 ;; `customize-apropos' with a prefix arg or by calling
129 ;; `customize-option' non-interactively.
130
131 ;; 7. hidden
132
133 ;; There is no widget value.
134
135 ;; 8. mismatch
136
137 ;; The widget value is not valid member of the :type specified for the
138 ;; option.
139
140 ;;; Code:
141
142 (require 'cus-face)
143 (require 'wid-edit)
144 (eval-when-compile
145 (defvar custom-versions-load-alist) ; from cus-load
146 (defvar recentf-exclude)) ; from recentf.el
147
148 (condition-case nil
149 (require 'cus-load)
150 (error nil))
151
152 (condition-case nil
153 (require 'cus-start)
154 (error nil))
155
156 (put 'custom-define-hook 'custom-type 'hook)
157 (put 'custom-define-hook 'standard-value '(nil))
158 (custom-add-to-group 'customize 'custom-define-hook 'custom-variable)
159
160 ;;; Customization Groups.
161
162 (defgroup emacs nil
163 "Customization of the One True Editor."
164 :link '(custom-manual "(emacs)Top"))
165
166 ;; Most of these groups are stolen from `finder.el',
167 (defgroup editing nil
168 "Basic text editing facilities."
169 :group 'emacs)
170
171 (defgroup abbrev nil
172 "Abbreviation handling, typing shortcuts, macros."
173 :tag "Abbreviations"
174 :group 'editing)
175
176 (defgroup matching nil
177 "Various sorts of searching and matching."
178 :group 'editing)
179
180 (defgroup emulations nil
181 "Emulations of other editors."
182 :link '(custom-manual "(emacs)Emulation")
183 :group 'editing)
184
185 (defgroup mouse nil
186 "Mouse support."
187 :group 'editing)
188
189 (defgroup outlines nil
190 "Support for hierarchical outlining."
191 :group 'editing)
192
193 (defgroup external nil
194 "Interfacing to external utilities."
195 :group 'emacs)
196
197 (defgroup processes nil
198 "Process, subshell, compilation, and job control support."
199 :group 'external
200 :group 'development)
201
202 (defgroup convenience nil
203 "Convenience features for faster editing."
204 :group 'emacs)
205
206 (defgroup programming nil
207 "Support for programming in other languages."
208 :group 'emacs)
209
210 (defgroup languages nil
211 "Specialized modes for editing programming languages."
212 :group 'programming)
213
214 (defgroup lisp nil
215 "Lisp support, including Emacs Lisp."
216 :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
217 :group 'languages
218 :group 'development)
219
220 (defgroup c nil
221 "Support for the C language and related languages."
222 :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
223 :link '(custom-manual "(ccmode)")
224 :group 'languages)
225
226 (defgroup tools nil
227 "Programming tools."
228 :group 'programming)
229
230 (defgroup oop nil
231 "Support for object-oriented programming."
232 :group 'programming)
233
234 (defgroup applications nil
235 "Applications written in Emacs."
236 :group 'emacs)
237
238 (defgroup calendar nil
239 "Calendar and time management support."
240 :group 'applications)
241
242 (defgroup mail nil
243 "Modes for electronic-mail handling."
244 :group 'applications)
245
246 (defgroup news nil
247 "Support for netnews reading and posting."
248 :link '(custom-manual "(gnus)")
249 :group 'applications)
250
251 (defgroup games nil
252 "Games, jokes and amusements."
253 :group 'applications)
254
255 (defgroup development nil
256 "Support for further development of Emacs."
257 :group 'emacs)
258
259 (defgroup docs nil
260 "Support for Emacs documentation."
261 :group 'development)
262
263 (defgroup extensions nil
264 "Emacs Lisp language extensions."
265 :group 'development)
266
267 (defgroup internal nil
268 "Code for Emacs internals, build process, defaults."
269 :group 'development)
270
271 (defgroup maint nil
272 "Maintenance aids for the Emacs development group."
273 :tag "Maintenance"
274 :group 'development)
275
276 (defgroup environment nil
277 "Fitting Emacs with its environment."
278 :group 'emacs)
279
280 (defgroup comm nil
281 "Communications, networking, remote access to files."
282 :tag "Communication"
283 :group 'environment)
284
285 (defgroup hardware nil
286 "Support for interfacing with exotic hardware."
287 :group 'environment)
288
289 (defgroup terminals nil
290 "Support for terminal types."
291 :group 'environment)
292
293 (defgroup unix nil
294 "Front-ends/assistants for, or emulators of, UNIX features."
295 :group 'environment)
296
297 (defgroup vms nil
298 "Support code for vms."
299 :group 'environment)
300
301 (defgroup i18n nil
302 "Internationalization and alternate character-set support."
303 :link '(custom-manual "(emacs)International")
304 :group 'environment
305 :group 'editing)
306
307 (defgroup x nil
308 "The X Window system."
309 :group 'environment)
310
311 (defgroup frames nil
312 "Support for Emacs frames and window systems."
313 :group 'environment)
314
315 (defgroup data nil
316 "Support editing files of data."
317 :group 'emacs)
318
319 (defgroup files nil
320 "Support editing files."
321 :group 'emacs)
322
323 (defgroup wp nil
324 "Word processing."
325 :group 'emacs)
326
327 (defgroup tex nil
328 "Code related to the TeX formatter."
329 :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
330 :group 'wp)
331
332 (defgroup faces nil
333 "Support for multiple fonts."
334 :group 'emacs)
335
336 (defgroup hypermedia nil
337 "Support for links between text or other media types."
338 :group 'emacs)
339
340 (defgroup help nil
341 "Support for on-line help systems."
342 :group 'emacs)
343
344 (defgroup multimedia nil
345 "Non-textual support, specifically images and sound."
346 :group 'emacs)
347
348 (defgroup local nil
349 "Code local to your site."
350 :group 'emacs)
351
352 (defgroup customize '((widgets custom-group))
353 "Customization of the Customization support."
354 :prefix "custom-"
355 :group 'help)
356
357 (defgroup custom-faces nil
358 "Faces used by customize."
359 :group 'customize
360 :group 'faces)
361
362 (defgroup custom-browse nil
363 "Control customize browser."
364 :prefix "custom-"
365 :group 'customize)
366
367 (defgroup custom-buffer nil
368 "Control customize buffers."
369 :prefix "custom-"
370 :group 'customize)
371
372 (defgroup custom-menu nil
373 "Control customize menus."
374 :prefix "custom-"
375 :group 'customize)
376
377 (defgroup abbrev-mode nil
378 "Word abbreviations mode."
379 :link '(custom-manual "(emacs)Abbrevs")
380 :group 'abbrev)
381
382 (defgroup alloc nil
383 "Storage allocation and gc for GNU Emacs Lisp interpreter."
384 :tag "Storage Allocation"
385 :group 'internal)
386
387 (defgroup undo nil
388 "Undoing changes in buffers."
389 :link '(custom-manual "(emacs)Undo")
390 :group 'editing)
391
392 (defgroup mode-line nil
393 "Content of the modeline."
394 :group 'environment)
395
396 (defgroup editing-basics nil
397 "Most basic editing facilities."
398 :group 'editing)
399
400 (defgroup display nil
401 "How characters are displayed in buffers."
402 :group 'environment)
403
404 (defgroup execute nil
405 "Executing external commands."
406 :group 'processes)
407
408 (defgroup installation nil
409 "The Emacs installation."
410 :group 'environment)
411
412 (defgroup dired nil
413 "Directory editing."
414 :group 'environment)
415
416 (defgroup limits nil
417 "Internal Emacs limits."
418 :group 'internal)
419
420 (defgroup debug nil
421 "Debugging Emacs itself."
422 :group 'development)
423
424 (defgroup minibuffer nil
425 "Controlling the behavior of the minibuffer."
426 :link '(custom-manual "(emacs)Minibuffer")
427 :group 'environment)
428
429 (defgroup keyboard nil
430 "Input from the keyboard."
431 :group 'environment)
432
433 (defgroup mouse nil
434 "Input from the mouse."
435 :group 'environment)
436
437 (defgroup menu nil
438 "Input from the menus."
439 :group 'environment)
440
441 (defgroup dnd nil
442 "Handling data from drag and drop."
443 :group 'environment)
444
445 (defgroup auto-save nil
446 "Preventing accidental loss of data."
447 :group 'files)
448
449 (defgroup processes-basics nil
450 "Basic stuff dealing with processes."
451 :group 'processes)
452
453 (defgroup mule nil
454 "MULE Emacs internationalization."
455 :group 'i18n)
456
457 (defgroup windows nil
458 "Windows within a frame."
459 :link '(custom-manual "(emacs)Windows")
460 :group 'environment)
461
462 (defgroup mac nil
463 "Mac specific features."
464 :link '(custom-manual "(emacs)Mac OS")
465 :group 'environment
466 :version "22.1"
467 :prefix "mac-")
468
469 ;;; Custom mode keymaps
470
471 (defvar custom-mode-map
472 ;; This keymap should be dense, but a dense keymap would prevent inheriting
473 ;; "\r" bindings from the parent map.
474 ;; Actually, this misfeature of dense keymaps was fixed on 2001-11-26.
475 (let ((map (make-keymap)))
476 (set-keymap-parent map widget-keymap)
477 (define-key map [remap self-insert-command] 'Custom-no-edit)
478 (define-key map "\^m" 'Custom-newline)
479 (define-key map " " 'scroll-up)
480 (define-key map "\177" 'scroll-down)
481 (define-key map "\C-c\C-c" 'Custom-set)
482 (define-key map "\C-x\C-s" 'Custom-save)
483 (define-key map "q" 'Custom-buffer-done)
484 (define-key map "u" 'Custom-goto-parent)
485 (define-key map "n" 'widget-forward)
486 (define-key map "p" 'widget-backward)
487 map)
488 "Keymap for `custom-mode'.")
489
490 (defvar custom-mode-link-map
491 (let ((map (make-keymap)))
492 (set-keymap-parent map custom-mode-map)
493 (define-key map [down-mouse-2] nil)
494 (define-key map [down-mouse-1] 'mouse-drag-region)
495 (define-key map [mouse-2] 'widget-move-and-invoke)
496 map)
497 "Local keymap for links in `custom-mode'.")
498
499
500 ;;; Utilities.
501
502 (defun custom-split-regexp-maybe (regexp)
503 "If REGEXP is a string, split it to a list at `\\|'.
504 You can get the original back from the result with:
505 (mapconcat 'identity result \"\\|\")
506
507 IF REGEXP is not a string, return it unchanged."
508 (if (stringp regexp)
509 (split-string regexp "\\\\|")
510 regexp))
511
512 (defun custom-variable-prompt ()
513 "Prompt for a custom variable, defaulting to the variable at point.
514 Return a list suitable for use in `interactive'."
515 (let* ((v (variable-at-point))
516 (default (and (symbolp v) (custom-variable-p v) (symbol-name v)))
517 (enable-recursive-minibuffers t)
518 val)
519 (setq val (completing-read
520 (if default (format "Customize variable (default %s): " default)
521 "Customize variable: ")
522 obarray 'custom-variable-p t nil nil default))
523 (list (if (equal val "")
524 (if (symbolp v) v nil)
525 (intern val)))))
526
527 (defun custom-menu-filter (menu widget)
528 "Convert MENU to the form used by `widget-choose'.
529 MENU should be in the same format as `custom-variable-menu'.
530 WIDGET is the widget to apply the filter entries of MENU on."
531 (let ((result nil)
532 current name action filter)
533 (while menu
534 (setq current (car menu)
535 name (nth 0 current)
536 action (nth 1 current)
537 filter (nth 2 current)
538 menu (cdr menu))
539 (if (or (null filter) (funcall filter widget))
540 (push (cons name action) result)
541 (push name result)))
542 (nreverse result)))
543
544 ;;; Unlispify.
545
546 (defvar custom-prefix-list nil
547 "List of prefixes that should be ignored by `custom-unlispify'.")
548
549 (defcustom custom-unlispify-menu-entries t
550 "Display menu entries as words instead of symbols if non-nil."
551 :group 'custom-menu
552 :type 'boolean)
553
554 (defcustom custom-unlispify-remove-prefixes nil
555 "Non-nil means remove group prefixes from option names in buffer."
556 :group 'custom-menu
557 :group 'custom-buffer
558 :type 'boolean)
559
560 (defun custom-unlispify-menu-entry (symbol &optional no-suffix)
561 "Convert SYMBOL into a menu entry."
562 (cond ((not custom-unlispify-menu-entries)
563 (symbol-name symbol))
564 ((get symbol 'custom-tag)
565 (if no-suffix
566 (get symbol 'custom-tag)
567 (concat (get symbol 'custom-tag) "...")))
568 (t
569 (with-current-buffer (get-buffer-create " *Custom-Work*")
570 (erase-buffer)
571 (princ symbol (current-buffer))
572 (goto-char (point-min))
573 ;; FIXME: Boolean variables are not predicates, so they shouldn't
574 ;; end with `-p'. -stef
575 ;; (when (and (eq (get symbol 'custom-type) 'boolean)
576 ;; (re-search-forward "-p\\'" nil t))
577 ;; (replace-match "" t t)
578 ;; (goto-char (point-min)))
579 (if custom-unlispify-remove-prefixes
580 (let ((prefixes custom-prefix-list)
581 prefix)
582 (while prefixes
583 (setq prefix (car prefixes))
584 (if (search-forward prefix (+ (point) (length prefix)) t)
585 (progn
586 (setq prefixes nil)
587 (delete-region (point-min) (point)))
588 (setq prefixes (cdr prefixes))))))
589 (subst-char-in-region (point-min) (point-max) ?- ?\ t)
590 (capitalize-region (point-min) (point-max))
591 (unless no-suffix
592 (goto-char (point-max))
593 (insert "..."))
594 (buffer-string)))))
595
596 (defcustom custom-unlispify-tag-names t
597 "Display tag names as words instead of symbols if non-nil."
598 :group 'custom-buffer
599 :type 'boolean)
600
601 (defun custom-unlispify-tag-name (symbol)
602 "Convert SYMBOL into a menu entry."
603 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names))
604 (custom-unlispify-menu-entry symbol t)))
605
606 (defun custom-prefix-add (symbol prefixes)
607 "Add SYMBOL to list of ignored PREFIXES."
608 (cons (or (get symbol 'custom-prefix)
609 (concat (symbol-name symbol) "-"))
610 prefixes))
611
612 ;;; Guess.
613
614 (defcustom custom-guess-name-alist
615 '(("-p\\'" boolean)
616 ("-flag\\'" boolean)
617 ("-hook\\'" hook)
618 ("-face\\'" face)
619 ("-file\\'" file)
620 ("-function\\'" function)
621 ("-functions\\'" (repeat function))
622 ("-list\\'" (repeat sexp))
623 ("-alist\\'" (repeat (cons sexp sexp))))
624 "Alist of (MATCH TYPE).
625
626 MATCH should be a regexp matching the name of a symbol, and TYPE should
627 be a widget suitable for editing the value of that symbol. The TYPE
628 of the first entry where MATCH matches the name of the symbol will be
629 used.
630
631 This is used for guessing the type of variables not declared with
632 customize."
633 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
634 :group 'custom-buffer)
635
636 (defcustom custom-guess-doc-alist
637 '(("\\`\\*?Non-nil " boolean))
638 "Alist of (MATCH TYPE).
639
640 MATCH should be a regexp matching a documentation string, and TYPE
641 should be a widget suitable for editing the value of a variable with
642 that documentation string. The TYPE of the first entry where MATCH
643 matches the name of the symbol will be used.
644
645 This is used for guessing the type of variables not declared with
646 customize."
647 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
648 :group 'custom-buffer)
649
650 (defun custom-guess-type (symbol)
651 "Guess a widget suitable for editing the value of SYMBOL.
652 This is done by matching SYMBOL with `custom-guess-name-alist' and
653 if that fails, the doc string with `custom-guess-doc-alist'."
654 (let ((name (symbol-name symbol))
655 (names custom-guess-name-alist)
656 current found)
657 (while names
658 (setq current (car names)
659 names (cdr names))
660 (when (string-match (nth 0 current) name)
661 (setq found (nth 1 current)
662 names nil)))
663 (unless found
664 (let ((doc (documentation-property symbol 'variable-documentation))
665 (docs custom-guess-doc-alist))
666 (when doc
667 (while docs
668 (setq current (car docs)
669 docs (cdr docs))
670 (when (string-match (nth 0 current) doc)
671 (setq found (nth 1 current)
672 docs nil))))))
673 found))
674
675 ;;; Sorting.
676
677 ;;;###autoload
678 (defcustom custom-browse-sort-alphabetically nil
679 "If non-nil, sort customization group alphabetically in `custom-browse'."
680 :type 'boolean
681 :group 'custom-browse)
682
683 (defcustom custom-browse-order-groups nil
684 "If non-nil, order group members within each customization group.
685 If `first', order groups before non-groups.
686 If `last', order groups after non-groups."
687 :type '(choice (const first)
688 (const last)
689 (const :tag "none" nil))
690 :group 'custom-browse)
691
692 (defcustom custom-browse-only-groups nil
693 "If non-nil, show group members only within each customization group."
694 :type 'boolean
695 :group 'custom-browse)
696
697 ;;;###autoload
698 (defcustom custom-buffer-sort-alphabetically nil
699 "If non-nil, sort each customization group alphabetically in Custom buffer."
700 :type 'boolean
701 :group 'custom-buffer)
702
703 (defcustom custom-buffer-order-groups 'last
704 "If non-nil, order group members within each customization group.
705 If `first', order groups before non-groups.
706 If `last', order groups after non-groups."
707 :type '(choice (const first)
708 (const last)
709 (const :tag "none" nil))
710 :group 'custom-buffer)
711
712 ;;;###autoload
713 (defcustom custom-menu-sort-alphabetically nil
714 "If non-nil, sort each customization group alphabetically in menus."
715 :type 'boolean
716 :group 'custom-menu)
717
718 (defcustom custom-menu-order-groups 'first
719 "If non-nil, order group members within each customization group.
720 If `first', order groups before non-groups.
721 If `last', order groups after non-groups."
722 :type '(choice (const first)
723 (const last)
724 (const :tag "none" nil))
725 :group 'custom-menu)
726
727 ;;;###autoload (add-hook 'same-window-regexps "\\`\\*Customiz.*\\*\\'")
728
729 (defun custom-sort-items (items sort-alphabetically order-groups)
730 "Return a sorted copy of ITEMS.
731 ITEMS should be a `custom-group' property.
732 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
733 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
734 groups after non-groups, if nil do not order groups at all."
735 (sort (copy-sequence items)
736 (lambda (a b)
737 (let ((typea (nth 1 a)) (typeb (nth 1 b))
738 (namea (nth 0 a)) (nameb (nth 0 b)))
739 (cond ((not order-groups)
740 ;; Since we don't care about A and B order, maybe sort.
741 (when sort-alphabetically
742 (string-lessp namea nameb)))
743 ((eq typea 'custom-group)
744 ;; If B is also a group, maybe sort. Otherwise, order A and B.
745 (if (eq typeb 'custom-group)
746 (when sort-alphabetically
747 (string-lessp namea nameb))
748 (eq order-groups 'first)))
749 ((eq typeb 'custom-group)
750 ;; Since A cannot be a group, order A and B.
751 (eq order-groups 'last))
752 (sort-alphabetically
753 ;; Since A and B cannot be groups, sort.
754 (string-lessp namea nameb)))))))
755
756 ;;; Custom Mode Commands.
757
758 ;; This variable is used by `custom-tool-bar-map', or directly by
759 ;; `custom-buffer-create-internal' if the toolbar is not present and
760 ;; `custom-buffer-verbose-help' is non-nil.
761
762 (defvar custom-commands
763 '(("Set for current session" Custom-set t
764 "Apply all settings in this buffer to the current session"
765 "index")
766 ("Save for future sessions" Custom-save
767 (or custom-file user-init-file)
768 "Apply all settings in this buffer and save them for future Emacs sessions."
769 "save")
770 ("Undo edits" Custom-reset-current t
771 "Restore all settings in this buffer to reflect their current values."
772 "refresh")
773 ("Reset to saved" Custom-reset-saved t
774 "Restore all settings in this buffer to their saved values (if any)."
775 "undo")
776 ("Erase customizations" Custom-reset-standard
777 (or custom-file user-init-file)
778 "Un-customize all settings in this buffer and save them with standard values."
779 "delete")
780 ("Help for Customize" Custom-help t
781 "Get help for using Customize."
782 "help")
783 ("Exit" Custom-buffer-done t "Exit Customize." "exit")))
784
785 (defun Custom-help ()
786 "Read the node on Easy Customization in the Emacs manual."
787 (interactive)
788 (info "(emacs)Easy Customization"))
789
790 (defvar custom-reset-menu
791 '(("Undo Edits" . Custom-reset-current)
792 ("Reset to Saved" . Custom-reset-saved)
793 ("Erase Customizations (use standard values)" . Custom-reset-standard))
794 "Alist of actions for the `Reset' button.
795 The key is a string containing the name of the action, the value is a
796 Lisp function taking the widget as an element which will be called
797 when the action is chosen.")
798
799 (defvar custom-options nil
800 "Customization widgets in the current buffer.")
801
802 (defun custom-command-apply (fun query &optional strong-query)
803 "Call function FUN on all widgets in `custom-options'.
804 If there is more than one widget, ask user for confirmation using
805 the query string QUERY, using `y-or-n-p' if STRONG-QUERY is nil,
806 and `yes-or-no-p' otherwise."
807 (if (or (and (= 1 (length custom-options))
808 (memq (widget-type (car custom-options))
809 '(custom-variable custom-face)))
810 (funcall (if strong-query 'yes-or-no-p 'y-or-n-p) query))
811 (progn (mapc fun custom-options) t)
812 (message "Aborted")
813 nil))
814
815 (defun Custom-set (&rest ignore)
816 "Set the current value of all edited settings in the buffer."
817 (interactive)
818 (custom-command-apply
819 (lambda (child)
820 (when (eq (widget-get child :custom-state) 'modified)
821 (widget-apply child :custom-set)))
822 "Set all values according to this buffer? "))
823
824 (defun Custom-save (&rest ignore)
825 "Set all edited settings, then save all settings that have been set.
826 If a setting was edited and set before, this saves it.
827 If a setting was merely edited before, this sets it then saves it."
828 (interactive)
829 (if (custom-command-apply
830 (lambda (child)
831 (when (memq (widget-get child :custom-state)
832 '(modified set changed rogue))
833 (widget-apply child :custom-save)))
834 "Save all settings in this buffer? " t)
835 (custom-save-all)))
836
837 (defun custom-reset (widget &optional event)
838 "Select item from reset menu."
839 (let* ((completion-ignore-case t)
840 (answer (widget-choose "Reset settings"
841 custom-reset-menu
842 event)))
843 (if answer
844 (funcall answer))))
845
846 (defun Custom-reset-current (&rest ignore)
847 "Reset all edited settings in the buffer to show their current values."
848 (interactive)
849 (custom-command-apply
850 (lambda (widget)
851 (if (memq (widget-get widget :custom-state) '(modified changed))
852 (widget-apply widget :custom-reset-current)))
853 "Reset all settings' buffer text to show current values? "))
854
855 (defun Custom-reset-saved (&rest ignore)
856 "Reset all edited or set settings in the buffer to their saved value.
857 This also shows the saved values in the buffer."
858 (interactive)
859 (custom-command-apply
860 (lambda (widget)
861 (if (memq (widget-get widget :custom-state) '(modified set changed rogue))
862 (widget-apply widget :custom-reset-saved)))
863 "Reset all settings (current values and buffer text) to saved values? "))
864
865 (defun Custom-reset-standard (&rest ignore)
866 "Erase all customization (either current or saved) for the group members.
867 The immediate result is to restore them to their standard values.
868 This operation eliminates any saved values for the group members,
869 making them as if they had never been customized at all."
870 (interactive)
871 (custom-command-apply
872 (lambda (widget)
873 (and (or (null (widget-get widget :custom-standard-value))
874 (widget-apply widget :custom-standard-value))
875 (memq (widget-get widget :custom-state)
876 '(modified set changed saved rogue))
877 (widget-apply widget :custom-reset-standard)))
878 "Erase all customizations for settings in this buffer? " t))
879
880 ;;; The Customize Commands
881
882 (defun custom-prompt-variable (prompt-var prompt-val &optional comment)
883 "Prompt for a variable and a value and return them as a list.
884 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
885 prompt for the value. The %s escape in PROMPT-VAL is replaced with
886 the name of the variable.
887
888 If the variable has a `variable-interactive' property, that is used as if
889 it were the arg to `interactive' (which see) to interactively read the value.
890
891 If the variable has a `custom-type' property, it must be a widget and the
892 `:prompt-value' property of that widget will be used for reading the value.
893
894 If optional COMMENT argument is non-nil, also prompt for a comment and return
895 it as the third element in the list."
896 (let* ((var (read-variable prompt-var))
897 (minibuffer-help-form '(describe-variable var))
898 (val
899 (let ((prop (get var 'variable-interactive))
900 (type (get var 'custom-type))
901 (prompt (format prompt-val var)))
902 (unless (listp type)
903 (setq type (list type)))
904 (cond (prop
905 ;; Use VAR's `variable-interactive' property
906 ;; as an interactive spec for prompting.
907 (call-interactively `(lambda (arg)
908 (interactive ,prop)
909 arg)))
910 (type
911 (widget-prompt-value type
912 prompt
913 (if (boundp var)
914 (symbol-value var))
915 (not (boundp var))))
916 (t
917 (eval-minibuffer prompt))))))
918 (if comment
919 (list var val
920 (read-string "Comment: " (get var 'variable-comment)))
921 (list var val))))
922
923 ;;;###autoload
924 (defun customize-set-value (variable value &optional comment)
925 "Set VARIABLE to VALUE, and return VALUE. VALUE is a Lisp object.
926
927 If VARIABLE has a `variable-interactive' property, that is used as if
928 it were the arg to `interactive' (which see) to interactively read the value.
929
930 If VARIABLE has a `custom-type' property, it must be a widget and the
931 `:prompt-value' property of that widget will be used for reading the value.
932
933 If given a prefix (or a COMMENT argument), also prompt for a comment."
934 (interactive (custom-prompt-variable "Set variable: "
935 "Set %s to value: "
936 current-prefix-arg))
937
938 (cond ((string= comment "")
939 (put variable 'variable-comment nil))
940 (comment
941 (put variable 'variable-comment comment)))
942 (set variable value))
943
944 ;;;###autoload
945 (defun customize-set-variable (variable value &optional comment)
946 "Set the default for VARIABLE to VALUE, and return VALUE.
947 VALUE is a Lisp object.
948
949 If VARIABLE has a `custom-set' property, that is used for setting
950 VARIABLE, otherwise `set-default' is used.
951
952 If VARIABLE has a `variable-interactive' property, that is used as if
953 it were the arg to `interactive' (which see) to interactively read the value.
954
955 If VARIABLE has a `custom-type' property, it must be a widget and the
956 `:prompt-value' property of that widget will be used for reading the value.
957
958 If given a prefix (or a COMMENT argument), also prompt for a comment."
959 (interactive (custom-prompt-variable "Set variable: "
960 "Set customized value for %s to: "
961 current-prefix-arg))
962 (custom-load-symbol variable)
963 (custom-push-theme 'theme-value variable 'user 'set (custom-quote value))
964 (funcall (or (get variable 'custom-set) 'set-default) variable value)
965 (put variable 'customized-value (list (custom-quote value)))
966 (cond ((string= comment "")
967 (put variable 'variable-comment nil)
968 (put variable 'customized-variable-comment nil))
969 (comment
970 (put variable 'variable-comment comment)
971 (put variable 'customized-variable-comment comment)))
972 value)
973
974 ;;;###autoload
975 (defun customize-save-variable (variable value &optional comment)
976 "Set the default for VARIABLE to VALUE, and save it for future sessions.
977 Return VALUE.
978
979 If VARIABLE has a `custom-set' property, that is used for setting
980 VARIABLE, otherwise `set-default' is used.
981
982 If VARIABLE has a `variable-interactive' property, that is used as if
983 it were the arg to `interactive' (which see) to interactively read the value.
984
985 If VARIABLE has a `custom-type' property, it must be a widget and the
986 `:prompt-value' property of that widget will be used for reading the value.
987
988 If given a prefix (or a COMMENT argument), also prompt for a comment."
989 (interactive (custom-prompt-variable "Set and save variable: "
990 "Set and save value for %s as: "
991 current-prefix-arg))
992 (funcall (or (get variable 'custom-set) 'set-default) variable value)
993 (put variable 'saved-value (list (custom-quote value)))
994 (custom-push-theme 'theme-value variable 'user 'set (custom-quote value))
995 (cond ((string= comment "")
996 (put variable 'variable-comment nil)
997 (put variable 'saved-variable-comment nil))
998 (comment
999 (put variable 'variable-comment comment)
1000 (put variable 'saved-variable-comment comment)))
1001 (put variable 'customized-value nil)
1002 (put variable 'customized-variable-comment nil)
1003 (custom-save-all)
1004 value)
1005
1006 ;;;###autoload
1007 (defun customize ()
1008 "Select a customization buffer which you can use to set user options.
1009 User options are structured into \"groups\".
1010 Initially the top-level group `Emacs' and its immediate subgroups
1011 are shown; the contents of those subgroups are initially hidden."
1012 (interactive)
1013 (customize-group 'emacs))
1014
1015 ;;;###autoload
1016 (defun customize-mode (mode)
1017 "Customize options related to the current major mode.
1018 If a prefix \\[universal-argument] was given (or if the current major mode has no known group),
1019 then prompt for the MODE to customize."
1020 (interactive
1021 (list
1022 (let ((completion-regexp-list '("-mode\\'"))
1023 (group (custom-group-of-mode major-mode)))
1024 (if (and group (not current-prefix-arg))
1025 major-mode
1026 (intern
1027 (completing-read (if group
1028 (format "Major mode (default %s): " major-mode)
1029 "Major mode: ")
1030 obarray
1031 'custom-group-of-mode
1032 t nil nil (if group (symbol-name major-mode))))))))
1033 (customize-group (custom-group-of-mode mode)))
1034
1035
1036 ;;;###autoload
1037 (defun customize-group (&optional group prompt-for-group other-window)
1038 "Customize GROUP, which must be a customization group."
1039 (interactive)
1040 (and (null group)
1041 (or prompt-for-group (called-interactively-p))
1042 (let ((completion-ignore-case t))
1043 (setq group
1044 (completing-read "Customize group (default emacs): "
1045 obarray
1046 (lambda (symbol)
1047 (or (and (get symbol 'custom-loads)
1048 (not (get symbol 'custom-autoload)))
1049 (get symbol 'custom-group)))
1050 t))))
1051 (when (stringp group)
1052 (if (string-equal "" group)
1053 (setq group 'emacs)
1054 (setq group (intern group))))
1055 (let ((name (format "*Customize Group: %s*"
1056 (custom-unlispify-tag-name group))))
1057 (if (get-buffer name)
1058 (if other-window
1059 (let ((pop-up-windows t)
1060 (same-window-buffer-names nil)
1061 (same-window-regexps nil))
1062 (pop-to-buffer name))
1063 (pop-to-buffer name))
1064 (funcall (if other-window
1065 'custom-buffer-create-other-window
1066 'custom-buffer-create)
1067 (list (list group 'custom-group))
1068 name
1069 (concat " for group "
1070 (custom-unlispify-tag-name group))))))
1071
1072 ;;;###autoload
1073 (defun customize-group-other-window (&optional group)
1074 "Customize GROUP, which must be a customization group, in another window."
1075 (interactive)
1076 (customize-group group t t))
1077
1078 ;;;###autoload
1079 (defalias 'customize-variable 'customize-option)
1080
1081 ;;;###autoload
1082 (defun customize-option (symbol)
1083 "Customize SYMBOL, which must be a user option variable."
1084 (interactive (custom-variable-prompt))
1085 (unless symbol
1086 (error "No variable specified"))
1087 (let ((basevar (indirect-variable symbol)))
1088 (custom-buffer-create (list (list basevar 'custom-variable))
1089 (format "*Customize Option: %s*"
1090 (custom-unlispify-tag-name basevar)))
1091 (unless (eq symbol basevar)
1092 (message "`%s' is an alias for `%s'" symbol basevar))))
1093
1094 ;;;###autoload
1095 (defalias 'customize-variable-other-window 'customize-option-other-window)
1096
1097 ;;;###autoload
1098 (defun customize-option-other-window (symbol)
1099 "Customize SYMBOL, which must be a user option variable.
1100 Show the buffer in another window, but don't select it."
1101 (interactive (custom-variable-prompt))
1102 (unless symbol
1103 (error "No variable specified"))
1104 (let ((basevar (indirect-variable symbol)))
1105 (custom-buffer-create-other-window
1106 (list (list basevar 'custom-variable))
1107 (format "*Customize Option: %s*" (custom-unlispify-tag-name basevar)))
1108 (unless (eq symbol basevar)
1109 (message "`%s' is an alias for `%s'" symbol basevar))))
1110
1111 (defvar customize-changed-options-previous-release "21.1"
1112 "Version for `customize-changed-options' to refer back to by default.")
1113
1114 ;; Packages will update this variable, so make it available.
1115 ;;;###autoload
1116 (defvar customize-package-emacs-version-alist nil
1117 "Alist mapping versions of a package to Emacs versions.
1118 We use this for packages that have their own names, but are released
1119 as part of Emacs itself.
1120
1121 Each elements looks like this:
1122
1123 (PACKAGE (PVERSION . EVERSION)...)
1124
1125 Here PACKAGE is the name of a package, as a symbol. After
1126 PACKAGE come one or more elements, each associating a
1127 package version PVERSION with the first Emacs version
1128 EVERSION in which it (or a subsequent version of PACKAGE)
1129 was first released. Both PVERSION and EVERSION are strings.
1130 PVERSION should be a string that this package used in
1131 the :package-version keyword for `defcustom', `defgroup',
1132 and `defface'.
1133
1134 For example, the MH-E package updates this alist as follows:
1135
1136 (add-to-list 'customize-package-emacs-version-alist
1137 '(MH-E (\"6.0\" . \"22.1\") (\"6.1\" . \"22.1\")
1138 (\"7.0\" . \"22.1\") (\"7.1\" . \"22.1\")
1139 (\"7.2\" . \"22.1\") (\"7.3\" . \"22.1\")
1140 (\"7.4\" . \"22.1\") (\"8.0\" . \"22.1\")))
1141
1142 The value of PACKAGE needs to be unique and it needs to match the
1143 PACKAGE value appearing in the :package-version keyword. Since
1144 the user might see the value in a error message, a good choice is
1145 the official name of the package, such as MH-E or Gnus.")
1146
1147 ;;;###autoload
1148 (defalias 'customize-changed 'customize-changed-options)
1149
1150 ;;;###autoload
1151 (defun customize-changed-options (since-version)
1152 "Customize all settings whose meanings have changed in Emacs itself.
1153 This includes new user option variables and faces, and new
1154 customization groups, as well as older options and faces whose meanings
1155 or default values have changed since the previous major Emacs release.
1156
1157 With argument SINCE-VERSION (a string), customize all settings
1158 that were added or redefined since that version."
1159
1160 (interactive
1161 (list
1162 (read-from-minibuffer
1163 (format "Customize options changed, since version (default %s): "
1164 customize-changed-options-previous-release))))
1165 (if (equal since-version "")
1166 (setq since-version nil)
1167 (unless (condition-case nil
1168 (numberp (read since-version))
1169 (error nil))
1170 (signal 'wrong-type-argument (list 'numberp since-version))))
1171 (unless since-version
1172 (setq since-version customize-changed-options-previous-release))
1173
1174 ;; Load the information for versions since since-version. We use
1175 ;; custom-load-symbol for this.
1176 (put 'custom-versions-load-alist 'custom-loads nil)
1177 (dolist (elt custom-versions-load-alist)
1178 (if (customize-version-lessp since-version (car elt))
1179 (dolist (load (cdr elt))
1180 (custom-add-load 'custom-versions-load-alist load))))
1181 (custom-load-symbol 'custom-versions-load-alist)
1182 (put 'custom-versions-load-alist 'custom-loads nil)
1183
1184 (let (found)
1185 (mapatoms
1186 (lambda (symbol)
1187 (let* ((package-version (get symbol 'custom-package-version))
1188 (version
1189 (or (and package-version
1190 (customize-package-emacs-version symbol
1191 package-version))
1192 (get symbol 'custom-version))))
1193 (if version
1194 (when (customize-version-lessp since-version version)
1195 (if (or (get symbol 'custom-group)
1196 (get symbol 'group-documentation))
1197 (push (list symbol 'custom-group) found))
1198 (if (custom-variable-p symbol)
1199 (push (list symbol 'custom-variable) found))
1200 (if (custom-facep symbol)
1201 (push (list symbol 'custom-face) found)))))))
1202 (if found
1203 (custom-buffer-create (custom-sort-items found t 'first)
1204 "*Customize Changed Options*")
1205 (error "No user option defaults have been changed since Emacs %s"
1206 since-version))))
1207
1208 (defun customize-package-emacs-version (symbol package-version)
1209 "Return the Emacs version in which SYMBOL's meaning last changed.
1210 PACKAGE-VERSION has the form (PACKAGE . VERSION). We use
1211 `customize-package-emacs-version-alist' to find the version of
1212 Emacs that is associated with version VERSION of PACKAGE."
1213 (let (package-versions emacs-version)
1214 ;; Use message instead of error since we want user to be able to
1215 ;; see the rest of the symbols even if a package author has
1216 ;; botched things up.
1217 (cond ((not (listp package-version))
1218 (message "Invalid package-version value for %s" symbol))
1219 ((setq package-versions (assq (car package-version)
1220 customize-package-emacs-version-alist))
1221 (setq emacs-version
1222 (cdr (assoc (cdr package-version) package-versions)))
1223 (unless emacs-version
1224 (message "%s version %s not found in %s" symbol
1225 (cdr package-version)
1226 "customize-package-emacs-version-alist")))
1227 (t
1228 (message "Package %s version %s lists no corresponding Emacs version"
1229 (car package-version)
1230 (cdr package-version))))
1231 emacs-version))
1232
1233 (defun customize-version-lessp (version1 version2)
1234 ;; Why are the versions strings, and given that they are, why aren't
1235 ;; they converted to numbers and compared as such here? -- fx
1236
1237 ;; In case someone made a mistake and left out the quotes
1238 ;; in the :version value.
1239 (if (numberp version2)
1240 (setq version2 (prin1-to-string version2)))
1241 (let (major1 major2 minor1 minor2)
1242 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version1)
1243 (setq major1 (read (or (match-string 1 version1)
1244 "0")))
1245 (setq minor1 (read (or (match-string 3 version1)
1246 "0")))
1247 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version2)
1248 (setq major2 (read (or (match-string 1 version2)
1249 "0")))
1250 (setq minor2 (read (or (match-string 3 version2)
1251 "0")))
1252 (or (< major1 major2)
1253 (and (= major1 major2)
1254 (< minor1 minor2)))))
1255
1256 ;;;###autoload
1257 (defun customize-face (&optional face prompt-for-face other-window)
1258 "Customize FACE, which should be a face name or nil.
1259 If FACE is nil, customize all faces. If FACE is actually a
1260 face-alias, customize the face it is aliased to.
1261
1262 Interactively, when point is on text which has a face specified,
1263 suggest to customize that face, if it's customizable."
1264 (interactive)
1265 (and (null face)
1266 (or prompt-for-face (called-interactively-p))
1267 (setq face (read-face-name "Customize face" "all faces" t)))
1268 (if (member face '(nil ""))
1269 (setq face (face-list)))
1270 (if (and (listp face) (null (cdr face)))
1271 (setq face (car face)))
1272 (let ((create-buffer-fn (if other-window
1273 'custom-buffer-create-other-window
1274 'custom-buffer-create)))
1275 (if (listp face)
1276 (funcall create-buffer-fn
1277 (custom-sort-items
1278 (mapcar (lambda (s)
1279 (list s 'custom-face))
1280 face)
1281 t nil)
1282 "*Customize Faces*")
1283 ;; If FACE is actually an alias, customize the face it is aliased to.
1284 (if (get face 'face-alias)
1285 (setq face (get face 'face-alias)))
1286 (unless (facep face)
1287 (error "Invalid face %S" face))
1288 (funcall create-buffer-fn
1289 (list (list face 'custom-face))
1290 (format "*Customize Face: %s*"
1291 (custom-unlispify-tag-name face))))))
1292
1293 ;;;###autoload
1294 (defun customize-face-other-window (&optional face)
1295 "Show customization buffer for face FACE in other window.
1296 If FACE is actually a face-alias, customize the face it is aliased to.
1297
1298 Interactively, when point is on text which has a face specified,
1299 suggest to customize that face, if it's customizable."
1300 (interactive)
1301 (customize-face face t t))
1302
1303 (defalias 'customize-customized 'customize-unsaved)
1304
1305 ;;;###autoload
1306 (defun customize-unsaved ()
1307 "Customize all user options set in this session but not saved."
1308 (interactive)
1309 (let ((found nil))
1310 (mapatoms (lambda (symbol)
1311 (and (or (get symbol 'customized-face)
1312 (get symbol 'customized-face-comment))
1313 (custom-facep symbol)
1314 (push (list symbol 'custom-face) found))
1315 (and (or (get symbol 'customized-value)
1316 (get symbol 'customized-variable-comment))
1317 (boundp symbol)
1318 (push (list symbol 'custom-variable) found))))
1319 (if (not found)
1320 (error "No user options are set but unsaved")
1321 (custom-buffer-create (custom-sort-items found t nil)
1322 "*Customize Unsaved*"))))
1323
1324 ;;;###autoload
1325 (defun customize-rogue ()
1326 "Customize all user variables modified outside customize."
1327 (interactive)
1328 (let ((found nil))
1329 (mapatoms (lambda (symbol)
1330 (let ((cval (or (get symbol 'customized-value)
1331 (get symbol 'saved-value)
1332 (get symbol 'standard-value))))
1333 (when (and cval ;Declared with defcustom.
1334 (default-boundp symbol) ;Has a value.
1335 (not (equal (eval (car cval))
1336 ;; Which does not match customize.
1337 (default-value symbol))))
1338 (push (list symbol 'custom-variable) found)))))
1339 (if (not found)
1340 (error "No rogue user options")
1341 (custom-buffer-create (custom-sort-items found t nil)
1342 "*Customize Rogue*"))))
1343 ;;;###autoload
1344 (defun customize-saved ()
1345 "Customize all already saved user options."
1346 (interactive)
1347 (let ((found nil))
1348 (mapatoms (lambda (symbol)
1349 (and (or (get symbol 'saved-face)
1350 (get symbol 'saved-face-comment))
1351 (custom-facep symbol)
1352 (push (list symbol 'custom-face) found))
1353 (and (or (get symbol 'saved-value)
1354 (get symbol 'saved-variable-comment))
1355 (boundp symbol)
1356 (push (list symbol 'custom-variable) found))))
1357 (if (not found )
1358 (error "No saved user options")
1359 (custom-buffer-create (custom-sort-items found t nil)
1360 "*Customize Saved*"))))
1361
1362 ;;;###autoload
1363 (defun customize-apropos (regexp &optional all)
1364 "Customize all loaded options, faces and groups matching REGEXP.
1365 If ALL is `options', include only options.
1366 If ALL is `faces', include only faces.
1367 If ALL is `groups', include only groups.
1368 If ALL is t (interactively, with prefix arg), include variables
1369 that are not customizable options, as well as faces and groups
1370 \(but we recommend using `apropos-variable' instead)."
1371 (interactive "sCustomize regexp: \nP")
1372 (let ((found nil))
1373 (mapatoms (lambda (symbol)
1374 (when (string-match regexp (symbol-name symbol))
1375 (when (and (not (memq all '(faces options)))
1376 (get symbol 'custom-group))
1377 (push (list symbol 'custom-group) found))
1378 (when (and (not (memq all '(options groups)))
1379 (custom-facep symbol))
1380 (push (list symbol 'custom-face) found))
1381 (when (and (not (memq all '(groups faces)))
1382 (boundp symbol)
1383 (eq (indirect-variable symbol) symbol)
1384 (or (get symbol 'saved-value)
1385 (custom-variable-p symbol)
1386 (and (not (memq all '(nil options)))
1387 (get symbol 'variable-documentation))))
1388 (push (list symbol 'custom-variable) found)))))
1389 (if (not found)
1390 (error "No customizable items matching %s" regexp)
1391 (custom-buffer-create
1392 (custom-sort-items found t custom-buffer-order-groups)
1393 "*Customize Apropos*"))))
1394
1395 ;;;###autoload
1396 (defun customize-apropos-options (regexp &optional arg)
1397 "Customize all loaded customizable options matching REGEXP.
1398 With prefix arg, include variables that are not customizable options
1399 \(but we recommend using `apropos-variable' instead)."
1400 (interactive "sCustomize regexp: \nP")
1401 (customize-apropos regexp (or arg 'options)))
1402
1403 ;;;###autoload
1404 (defun customize-apropos-faces (regexp)
1405 "Customize all loaded faces matching REGEXP."
1406 (interactive "sCustomize regexp: \n")
1407 (customize-apropos regexp 'faces))
1408
1409 ;;;###autoload
1410 (defun customize-apropos-groups (regexp)
1411 "Customize all loaded groups matching REGEXP."
1412 (interactive "sCustomize regexp: \n")
1413 (customize-apropos regexp 'groups))
1414
1415 ;;; Buffer.
1416
1417 (defcustom custom-buffer-style 'links
1418 "Control the presentation style for customization buffers.
1419 The value should be a symbol, one of:
1420
1421 brackets: groups nest within each other with big horizontal brackets.
1422 links: groups have links to subgroups."
1423 :type '(radio (const brackets)
1424 (const links))
1425 :group 'custom-buffer)
1426
1427 (defcustom custom-buffer-done-kill nil
1428 "*Non-nil means exiting a Custom buffer should kill it."
1429 :type 'boolean
1430 :version "22.1"
1431 :group 'custom-buffer)
1432
1433 (defcustom custom-buffer-indent 3
1434 "Number of spaces to indent nested groups."
1435 :type 'integer
1436 :group 'custom-buffer)
1437
1438 (defun custom-get-fresh-buffer (name)
1439 "Get a fresh new buffer with name NAME.
1440 If the buffer already exist, clean it up to be like new.
1441 Beware: it's not quite like new. Good enough for custom, but maybe
1442 not for everybody."
1443 ;; To be more complete, we should also kill all permanent-local variables,
1444 ;; but it's not needed for custom.
1445 (let ((buf (get-buffer name)))
1446 (when (and buf (buffer-local-value 'buffer-file-name buf))
1447 ;; This will check if the file is not saved.
1448 (kill-buffer buf)
1449 (setq buf nil))
1450 (if (null buf)
1451 (get-buffer-create name)
1452 (with-current-buffer buf
1453 (kill-all-local-variables)
1454 (run-hooks 'kill-buffer-hook)
1455 ;; Delete overlays before erasing the buffer so the overlay hooks
1456 ;; don't get run spuriously when we erase the buffer.
1457 (let ((ols (overlay-lists)))
1458 (dolist (ol (nconc (car ols) (cdr ols)))
1459 (delete-overlay ol)))
1460 (erase-buffer)
1461 buf))))
1462
1463 ;;;###autoload
1464 (defun custom-buffer-create (options &optional name description)
1465 "Create a buffer containing OPTIONS.
1466 Optional NAME is the name of the buffer.
1467 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1468 SYMBOL is a customization option, and WIDGET is a widget for editing
1469 that option."
1470 (pop-to-buffer (custom-get-fresh-buffer (or name "*Customization*")))
1471 (custom-buffer-create-internal options description))
1472
1473 ;;;###autoload
1474 (defun custom-buffer-create-other-window (options &optional name description)
1475 "Create a buffer containing OPTIONS, and display it in another window.
1476 The result includes selecting that window.
1477 Optional NAME is the name of the buffer.
1478 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1479 SYMBOL is a customization option, and WIDGET is a widget for editing
1480 that option."
1481 (unless name (setq name "*Customization*"))
1482 (let ((pop-up-windows t)
1483 (same-window-buffer-names nil)
1484 (same-window-regexps nil))
1485 (pop-to-buffer (custom-get-fresh-buffer name))
1486 (custom-buffer-create-internal options description)))
1487
1488 (defcustom custom-reset-button-menu nil
1489 "If non-nil, only show a single reset button in customize buffers.
1490 This button will have a menu with all three reset operations."
1491 :type 'boolean
1492 :group 'custom-buffer)
1493
1494 (defcustom custom-buffer-verbose-help t
1495 "If non-nil, include explanatory text in the customization buffer."
1496 :type 'boolean
1497 :group 'custom-buffer)
1498
1499 (defun Custom-buffer-done (&rest ignore)
1500 "Exit current Custom buffer according to `custom-buffer-done-kill'."
1501 (interactive)
1502 (quit-window custom-buffer-done-kill))
1503
1504 (defvar custom-button nil
1505 "Face used for buttons in customization buffers.")
1506
1507 (defvar custom-button-mouse nil
1508 "Mouse face used for buttons in customization buffers.")
1509
1510 (defvar custom-button-pressed nil
1511 "Face used for pressed buttons in customization buffers.")
1512
1513 (defcustom custom-raised-buttons (not (equal (face-valid-attribute-values :box)
1514 '(("unspecified" . unspecified))))
1515 "If non-nil, indicate active buttons in a `raised-button' style.
1516 Otherwise use brackets."
1517 :type 'boolean
1518 :version "21.1"
1519 :group 'custom-buffer
1520 :set (lambda (variable value)
1521 (custom-set-default variable value)
1522 (setq custom-button
1523 (if value 'custom-button 'custom-button-unraised))
1524 (setq custom-button-mouse
1525 (if value 'custom-button-mouse 'highlight))
1526 (setq custom-button-pressed
1527 (if value
1528 'custom-button-pressed
1529 'custom-button-pressed-unraised))))
1530
1531 (defun custom-buffer-create-internal (options &optional description)
1532 (custom-mode)
1533 (let ((init-file (or custom-file user-init-file)))
1534 ;; Insert verbose help at the top of the custom buffer.
1535 (when custom-buffer-verbose-help
1536 (widget-insert "Editing a setting changes only the text in this buffer."
1537 (if init-file
1538 "
1539 To set apply your changes, use the Save or Set buttons.
1540 Saving a change normally works by editing your init file."
1541 "
1542 Currently, these settings cannot be saved for future Emacs sessions,
1543 possibly because you started Emacs with `-q'.")
1544 "\nFor details, see ")
1545 (widget-create 'custom-manual
1546 :tag "Saving Customizations"
1547 "(emacs)Saving Customizations")
1548 (widget-insert " in the ")
1549 (widget-create 'custom-manual
1550 :tag "Emacs manual"
1551 :help-echo "Read the Emacs manual."
1552 "(emacs)Top")
1553 (widget-insert "."))
1554 ;; Insert custom command buttons if the toolbar is not in use.
1555
1556 (widget-insert "\n")
1557 (when (not (and 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 ; (string-match "XEmacs" emacs-version)
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 ,@(when (or custom-file user-init-file)
2689 '(("Save for Future Sessions" custom-variable-save
2690 (lambda (widget)
2691 (memq (widget-get widget :custom-state)
2692 '(modified set changed rogue))))))
2693 ("Undo Edits" custom-redraw
2694 (lambda (widget)
2695 (and (default-boundp (widget-value widget))
2696 (memq (widget-get widget :custom-state) '(modified changed)))))
2697 ("Reset to Saved" custom-variable-reset-saved
2698 (lambda (widget)
2699 (and (or (get (widget-value widget) 'saved-value)
2700 (get (widget-value widget) 'saved-variable-comment))
2701 (memq (widget-get widget :custom-state)
2702 '(modified set changed rogue)))))
2703 ,@(when (or custom-file user-init-file)
2704 '(("Erase Customization" custom-variable-reset-standard
2705 (lambda (widget)
2706 (and (get (widget-value widget) 'standard-value)
2707 (memq (widget-get widget :custom-state)
2708 '(modified set changed saved rogue)))))))
2709 ("Set to Backup Value" custom-variable-reset-backup
2710 (lambda (widget)
2711 (get (widget-value widget) 'backup-value)))
2712 ("---" ignore ignore)
2713 ("Add Comment" custom-comment-show custom-comment-invisible-p)
2714 ("---" ignore ignore)
2715 ("Show Current Value" custom-variable-edit
2716 (lambda (widget)
2717 (eq (widget-get widget :custom-form) 'lisp)))
2718 ("Show Saved Lisp Expression" custom-variable-edit-lisp
2719 (lambda (widget)
2720 (eq (widget-get widget :custom-form) 'edit))))
2721 "Alist of actions for the `custom-variable' widget.
2722 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2723 the menu entry, ACTION is the function to call on the widget when the
2724 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2725 widget as an argument, and returns non-nil if ACTION is valid on that
2726 widget. If FILTER is nil, ACTION is always valid.")
2727
2728 (defun custom-variable-action (widget &optional event)
2729 "Show the menu for `custom-variable' WIDGET.
2730 Optional EVENT is the location for the menu."
2731 (if (eq (widget-get widget :custom-state) 'hidden)
2732 (custom-toggle-hide widget)
2733 (unless (eq (widget-get widget :custom-state) 'modified)
2734 (custom-variable-state-set widget))
2735 (custom-redraw-magic widget)
2736 (let* ((completion-ignore-case t)
2737 (answer (widget-choose (concat "Operation on "
2738 (custom-unlispify-tag-name
2739 (widget-get widget :value)))
2740 (custom-menu-filter custom-variable-menu
2741 widget)
2742 event)))
2743 (if answer
2744 (funcall answer widget)))))
2745
2746 (defun custom-variable-edit (widget)
2747 "Edit value of WIDGET."
2748 (widget-put widget :custom-state 'unknown)
2749 (widget-put widget :custom-form 'edit)
2750 (custom-redraw widget))
2751
2752 (defun custom-variable-edit-lisp (widget)
2753 "Edit the Lisp representation of the value of WIDGET."
2754 (widget-put widget :custom-state 'unknown)
2755 (widget-put widget :custom-form 'lisp)
2756 (custom-redraw widget))
2757
2758 (defun custom-variable-set (widget)
2759 "Set the current value for the variable being edited by WIDGET."
2760 (let* ((form (widget-get widget :custom-form))
2761 (state (widget-get widget :custom-state))
2762 (child (car (widget-get widget :children)))
2763 (symbol (widget-value widget))
2764 (set (or (get symbol 'custom-set) 'set-default))
2765 (comment-widget (widget-get widget :comment-widget))
2766 (comment (widget-value comment-widget))
2767 val)
2768 (cond ((eq state 'hidden)
2769 (error "Cannot set hidden variable"))
2770 ((setq val (widget-apply child :validate))
2771 (goto-char (widget-get val :from))
2772 (error "%s" (widget-get val :error)))
2773 ((memq form '(lisp mismatch))
2774 (when (equal comment "")
2775 (setq comment nil)
2776 ;; Make the comment invisible by hand if it's empty
2777 (custom-comment-hide comment-widget))
2778 (custom-variable-backup-value widget)
2779 (custom-push-theme 'theme-value symbol 'user
2780 'set (custom-quote (widget-value child)))
2781 (funcall set symbol (eval (setq val (widget-value child))))
2782 (put symbol 'customized-value (list val))
2783 (put symbol 'variable-comment comment)
2784 (put symbol 'customized-variable-comment comment))
2785 (t
2786 (when (equal comment "")
2787 (setq comment nil)
2788 ;; Make the comment invisible by hand if it's empty
2789 (custom-comment-hide comment-widget))
2790 (custom-variable-backup-value widget)
2791 (custom-push-theme 'theme-value symbol 'user
2792 'set (custom-quote (widget-value child)))
2793 (funcall set symbol (setq val (widget-value child)))
2794 (put symbol 'customized-value (list (custom-quote val)))
2795 (put symbol 'variable-comment comment)
2796 (put symbol 'customized-variable-comment comment)))
2797 (custom-variable-state-set widget)
2798 (custom-redraw-magic widget)))
2799
2800 (defun custom-variable-save (widget)
2801 "Set and save the value for the variable being edited by WIDGET."
2802 (let* ((form (widget-get widget :custom-form))
2803 (state (widget-get widget :custom-state))
2804 (child (car (widget-get widget :children)))
2805 (symbol (widget-value widget))
2806 (set (or (get symbol 'custom-set) 'set-default))
2807 (comment-widget (widget-get widget :comment-widget))
2808 (comment (widget-value comment-widget))
2809 val)
2810 (cond ((eq state 'hidden)
2811 (error "Cannot set hidden variable"))
2812 ((setq val (widget-apply child :validate))
2813 (goto-char (widget-get val :from))
2814 (error "Saving %s: %s" symbol (widget-get val :error)))
2815 ((memq form '(lisp mismatch))
2816 (when (equal comment "")
2817 (setq comment nil)
2818 ;; Make the comment invisible by hand if it's empty
2819 (custom-comment-hide comment-widget))
2820 (put symbol 'saved-value (list (widget-value child)))
2821 (custom-push-theme 'theme-value symbol 'user
2822 'set (custom-quote (widget-value child)))
2823 (funcall set symbol (eval (widget-value child)))
2824 (put symbol 'variable-comment comment)
2825 (put symbol 'saved-variable-comment comment))
2826 (t
2827 (when (equal comment "")
2828 (setq comment nil)
2829 ;; Make the comment invisible by hand if it's empty
2830 (custom-comment-hide comment-widget))
2831 (put symbol 'saved-value
2832 (list (custom-quote (widget-value child))))
2833 (custom-push-theme 'theme-value symbol 'user
2834 'set (custom-quote (widget-value child)))
2835 (funcall set symbol (widget-value child))
2836 (put symbol 'variable-comment comment)
2837 (put symbol 'saved-variable-comment comment)))
2838 (put symbol 'customized-value nil)
2839 (put symbol 'customized-variable-comment nil)
2840 (custom-save-all)
2841 (custom-variable-state-set widget)
2842 (custom-redraw-magic widget)))
2843
2844 (defun custom-variable-reset-saved (widget)
2845 "Restore the saved value for the variable being edited by WIDGET.
2846 This also updates the buffer to show that value.
2847 The value that was current before this operation
2848 becomes the backup value, so you can get it again."
2849 (let* ((symbol (widget-value widget))
2850 (set (or (get symbol 'custom-set) 'set-default))
2851 (value (get symbol 'saved-value))
2852 (comment (get symbol 'saved-variable-comment)))
2853 (cond ((or value comment)
2854 (put symbol 'variable-comment comment)
2855 (custom-variable-backup-value widget)
2856 (custom-push-theme 'theme-value symbol 'user 'set (car-safe value))
2857 (condition-case nil
2858 (funcall set symbol (eval (car value)))
2859 (error nil)))
2860 (t
2861 (error "No saved value for %s" symbol)))
2862 (put symbol 'customized-value nil)
2863 (put symbol 'customized-variable-comment nil)
2864 (widget-put widget :custom-state 'unknown)
2865 ;; This call will possibly make the comment invisible
2866 (custom-redraw widget)))
2867
2868 (defun custom-variable-reset-standard (widget)
2869 "Restore the standard setting for the variable being edited by WIDGET.
2870 This operation eliminates any saved setting for the variable,
2871 restoring it to the state of a variable that has never been customized.
2872 The value that was current before this operation
2873 becomes the backup value, so you can get it again."
2874 (let* ((symbol (widget-value widget)))
2875 (if (get symbol 'standard-value)
2876 (custom-variable-backup-value widget)
2877 (error "No standard setting known for %S" symbol))
2878 (put symbol 'variable-comment nil)
2879 (put symbol 'customized-value nil)
2880 (put symbol 'customized-variable-comment nil)
2881 (custom-push-theme 'theme-value symbol 'user 'reset)
2882 (custom-theme-recalc-variable symbol)
2883 (when (or (get symbol 'saved-value) (get symbol 'saved-variable-comment))
2884 (put symbol 'saved-value nil)
2885 (put symbol 'saved-variable-comment nil)
2886 (custom-save-all))
2887 (widget-put widget :custom-state 'unknown)
2888 ;; This call will possibly make the comment invisible
2889 (custom-redraw widget)))
2890
2891 (defun custom-variable-backup-value (widget)
2892 "Back up the current value for WIDGET's variable.
2893 The backup value is kept in the car of the `backup-value' property."
2894 (let* ((symbol (widget-value widget))
2895 (get (or (get symbol 'custom-get) 'default-value))
2896 (type (custom-variable-type symbol))
2897 (conv (widget-convert type))
2898 (value (if (default-boundp symbol)
2899 (funcall get symbol)
2900 (widget-get conv :value))))
2901 (put symbol 'backup-value (list value))))
2902
2903 (defun custom-variable-reset-backup (widget)
2904 "Restore the backup value for the variable being edited by WIDGET.
2905 The value that was current before this operation
2906 becomes the backup value, so you can use this operation repeatedly
2907 to switch between two values."
2908 (let* ((symbol (widget-value widget))
2909 (set (or (get symbol 'custom-set) 'set-default))
2910 (value (get symbol 'backup-value))
2911 (comment-widget (widget-get widget :comment-widget))
2912 (comment (widget-value comment-widget)))
2913 (if value
2914 (progn
2915 (custom-variable-backup-value widget)
2916 (custom-push-theme 'theme-value symbol 'user 'set value)
2917 (condition-case nil
2918 (funcall set symbol (car value))
2919 (error nil)))
2920 (error "No backup value for %s" symbol))
2921 (put symbol 'customized-value (list (car value)))
2922 (put symbol 'variable-comment comment)
2923 (put symbol 'customized-variable-comment comment)
2924 (custom-variable-state-set widget)
2925 ;; This call will possibly make the comment invisible
2926 (custom-redraw widget)))
2927
2928 ;;; The `custom-visibility' Widget
2929
2930 (define-widget 'custom-visibility 'visibility
2931 "Show or hide a documentation string."
2932 :button-face 'custom-visibility
2933 :pressed-face 'custom-visibility
2934 :mouse-face 'highlight
2935 :pressed-face 'highlight)
2936
2937 (defface custom-visibility
2938 '((t :height 0.8 :inherit link))
2939 "Face for the `custom-visibility' widget."
2940 :version "23.1"
2941 :group 'custom-faces)
2942
2943 ;;; The `custom-face-edit' Widget.
2944
2945 (define-widget 'custom-face-edit 'checklist
2946 "Edit face attributes."
2947 :format "%t: %v"
2948 :tag "Attributes"
2949 :extra-offset 13
2950 :button-args '(:help-echo "Control whether this attribute has any effect.")
2951 :value-to-internal 'custom-face-edit-fix-value
2952 :match (lambda (widget value)
2953 (widget-checklist-match widget
2954 (custom-face-edit-fix-value widget value)))
2955 :convert-widget 'custom-face-edit-convert-widget
2956 :args (mapcar (lambda (att)
2957 (list 'group
2958 :inline t
2959 :sibling-args (widget-get (nth 1 att) :sibling-args)
2960 (list 'const :format "" :value (nth 0 att))
2961 (nth 1 att)))
2962 custom-face-attributes))
2963
2964 (defun custom-face-edit-fix-value (widget value)
2965 "Ignoring WIDGET, convert :bold and :italic in VALUE to new form.
2966 Also change :reverse-video to :inverse-video."
2967 (if (listp value)
2968 (let (result)
2969 (while value
2970 (let ((key (car value))
2971 (val (car (cdr value))))
2972 (cond ((eq key :italic)
2973 (push :slant result)
2974 (push (if val 'italic 'normal) result))
2975 ((eq key :bold)
2976 (push :weight result)
2977 (push (if val 'bold 'normal) result))
2978 ((eq key :reverse-video)
2979 (push :inverse-video result)
2980 (push val result))
2981 (t
2982 (push key result)
2983 (push val result))))
2984 (setq value (cdr (cdr value))))
2985 (setq result (nreverse result))
2986 result)
2987 value))
2988
2989 (defun custom-face-edit-convert-widget (widget)
2990 "Convert :args as widget types in WIDGET."
2991 (widget-put
2992 widget
2993 :args (mapcar (lambda (arg)
2994 (widget-convert arg
2995 :deactivate 'custom-face-edit-deactivate
2996 :activate 'custom-face-edit-activate
2997 :delete 'custom-face-edit-delete))
2998 (widget-get widget :args)))
2999 widget)
3000
3001 (defun custom-face-edit-deactivate (widget)
3002 "Make face widget WIDGET inactive for user modifications."
3003 (unless (widget-get widget :inactive)
3004 (let ((tag (custom-face-edit-attribute-tag widget))
3005 (from (copy-marker (widget-get widget :from)))
3006 (value (widget-value widget))
3007 (inhibit-read-only t)
3008 (inhibit-modification-hooks t))
3009 (save-excursion
3010 (goto-char from)
3011 (widget-default-delete widget)
3012 (insert tag ": *\n")
3013 (widget-put widget :inactive
3014 (cons value (cons from (- (point) from))))))))
3015
3016 (defun custom-face-edit-activate (widget)
3017 "Make face widget WIDGET inactive for user modifications."
3018 (let ((inactive (widget-get widget :inactive))
3019 (inhibit-read-only t)
3020 (inhibit-modification-hooks t))
3021 (when (consp inactive)
3022 (save-excursion
3023 (goto-char (car (cdr inactive)))
3024 (delete-region (point) (+ (point) (cdr (cdr inactive))))
3025 (widget-put widget :inactive nil)
3026 (widget-apply widget :create)
3027 (widget-value-set widget (car inactive))
3028 (widget-setup)))))
3029
3030 (defun custom-face-edit-delete (widget)
3031 "Remove WIDGET from the buffer."
3032 (let ((inactive (widget-get widget :inactive))
3033 (inhibit-read-only t)
3034 (inhibit-modification-hooks t))
3035 (if (not inactive)
3036 ;; Widget is alive, we don't have to do anything special
3037 (widget-default-delete widget)
3038 ;; WIDGET is already deleted because we did so to inactivate it;
3039 ;; now just get rid of the label we put in its place.
3040 (delete-region (car (cdr inactive))
3041 (+ (car (cdr inactive)) (cdr (cdr inactive))))
3042 (widget-put widget :inactive nil))))
3043
3044
3045 (defun custom-face-edit-attribute-tag (widget)
3046 "Returns the first :tag property in WIDGET or one of its children."
3047 (let ((tag (widget-get widget :tag)))
3048 (or (and (not (equal tag "")) tag)
3049 (let ((children (widget-get widget :children)))
3050 (while (and (null tag) children)
3051 (setq tag (custom-face-edit-attribute-tag (pop children))))
3052 tag))))
3053
3054 ;;; The `custom-display' Widget.
3055
3056 (define-widget 'custom-display 'menu-choice
3057 "Select a display type."
3058 :tag "Display"
3059 :value t
3060 :help-echo "Specify frames where the face attributes should be used."
3061 :args '((const :tag "all" t)
3062 (const :tag "defaults" default)
3063 (checklist
3064 :offset 0
3065 :extra-offset 9
3066 :args ((group :sibling-args (:help-echo "\
3067 Only match the specified window systems.")
3068 (const :format "Type: "
3069 type)
3070 (checklist :inline t
3071 :offset 0
3072 (const :format "X "
3073 :sibling-args (:help-echo "\
3074 The X11 Window System.")
3075 x)
3076 (const :format "PM "
3077 :sibling-args (:help-echo "\
3078 OS/2 Presentation Manager.")
3079 pm)
3080 (const :format "W32 "
3081 :sibling-args (:help-echo "\
3082 Windows NT/9X.")
3083 w32)
3084 (const :format "MAC "
3085 :sibling-args (:help-echo "\
3086 Macintosh OS.")
3087 mac)
3088 (const :format "DOS "
3089 :sibling-args (:help-echo "\
3090 Plain MS-DOS.")
3091 pc)
3092 (const :format "TTY%n"
3093 :sibling-args (:help-echo "\
3094 Plain text terminals.")
3095 tty)))
3096 (group :sibling-args (:help-echo "\
3097 Only match the frames with the specified color support.")
3098 (const :format "Class: "
3099 class)
3100 (checklist :inline t
3101 :offset 0
3102 (const :format "Color "
3103 :sibling-args (:help-echo "\
3104 Match color frames.")
3105 color)
3106 (const :format "Grayscale "
3107 :sibling-args (:help-echo "\
3108 Match grayscale frames.")
3109 grayscale)
3110 (const :format "Monochrome%n"
3111 :sibling-args (:help-echo "\
3112 Match frames with no color support.")
3113 mono)))
3114 (group :sibling-args (:help-echo "\
3115 The minimum number of colors the frame should support.")
3116 (const :format "" min-colors)
3117 (integer :tag "Minimum number of colors" ))
3118 (group :sibling-args (:help-echo "\
3119 Only match frames with the specified intensity.")
3120 (const :format "\
3121 Background brightness: "
3122 background)
3123 (checklist :inline t
3124 :offset 0
3125 (const :format "Light "
3126 :sibling-args (:help-echo "\
3127 Match frames with light backgrounds.")
3128 light)
3129 (const :format "Dark\n"
3130 :sibling-args (:help-echo "\
3131 Match frames with dark backgrounds.")
3132 dark)))
3133 (group :sibling-args (:help-echo "\
3134 Only match frames that support the specified face attributes.")
3135 (const :format "Supports attributes:" supports)
3136 (custom-face-edit :inline t :format "%n%v"))))))
3137
3138 ;;; The `custom-face' Widget.
3139
3140 (defface custom-face-tag
3141 `((t (:weight bold :height 1.2 :inherit variable-pitch)))
3142 "Face used for face tags."
3143 :group 'custom-faces)
3144 ;; backward-compatibility alias
3145 (put 'custom-face-tag-face 'face-alias 'custom-face-tag)
3146
3147 (defcustom custom-face-default-form 'selected
3148 "Default form of displaying face definition."
3149 :type '(choice (const all)
3150 (const selected)
3151 (const lisp))
3152 :group 'custom-buffer
3153 :version "20.3")
3154
3155 (define-widget 'custom-face 'custom
3156 "Customize face."
3157 :sample-face 'custom-face-tag-face
3158 :help-echo "Set or reset this face."
3159 :documentation-property #'face-doc-string
3160 :value-create 'custom-face-value-create
3161 :action 'custom-face-action
3162 :custom-category 'face
3163 :custom-form nil ; defaults to value of `custom-face-default-form'
3164 :custom-set 'custom-face-set
3165 :custom-save 'custom-face-save
3166 :custom-reset-current 'custom-redraw
3167 :custom-reset-saved 'custom-face-reset-saved
3168 :custom-reset-standard 'custom-face-reset-standard
3169 :custom-standard-value 'custom-face-standard-value
3170 :custom-menu 'custom-face-menu-create)
3171
3172 (define-widget 'custom-face-all 'editable-list
3173 "An editable list of display specifications and attributes."
3174 :entry-format "%i %d %v"
3175 :insert-button-args '(:help-echo "Insert new display specification here.")
3176 :append-button-args '(:help-echo "Append new display specification here.")
3177 :delete-button-args '(:help-echo "Delete this display specification.")
3178 :args '((group :format "%v" custom-display custom-face-edit)))
3179
3180 (defconst custom-face-all (widget-convert 'custom-face-all)
3181 "Converted version of the `custom-face-all' widget.")
3182
3183 (define-widget 'custom-display-unselected 'item
3184 "A display specification that doesn't match the selected display."
3185 :match 'custom-display-unselected-match)
3186
3187 (defun custom-display-unselected-match (widget value)
3188 "Non-nil if VALUE is an unselected display specification."
3189 (not (face-spec-set-match-display value (selected-frame))))
3190
3191 (define-widget 'custom-face-selected 'group
3192 "Edit the attributes of the selected display in a face specification."
3193 :args '((choice :inline t
3194 (group :tag "With Defaults" :inline t
3195 (group (const :tag "" default)
3196 (custom-face-edit :tag " Default\n Attributes"))
3197 (repeat :format ""
3198 :inline t
3199 (group custom-display-unselected sexp))
3200 (group (sexp :format "")
3201 (custom-face-edit :tag " Overriding\n Attributes"))
3202 (repeat :format ""
3203 :inline t
3204 sexp))
3205 (group :tag "No Defaults" :inline t
3206 (repeat :format ""
3207 :inline t
3208 (group custom-display-unselected sexp))
3209 (group (sexp :format "")
3210 (custom-face-edit :tag "\n Attributes"))
3211 (repeat :format ""
3212 :inline t
3213 sexp)))))
3214
3215
3216
3217 (defconst custom-face-selected (widget-convert 'custom-face-selected)
3218 "Converted version of the `custom-face-selected' widget.")
3219
3220 (defun custom-filter-face-spec (spec filter-index &optional default-filter)
3221 "Return a canonicalized version of SPEC using.
3222 FILTER-INDEX is the index in the entry for each attribute in
3223 `custom-face-attributes' at which the appropriate filter function can be
3224 found, and DEFAULT-FILTER is the filter to apply for attributes that
3225 don't specify one."
3226 (mapcar (lambda (entry)
3227 ;; Filter a single face-spec entry
3228 (let ((tests (car entry))
3229 (unfiltered-attrs
3230 ;; Handle both old- and new-style attribute syntax
3231 (if (listp (car (cdr entry)))
3232 (car (cdr entry))
3233 (cdr entry)))
3234 (filtered-attrs nil))
3235 ;; Filter each face attribute
3236 (while unfiltered-attrs
3237 (let* ((attr (pop unfiltered-attrs))
3238 (pre-filtered-value (pop unfiltered-attrs))
3239 (filter
3240 (or (nth filter-index (assq attr custom-face-attributes))
3241 default-filter))
3242 (filtered-value
3243 (if filter
3244 (funcall filter pre-filtered-value)
3245 pre-filtered-value)))
3246 (push filtered-value filtered-attrs)
3247 (push attr filtered-attrs)))
3248 ;;
3249 (list tests filtered-attrs)))
3250 spec))
3251
3252 (defun custom-pre-filter-face-spec (spec)
3253 "Return SPEC changed as necessary for editing by the face customization widget.
3254 SPEC must be a full face spec."
3255 (custom-filter-face-spec spec 2))
3256
3257 (defun custom-post-filter-face-spec (spec)
3258 "Return the customized SPEC in a form suitable for setting the face."
3259 (custom-filter-face-spec spec 3))
3260
3261 (defun custom-face-value-create (widget)
3262 "Create a list of the display specifications for WIDGET."
3263 (let ((buttons (widget-get widget :buttons))
3264 children
3265 (symbol (widget-get widget :value))
3266 (tag (widget-get widget :tag))
3267 (state (widget-get widget :custom-state))
3268 (begin (point))
3269 (is-last (widget-get widget :custom-last))
3270 (prefix (widget-get widget :custom-prefix)))
3271 (unless tag
3272 (setq tag (prin1-to-string symbol)))
3273 (cond ((eq custom-buffer-style 'tree)
3274 (insert prefix (if is-last " `--- " " |--- "))
3275 (push (widget-create-child-and-convert
3276 widget 'custom-browse-face-tag)
3277 buttons)
3278 (insert " " tag "\n")
3279 (widget-put widget :buttons buttons))
3280 (t
3281 ;; Create tag.
3282 (insert tag)
3283 (widget-specify-sample widget begin (point))
3284 (if (eq custom-buffer-style 'face)
3285 (insert " ")
3286 (if (string-match "face\\'" tag)
3287 (insert ":")
3288 (insert " face: ")))
3289 ;; Sample.
3290 (push (widget-create-child-and-convert widget 'item
3291 :format "(%{%t%})"
3292 :sample-face symbol
3293 :tag "sample")
3294 buttons)
3295 ;; Visibility.
3296 (insert " ")
3297 (push (widget-create-child-and-convert
3298 widget 'visibility
3299 :help-echo "Hide or show this face."
3300 :on "Hide Face"
3301 :off "Show Face"
3302 :action 'custom-toggle-parent
3303 (not (eq state 'hidden)))
3304 buttons)
3305 ;; Magic.
3306 (insert "\n")
3307 (let ((magic (widget-create-child-and-convert
3308 widget 'custom-magic nil)))
3309 (widget-put widget :custom-magic magic)
3310 (push magic buttons))
3311 ;; Update buttons.
3312 (widget-put widget :buttons buttons)
3313 ;; Insert documentation.
3314 (widget-add-documentation-string-button
3315 widget :visibility-widget 'custom-visibility)
3316
3317 ;; The comment field
3318 (unless (eq state 'hidden)
3319 (let* ((comment (get symbol 'face-comment))
3320 (comment-widget
3321 (widget-create-child-and-convert
3322 widget 'custom-comment
3323 :parent widget
3324 :value (or comment ""))))
3325 (widget-put widget :comment-widget comment-widget)
3326 (push comment-widget children)))
3327 ;; See also.
3328 (unless (eq state 'hidden)
3329 (when (eq (widget-get widget :custom-level) 1)
3330 (custom-add-parent-links widget))
3331 (custom-add-see-also widget))
3332 ;; Editor.
3333 (unless (eq (preceding-char) ?\n)
3334 (insert "\n"))
3335 (unless (eq state 'hidden)
3336 (message "Creating face editor...")
3337 (custom-load-widget widget)
3338 (unless (widget-get widget :custom-form)
3339 (widget-put widget :custom-form custom-face-default-form))
3340 (let* ((symbol (widget-value widget))
3341 (spec (or (get symbol 'customized-face)
3342 (get symbol 'saved-face)
3343 (get symbol 'face-defface-spec)
3344 ;; Attempt to construct it.
3345 (list (list t (custom-face-attributes-get
3346 symbol (selected-frame))))))
3347 (form (widget-get widget :custom-form))
3348 (indent (widget-get widget :indent))
3349 edit)
3350 ;; If the user has changed this face in some other way,
3351 ;; edit it as the user has specified it.
3352 (if (not (face-spec-match-p symbol spec (selected-frame)))
3353 (setq spec (list (list t (face-attr-construct symbol (selected-frame))))))
3354 (setq spec (custom-pre-filter-face-spec spec))
3355 (setq edit (widget-create-child-and-convert
3356 widget
3357 (cond ((and (eq form 'selected)
3358 (widget-apply custom-face-selected
3359 :match spec))
3360 (when indent (insert-char ?\ indent))
3361 'custom-face-selected)
3362 ((and (not (eq form 'lisp))
3363 (widget-apply custom-face-all
3364 :match spec))
3365 'custom-face-all)
3366 (t
3367 (when indent (insert-char ?\ indent))
3368 'sexp))
3369 :value spec))
3370 (custom-face-state-set widget)
3371 (push edit children)
3372 (widget-put widget :children children))
3373 (message "Creating face editor...done"))))))
3374
3375 (defvar custom-face-menu
3376 `(("Set for Current Session" custom-face-set)
3377 ,@(when (or custom-file user-init-file)
3378 '(("Save for Future Sessions" custom-face-save)))
3379 ("Undo Edits" custom-redraw
3380 (lambda (widget)
3381 (memq (widget-get widget :custom-state) '(modified changed))))
3382 ("Reset to Saved" custom-face-reset-saved
3383 (lambda (widget)
3384 (or (get (widget-value widget) 'saved-face)
3385 (get (widget-value widget) 'saved-face-comment))))
3386 ,@(when (or custom-file user-init-file)
3387 '(("Erase Customization" custom-face-reset-standard
3388 (lambda (widget)
3389 (get (widget-value widget) 'face-defface-spec)))))
3390 ("---" ignore ignore)
3391 ("Add Comment" custom-comment-show custom-comment-invisible-p)
3392 ("---" ignore ignore)
3393 ("For Current Display" custom-face-edit-selected
3394 (lambda (widget)
3395 (not (eq (widget-get widget :custom-form) 'selected))))
3396 ("For All Kinds of Displays" custom-face-edit-all
3397 (lambda (widget)
3398 (not (eq (widget-get widget :custom-form) 'all))))
3399 ("Show Lisp Expression" custom-face-edit-lisp
3400 (lambda (widget)
3401 (not (eq (widget-get widget :custom-form) 'lisp)))))
3402 "Alist of actions for the `custom-face' widget.
3403 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3404 the menu entry, ACTION is the function to call on the widget when the
3405 menu is selected, and FILTER is a predicate which takes a `custom-face'
3406 widget as an argument, and returns non-nil if ACTION is valid on that
3407 widget. If FILTER is nil, ACTION is always valid.")
3408
3409 (defun custom-face-edit-selected (widget)
3410 "Edit selected attributes of the value of WIDGET."
3411 (widget-put widget :custom-state 'unknown)
3412 (widget-put widget :custom-form 'selected)
3413 (custom-redraw widget))
3414
3415 (defun custom-face-edit-all (widget)
3416 "Edit all attributes of the value of WIDGET."
3417 (widget-put widget :custom-state 'unknown)
3418 (widget-put widget :custom-form 'all)
3419 (custom-redraw widget))
3420
3421 (defun custom-face-edit-lisp (widget)
3422 "Edit the Lisp representation of the value of WIDGET."
3423 (widget-put widget :custom-state 'unknown)
3424 (widget-put widget :custom-form 'lisp)
3425 (custom-redraw widget))
3426
3427 (defun custom-face-state-set (widget)
3428 "Set the state of WIDGET."
3429 (let* ((symbol (widget-value widget))
3430 (comment (get symbol 'face-comment))
3431 tmp temp
3432 (state
3433 (cond ((progn
3434 (setq tmp (get symbol 'customized-face))
3435 (setq temp (get symbol 'customized-face-comment))
3436 (or tmp temp))
3437 (if (equal temp comment)
3438 'set
3439 'changed))
3440 ((progn
3441 (setq tmp (get symbol 'saved-face))
3442 (setq temp (get symbol 'saved-face-comment))
3443 (or tmp temp))
3444 (if (equal temp comment)
3445 (cond
3446 ((eq 'user (caar (get symbol 'theme-face)))
3447 'saved)
3448 ((eq 'changed (caar (get symbol 'theme-face)))
3449 'changed)
3450 (t 'themed))
3451 'changed))
3452 ((get symbol 'face-defface-spec)
3453 (if (equal comment nil)
3454 'standard
3455 'changed))
3456 (t
3457 'rogue))))
3458 ;; If the user called set-face-attribute to change the default
3459 ;; for new frames, this face is "set outside of Customize".
3460 (if (and (not (eq state 'rogue))
3461 (get symbol 'face-modified))
3462 (setq state 'changed))
3463 (widget-put widget :custom-state state)))
3464
3465 (defun custom-face-action (widget &optional event)
3466 "Show the menu for `custom-face' WIDGET.
3467 Optional EVENT is the location for the menu."
3468 (if (eq (widget-get widget :custom-state) 'hidden)
3469 (custom-toggle-hide widget)
3470 (let* ((completion-ignore-case t)
3471 (symbol (widget-get widget :value))
3472 (answer (widget-choose (concat "Operation on "
3473 (custom-unlispify-tag-name symbol))
3474 (custom-menu-filter custom-face-menu
3475 widget)
3476 event)))
3477 (if answer
3478 (funcall answer widget)))))
3479
3480 (defun custom-face-set (widget)
3481 "Make the face attributes in WIDGET take effect."
3482 (let* ((symbol (widget-value widget))
3483 (child (car (widget-get widget :children)))
3484 (value (custom-post-filter-face-spec (widget-value child)))
3485 (comment-widget (widget-get widget :comment-widget))
3486 (comment (widget-value comment-widget)))
3487 (when (equal comment "")
3488 (setq comment nil)
3489 ;; Make the comment invisible by hand if it's empty
3490 (custom-comment-hide comment-widget))
3491 (put symbol 'customized-face value)
3492 (custom-push-theme 'theme-face symbol 'user 'set value)
3493 (if (face-spec-choose value)
3494 (face-spec-set symbol value)
3495 ;; face-set-spec ignores empty attribute lists, so just give it
3496 ;; something harmless instead.
3497 (face-spec-set symbol '((t :foreground unspecified))))
3498 (put symbol 'customized-face-comment comment)
3499 (put symbol 'face-comment comment)
3500 (custom-face-state-set widget)
3501 (custom-redraw-magic widget)))
3502
3503 (defun custom-face-save (widget)
3504 "Save in `.emacs' the face attributes in WIDGET."
3505 (let* ((symbol (widget-value widget))
3506 (child (car (widget-get widget :children)))
3507 (value (custom-post-filter-face-spec (widget-value child)))
3508 (comment-widget (widget-get widget :comment-widget))
3509 (comment (widget-value comment-widget)))
3510 (when (equal comment "")
3511 (setq comment nil)
3512 ;; Make the comment invisible by hand if it's empty
3513 (custom-comment-hide comment-widget))
3514 (custom-push-theme 'theme-face symbol 'user 'set value)
3515 (if (face-spec-choose value)
3516 (face-spec-set symbol value)
3517 ;; face-set-spec ignores empty attribute lists, so just give it
3518 ;; something harmless instead.
3519 (face-spec-set symbol '((t :foreground unspecified))))
3520 (unless (eq (widget-get widget :custom-state) 'standard)
3521 (put symbol 'saved-face value))
3522 (put symbol 'customized-face nil)
3523 (put symbol 'face-comment comment)
3524 (put symbol 'customized-face-comment nil)
3525 (put symbol 'saved-face-comment comment)
3526 (custom-save-all)
3527 (custom-face-state-set widget)
3528 (custom-redraw-magic widget)))
3529
3530 ;; For backward compatibility.
3531 (define-obsolete-function-alias 'custom-face-save-command 'custom-face-save
3532 "22.1")
3533
3534 (defun custom-face-reset-saved (widget)
3535 "Restore WIDGET to the face's default attributes."
3536 (let* ((symbol (widget-value widget))
3537 (child (car (widget-get widget :children)))
3538 (value (get symbol 'saved-face))
3539 (comment (get symbol 'saved-face-comment))
3540 (comment-widget (widget-get widget :comment-widget)))
3541 (unless (or value comment)
3542 (error "No saved value for this face"))
3543 (put symbol 'customized-face nil)
3544 (put symbol 'customized-face-comment nil)
3545 (custom-push-theme 'theme-face symbol 'user 'set value)
3546 (face-spec-set symbol value)
3547 (put symbol 'face-comment comment)
3548 (widget-value-set child value)
3549 ;; This call manages the comment visibility
3550 (widget-value-set comment-widget (or comment ""))
3551 (custom-face-state-set widget)
3552 (custom-redraw-magic widget)))
3553
3554 (defun custom-face-standard-value (widget)
3555 (get (widget-value widget) 'face-defface-spec))
3556
3557 (defun custom-face-reset-standard (widget)
3558 "Restore WIDGET to the face's standard attribute values.
3559 This operation eliminates any saved attributes for the face,
3560 restoring it to the state of a face that has never been customized."
3561 (let* ((symbol (widget-value widget))
3562 (child (car (widget-get widget :children)))
3563 (value (get symbol 'face-defface-spec))
3564 (comment-widget (widget-get widget :comment-widget)))
3565 (unless value
3566 (error "No standard setting for this face"))
3567 (put symbol 'customized-face nil)
3568 (put symbol 'customized-face-comment nil)
3569 (custom-push-theme 'theme-face symbol 'user 'reset)
3570 (face-spec-set symbol value)
3571 (custom-theme-recalc-face symbol)
3572 (when (or (get symbol 'saved-face) (get symbol 'saved-face-comment))
3573 (put symbol 'saved-face nil)
3574 (put symbol 'saved-face-comment nil)
3575 (custom-save-all))
3576 (put symbol 'face-comment nil)
3577 (widget-value-set child
3578 (custom-pre-filter-face-spec
3579 (list (list t (custom-face-attributes-get
3580 symbol nil)))))
3581 ;; This call manages the comment visibility
3582 (widget-value-set comment-widget "")
3583 (custom-face-state-set widget)
3584 (custom-redraw-magic widget)))
3585
3586 ;;; The `face' Widget.
3587
3588 (defvar widget-face-prompt-value-history nil
3589 "History of input to `widget-face-prompt-value'.")
3590
3591 (define-widget 'face 'symbol
3592 "A Lisp face name (with sample)."
3593 :format "%{%t%}: (%{sample%}) %v"
3594 :tag "Face"
3595 :value 'default
3596 :sample-face-get 'widget-face-sample-face-get
3597 :notify 'widget-face-notify
3598 :match (lambda (widget value) (facep value))
3599 :complete-function (lambda ()
3600 (interactive)
3601 (lisp-complete-symbol 'facep))
3602 :prompt-match 'facep
3603 :prompt-history 'widget-face-prompt-value-history
3604 :validate (lambda (widget)
3605 (unless (facep (widget-value widget))
3606 (widget-put widget
3607 :error (format "Invalid face: %S"
3608 (widget-value widget)))
3609 widget)))
3610
3611 (defun widget-face-sample-face-get (widget)
3612 (let ((value (widget-value widget)))
3613 (if (facep value)
3614 value
3615 'default)))
3616
3617 (defun widget-face-notify (widget child &optional event)
3618 "Update the sample, and notify the parent."
3619 (overlay-put (widget-get widget :sample-overlay)
3620 'face (widget-apply widget :sample-face-get))
3621 (widget-default-notify widget child event))
3622
3623
3624 ;;; The `hook' Widget.
3625
3626 (define-widget 'hook 'list
3627 "An Emacs Lisp hook."
3628 :value-to-internal (lambda (widget value)
3629 (if (and value (symbolp value))
3630 (list value)
3631 value))
3632 :match (lambda (widget value)
3633 (or (symbolp value)
3634 (widget-group-match widget value)))
3635 ;; Avoid adding undefined functions to the hook, especially for
3636 ;; things like `find-file-hook' or even more basic ones, to avoid
3637 ;; chaos.
3638 :set (lambda (symbol value)
3639 (dolist (elt value)
3640 (if (fboundp elt)
3641 (add-hook symbol elt))))
3642 :convert-widget 'custom-hook-convert-widget
3643 :tag "Hook")
3644
3645 (defun custom-hook-convert-widget (widget)
3646 ;; Handle `:options'.
3647 (let* ((options (widget-get widget :options))
3648 (other `(editable-list :inline t
3649 :entry-format "%i %d%v"
3650 (function :format " %v")))
3651 (args (if options
3652 (list `(checklist :inline t
3653 ,@(mapcar (lambda (entry)
3654 `(function-item ,entry))
3655 options))
3656 other)
3657 (list other))))
3658 (widget-put widget :args args)
3659 widget))
3660
3661 ;;; The `custom-group-link' Widget.
3662
3663 (define-widget 'custom-group-link 'link
3664 "Show parent in other window when activated."
3665 :button-face 'custom-link
3666 :mouse-face 'highlight
3667 :pressed-face 'highlight
3668 :help-echo "Create customization buffer for this group."
3669 :keymap custom-mode-link-map
3670 :follow-link 'mouse-face
3671 :action 'custom-group-link-action)
3672
3673 (defun custom-group-link-action (widget &rest ignore)
3674 (customize-group (widget-value widget)))
3675
3676 ;;; The `custom-group' Widget.
3677
3678 (defcustom custom-group-tag-faces nil
3679 ;; In XEmacs, this ought to play games with font size.
3680 ;; Fixme: make it do so in Emacs.
3681 "Face used for group tags.
3682 The first member is used for level 1 groups, the second for level 2,
3683 and so forth. The remaining group tags are shown with `custom-group-tag'."
3684 :type '(repeat face)
3685 :group 'custom-faces)
3686
3687 (defface custom-group-tag-1
3688 `((((class color)
3689 (background dark))
3690 (:foreground "pink" :weight bold :height 1.2 :inherit variable-pitch))
3691 (((min-colors 88) (class color)
3692 (background light))
3693 (:foreground "red1" :weight bold :height 1.2 :inherit variable-pitch))
3694 (((class color)
3695 (background light))
3696 (:foreground "red" :weight bold :height 1.2 :inherit variable-pitch))
3697 (t (:weight bold)))
3698 "Face used for group tags."
3699 :group 'custom-faces)
3700 ;; backward-compatibility alias
3701 (put 'custom-group-tag-face-1 'face-alias 'custom-group-tag-1)
3702
3703 (defface custom-group-tag
3704 `((((class color)
3705 (background dark))
3706 (:foreground "light blue" :weight bold :height 1.2 :inherit variable-pitch))
3707 (((min-colors 88) (class color)
3708 (background light))
3709 (:foreground "blue1" :weight bold :height 1.2 :inherit variable-pitch))
3710 (((class color)
3711 (background light))
3712 (:foreground "blue" :weight bold :height 1.2 :inherit variable-pitch))
3713 (t (:weight bold)))
3714 "Face used for low level group tags."
3715 :group 'custom-faces)
3716 ;; backward-compatibility alias
3717 (put 'custom-group-tag-face 'face-alias 'custom-group-tag)
3718
3719 (define-widget 'custom-group 'custom
3720 "Customize group."
3721 :format "%v"
3722 :sample-face-get 'custom-group-sample-face-get
3723 :documentation-property 'group-documentation
3724 :help-echo "Set or reset all members of this group."
3725 :value-create 'custom-group-value-create
3726 :action 'custom-group-action
3727 :custom-category 'group
3728 :custom-set 'custom-group-set
3729 :custom-save 'custom-group-save
3730 :custom-reset-current 'custom-group-reset-current
3731 :custom-reset-saved 'custom-group-reset-saved
3732 :custom-reset-standard 'custom-group-reset-standard
3733 :custom-menu 'custom-group-menu-create)
3734
3735 (defun custom-group-sample-face-get (widget)
3736 ;; Use :sample-face.
3737 (or (nth (1- (widget-get widget :custom-level)) custom-group-tag-faces)
3738 'custom-group-tag))
3739
3740 (define-widget 'custom-group-visibility 'visibility
3741 "An indicator and manipulator for hidden group contents."
3742 :create 'custom-group-visibility-create)
3743
3744 (defun custom-group-visibility-create (widget)
3745 (let ((visible (widget-value widget)))
3746 (if visible
3747 (insert "--------")))
3748 (widget-default-create widget))
3749
3750 (defun custom-group-members (symbol groups-only)
3751 "Return SYMBOL's custom group members.
3752 If GROUPS-ONLY non-nil, return only those members that are groups."
3753 (if (not groups-only)
3754 (get symbol 'custom-group)
3755 (let (members)
3756 (dolist (entry (get symbol 'custom-group))
3757 (when (eq (nth 1 entry) 'custom-group)
3758 (push entry members)))
3759 (nreverse members))))
3760
3761 (defun custom-group-value-create (widget)
3762 "Insert a customize group for WIDGET in the current buffer."
3763 (unless (eq (widget-get widget :custom-state) 'hidden)
3764 (custom-load-widget widget))
3765 (let* ((state (widget-get widget :custom-state))
3766 (level (widget-get widget :custom-level))
3767 ;; (indent (widget-get widget :indent))
3768 (prefix (widget-get widget :custom-prefix))
3769 (buttons (widget-get widget :buttons))
3770 (tag (widget-get widget :tag))
3771 (symbol (widget-value widget))
3772 (members (custom-group-members symbol
3773 (and (eq custom-buffer-style 'tree)
3774 custom-browse-only-groups))))
3775 (cond ((and (eq custom-buffer-style 'tree)
3776 (eq state 'hidden)
3777 (or members (custom-unloaded-widget-p widget)))
3778 (custom-browse-insert-prefix prefix)
3779 (push (widget-create-child-and-convert
3780 widget 'custom-browse-visibility
3781 ;; :tag-glyph "plus"
3782 :tag "+")
3783 buttons)
3784 (insert "-- ")
3785 ;; (widget-glyph-insert nil "-- " "horizontal")
3786 (push (widget-create-child-and-convert
3787 widget 'custom-browse-group-tag)
3788 buttons)
3789 (insert " " tag "\n")
3790 (widget-put widget :buttons buttons))
3791 ((and (eq custom-buffer-style 'tree)
3792 (zerop (length members)))
3793 (custom-browse-insert-prefix prefix)
3794 (insert "[ ]-- ")
3795 ;; (widget-glyph-insert nil "[ ]" "empty")
3796 ;; (widget-glyph-insert nil "-- " "horizontal")
3797 (push (widget-create-child-and-convert
3798 widget 'custom-browse-group-tag)
3799 buttons)
3800 (insert " " tag "\n")
3801 (widget-put widget :buttons buttons))
3802 ((eq custom-buffer-style 'tree)
3803 (custom-browse-insert-prefix prefix)
3804 (if (zerop (length members))
3805 (progn
3806 (custom-browse-insert-prefix prefix)
3807 (insert "[ ]-- ")
3808 ;; (widget-glyph-insert nil "[ ]" "empty")
3809 ;; (widget-glyph-insert nil "-- " "horizontal")
3810 (push (widget-create-child-and-convert
3811 widget 'custom-browse-group-tag)
3812 buttons)
3813 (insert " " tag "\n")
3814 (widget-put widget :buttons buttons))
3815 (push (widget-create-child-and-convert
3816 widget 'custom-browse-visibility
3817 ;; :tag-glyph "minus"
3818 :tag "-")
3819 buttons)
3820 (insert "-\\ ")
3821 ;; (widget-glyph-insert nil "-\\ " "top")
3822 (push (widget-create-child-and-convert
3823 widget 'custom-browse-group-tag)
3824 buttons)
3825 (insert " " tag "\n")
3826 (widget-put widget :buttons buttons)
3827 (message "Creating group...")
3828 (let* ((members (custom-sort-items members
3829 custom-browse-sort-alphabetically
3830 custom-browse-order-groups))
3831 (prefixes (widget-get widget :custom-prefixes))
3832 (custom-prefix-list (custom-prefix-add symbol prefixes))
3833 (extra-prefix (if (widget-get widget :custom-last)
3834 " "
3835 " | "))
3836 (prefix (concat prefix extra-prefix))
3837 children entry)
3838 (while members
3839 (setq entry (car members)
3840 members (cdr members))
3841 (push (widget-create-child-and-convert
3842 widget (nth 1 entry)
3843 :group widget
3844 :tag (custom-unlispify-tag-name (nth 0 entry))
3845 :custom-prefixes custom-prefix-list
3846 :custom-level (1+ level)
3847 :custom-last (null members)
3848 :value (nth 0 entry)
3849 :custom-prefix prefix)
3850 children))
3851 (widget-put widget :children (reverse children)))
3852 (message "Creating group...done")))
3853 ;; Nested style.
3854 ((eq state 'hidden)
3855 ;; Create level indicator.
3856 ;; Create tag.
3857 (if (eq custom-buffer-style 'links)
3858 (push (widget-create-child-and-convert
3859 widget 'custom-group-link
3860 :tag tag
3861 symbol)
3862 buttons)
3863 (insert-char ?\ (* custom-buffer-indent (1- level)))
3864 (insert "-- ")
3865 (push (widget-create-child-and-convert
3866 widget 'custom-group-visibility
3867 :help-echo "Show members of this group."
3868 :action 'custom-toggle-parent
3869 (not (eq state 'hidden)))
3870 buttons))
3871 (insert " : ")
3872 ;; Create magic button.
3873 (let ((magic (widget-create-child-and-convert
3874 widget 'custom-magic nil)))
3875 (widget-put widget :custom-magic magic)
3876 (push magic buttons))
3877 ;; Update buttons.
3878 (widget-put widget :buttons buttons)
3879 ;; Insert documentation.
3880 (if (and (eq custom-buffer-style 'links) (> level 1))
3881 (widget-put widget :documentation-indent 0))
3882 (widget-add-documentation-string-button
3883 widget :visibility-widget 'custom-visibility))
3884
3885 ;; Nested style.
3886 (t ;Visible.
3887 ;; Add parent groups references above the group.
3888 (if t ;;; This should test that the buffer
3889 ;;; was made to display a group.
3890 (when (eq level 1)
3891 (if (custom-add-parent-links widget
3892 "Parent group:")
3893 (insert "\n"))))
3894 ;; Create level indicator.
3895 (insert-char ?\ (* custom-buffer-indent (1- level)))
3896 (insert "/- ")
3897 ;; Create tag.
3898 (let ((start (point)))
3899 (insert tag " group: ")
3900 (widget-specify-sample widget start (point)))
3901 (insert (widget-docstring widget))
3902 ;; Create visibility indicator.
3903 (unless (eq custom-buffer-style 'links)
3904 (insert "--------")
3905 (push (widget-create-child-and-convert
3906 widget 'visibility
3907 :help-echo "Hide members of this group."
3908 :action 'custom-toggle-parent
3909 (not (eq state 'hidden)))
3910 buttons)
3911 (insert " "))
3912 ;; Create more dashes.
3913 ;; Use 76 instead of 75 to compensate for the temporary "<"
3914 ;; added by `widget-insert'.
3915 (insert-char ?- (- 76 (current-column)
3916 (* custom-buffer-indent level)))
3917 (insert "\\\n")
3918 ;; Create magic button.
3919 (let ((magic (widget-create-child-and-convert
3920 widget 'custom-magic
3921 :indent 0
3922 nil)))
3923 (widget-put widget :custom-magic magic)
3924 (push magic buttons))
3925 ;; Update buttons.
3926 (widget-put widget :buttons buttons)
3927 ;; Insert documentation.
3928 (widget-add-documentation-string-button
3929 widget :visibility-widget 'custom-visibility)
3930
3931 ;; Parent groups.
3932 (if nil ;;; This should test that the buffer
3933 ;;; was not made to display a group.
3934 (when (eq level 1)
3935 (insert-char ?\ custom-buffer-indent)
3936 (custom-add-parent-links widget)))
3937 (custom-add-see-also widget
3938 (make-string (* custom-buffer-indent level)
3939 ?\ ))
3940 ;; Members.
3941 (message "Creating group...")
3942 (let* ((members (custom-sort-items members
3943 custom-buffer-sort-alphabetically
3944 custom-buffer-order-groups))
3945 (prefixes (widget-get widget :custom-prefixes))
3946 (custom-prefix-list (custom-prefix-add symbol prefixes))
3947 (length (length members))
3948 (count 0)
3949 (children (mapcar (lambda (entry)
3950 (widget-insert "\n")
3951 (message "\
3952 Creating group members... %2d%%"
3953 (/ (* 100.0 count) length))
3954 (setq count (1+ count))
3955 (prog1
3956 (widget-create-child-and-convert
3957 widget (nth 1 entry)
3958 :group widget
3959 :tag (custom-unlispify-tag-name
3960 (nth 0 entry))
3961 :custom-prefixes custom-prefix-list
3962 :custom-level (1+ level)
3963 :value (nth 0 entry))
3964 (unless (eq (preceding-char) ?\n)
3965 (widget-insert "\n"))))
3966 members)))
3967 (message "Creating group magic...")
3968 (mapc 'custom-magic-reset children)
3969 (message "Creating group state...")
3970 (widget-put widget :children children)
3971 (custom-group-state-update widget)
3972 (message "Creating group... done"))
3973 ;; End line
3974 (insert "\n")
3975 (insert-char ?\ (* custom-buffer-indent (1- level)))
3976 (insert "\\- " (widget-get widget :tag) " group end ")
3977 (insert-char ?- (- 75 (current-column) (* custom-buffer-indent level)))
3978 (insert "/\n")))))
3979
3980 (defvar custom-group-menu
3981 `(("Set for Current Session" custom-group-set
3982 (lambda (widget)
3983 (eq (widget-get widget :custom-state) 'modified)))
3984 ,@(when (or custom-file user-init-file)
3985 '(("Save for Future Sessions" custom-group-save
3986 (lambda (widget)
3987 (memq (widget-get widget :custom-state) '(modified set))))))
3988 ("Undo Edits" custom-group-reset-current
3989 (lambda (widget)
3990 (memq (widget-get widget :custom-state) '(modified))))
3991 ("Reset to Saved" custom-group-reset-saved
3992 (lambda (widget)
3993 (memq (widget-get widget :custom-state) '(modified set))))
3994 ,@(when (or custom-file user-init-file)
3995 '(("Erase Customization" custom-group-reset-standard
3996 (lambda (widget)
3997 (memq (widget-get widget :custom-state) '(modified set saved)))))))
3998 "Alist of actions for the `custom-group' widget.
3999 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
4000 the menu entry, ACTION is the function to call on the widget when the
4001 menu is selected, and FILTER is a predicate which takes a `custom-group'
4002 widget as an argument, and returns non-nil if ACTION is valid on that
4003 widget. If FILTER is nil, ACTION is always valid.")
4004
4005 (defun custom-group-action (widget &optional event)
4006 "Show the menu for `custom-group' WIDGET.
4007 Optional EVENT is the location for the menu."
4008 (if (eq (widget-get widget :custom-state) 'hidden)
4009 (custom-toggle-hide widget)
4010 (let* ((completion-ignore-case t)
4011 (answer (widget-choose (concat "Operation on "
4012 (custom-unlispify-tag-name
4013 (widget-get widget :value)))
4014 (custom-menu-filter custom-group-menu
4015 widget)
4016 event)))
4017 (if answer
4018 (funcall answer widget)))))
4019
4020 (defun custom-group-set (widget)
4021 "Set changes in all modified group members."
4022 (dolist (child (widget-get widget :children))
4023 (when (eq (widget-get child :custom-state) 'modified)
4024 (widget-apply child :custom-set))))
4025
4026 (defun custom-group-save (widget)
4027 "Save all modified group members."
4028 (dolist (child (children (widget-get widget :children)))
4029 (when (memq (widget-get child :custom-state) '(modified set))
4030 (widget-apply child :custom-save))))
4031
4032 (defun custom-group-reset-current (widget)
4033 "Reset all modified group members."
4034 (dolist (child (widget-get widget :children))
4035 (when (eq (widget-get child :custom-state) 'modified)
4036 (widget-apply child :custom-reset-current))))
4037
4038 (defun custom-group-reset-saved (widget)
4039 "Reset all modified or set group members."
4040 (dolist (child (widget-get widget :children))
4041 (when (memq (widget-get child :custom-state) '(modified set))
4042 (widget-apply child :custom-reset-saved))))
4043
4044 (defun custom-group-reset-standard (widget)
4045 "Reset all modified, set, or saved group members."
4046 (dolist (child (widget-get widget :children))
4047 (when (memq (widget-get child :custom-state)
4048 '(modified set saved))
4049 (widget-apply child :custom-reset-standard))))
4050
4051 (defun custom-group-state-update (widget)
4052 "Update magic."
4053 (unless (eq (widget-get widget :custom-state) 'hidden)
4054 (let* ((children (widget-get widget :children))
4055 (states (mapcar (lambda (child)
4056 (widget-get child :custom-state))
4057 children))
4058 (magics custom-magic-alist)
4059 (found 'standard))
4060 (while magics
4061 (let ((magic (car (car magics))))
4062 (if (and (not (eq magic 'hidden))
4063 (memq magic states))
4064 (setq found magic
4065 magics nil)
4066 (setq magics (cdr magics)))))
4067 (widget-put widget :custom-state found)))
4068 (custom-magic-reset widget))
4069 \f
4070 ;;; Reading and writing the custom file.
4071
4072 ;;;###autoload
4073 (defcustom custom-file nil
4074 "File used for storing customization information.
4075 The default is nil, which means to use your init file
4076 as specified by `user-init-file'. If the value is not nil,
4077 it should be an absolute file name.
4078
4079 You can set this option through Custom, if you carefully read the
4080 last paragraph below. However, usually it is simpler to write
4081 something like the following in your init file:
4082
4083 \(setq custom-file \"~/.emacs-custom.el\")
4084 \(load custom-file)
4085
4086 Note that both lines are necessary: the first line tells Custom to
4087 save all customizations in this file, but does not load it.
4088
4089 When you change this variable outside Custom, look in the
4090 previous custom file \(usually your init file) for the
4091 forms `(custom-set-variables ...)' and `(custom-set-faces ...)',
4092 and copy them (whichever ones you find) to the new custom file.
4093 This will preserve your existing customizations.
4094
4095 If you save this option using Custom, Custom will write all
4096 currently saved customizations, including the new one for this
4097 option itself, into the file you specify, overwriting any
4098 `custom-set-variables' and `custom-set-faces' forms already
4099 present in that file. It will not delete any customizations from
4100 the old custom file. You should do that manually if that is what you
4101 want. You also have to put something like `\(load \"CUSTOM-FILE\")
4102 in your init file, where CUSTOM-FILE is the actual name of the
4103 file. Otherwise, Emacs will not load the file when it starts up,
4104 and hence will not set `custom-file' to that file either."
4105 :type '(choice (const :tag "Your Emacs init file" nil)
4106 (file :format "%t:%v%d"
4107 :doc
4108 "Please read entire docstring below before setting \
4109 this through Custom.
4110 Click om \"More\" \(or position point there and press RETURN)
4111 if only the first line of the docstring is shown."))
4112 :group 'customize)
4113
4114 (defun custom-file ()
4115 "Return the file name for saving customizations."
4116 (file-chase-links
4117 (or custom-file
4118 (let ((user-init-file user-init-file)
4119 (default-init-file
4120 (if (eq system-type 'ms-dos) "~/_emacs" "~/.emacs")))
4121 (when (null user-init-file)
4122 (if (or (file-exists-p default-init-file)
4123 (and (eq system-type 'windows-nt)
4124 (file-exists-p "~/_emacs")))
4125 ;; Started with -q, i.e. the file containing
4126 ;; Custom settings hasn't been read. Saving
4127 ;; settings there would overwrite other settings.
4128 (error "Saving settings from \"emacs -q\" would overwrite existing customizations"))
4129 (setq user-init-file default-init-file))
4130 user-init-file))))
4131
4132 ;;;###autoload
4133 (defun custom-save-all ()
4134 "Save all customizations in `custom-file'."
4135 (when (and (null custom-file) init-file-had-error)
4136 (error "Cannot save customizations; init file was not fully loaded"))
4137 (let* ((filename (custom-file))
4138 (recentf-exclude
4139 (if recentf-mode
4140 (cons (concat "\\`"
4141 (regexp-quote
4142 (recentf-expand-file-name (custom-file)))
4143 "\\'")
4144 recentf-exclude)))
4145 (old-buffer (find-buffer-visiting filename)))
4146 (with-current-buffer (let ((find-file-visit-truename t))
4147 (or old-buffer (find-file-noselect filename)))
4148 (unless (eq major-mode 'emacs-lisp-mode)
4149 (emacs-lisp-mode))
4150 (let ((inhibit-read-only t))
4151 (custom-save-variables)
4152 (custom-save-faces))
4153 (let ((file-precious-flag t))
4154 (save-buffer))
4155 (unless old-buffer
4156 (kill-buffer (current-buffer))))))
4157
4158 ;;;###autoload
4159 (defun customize-save-customized ()
4160 "Save all user options which have been set in this session."
4161 (interactive)
4162 (mapatoms (lambda (symbol)
4163 (let ((face (get symbol 'customized-face))
4164 (value (get symbol 'customized-value))
4165 (face-comment (get symbol 'customized-face-comment))
4166 (variable-comment
4167 (get symbol 'customized-variable-comment)))
4168 (when face
4169 (put symbol 'saved-face face)
4170 (custom-push-theme 'theme-face symbol 'user 'set value)
4171 (put symbol 'customized-face nil))
4172 (when value
4173 (put symbol 'saved-value value)
4174 (custom-push-theme 'theme-value symbol 'user 'set value)
4175 (put symbol 'customized-value nil))
4176 (when variable-comment
4177 (put symbol 'saved-variable-comment variable-comment)
4178 (put symbol 'customized-variable-comment nil))
4179 (when face-comment
4180 (put symbol 'saved-face-comment face-comment)
4181 (put symbol 'customized-face-comment nil)))))
4182 ;; We really should update all custom buffers here.
4183 (custom-save-all))
4184 \f
4185 ;; Editing the custom file contents in a buffer.
4186
4187 (defun custom-save-delete (symbol)
4188 "Delete all calls to SYMBOL from the contents of the current buffer.
4189 Leave point at the old location of the first such call,
4190 or (if there were none) at the end of the buffer.
4191
4192 This function does not save the buffer."
4193 (goto-char (point-min))
4194 ;; Skip all whitespace and comments.
4195 (while (forward-comment 1))
4196 (or (eobp)
4197 (save-excursion (forward-sexp (buffer-size)))) ; Test for scan errors.
4198 (let (first)
4199 (catch 'found
4200 (while t ;; We exit this loop only via throw.
4201 ;; Skip all whitespace and comments.
4202 (while (forward-comment 1))
4203 (let ((start (point))
4204 (sexp (condition-case nil
4205 (read (current-buffer))
4206 (end-of-file (throw 'found nil)))))
4207 (when (and (listp sexp)
4208 (eq (car sexp) symbol))
4209 (delete-region start (point))
4210 (unless first
4211 (setq first (point)))))))
4212 (if first
4213 (goto-char first)
4214 ;; Move in front of local variables, otherwise long Custom
4215 ;; entries would make them ineffective.
4216 (let ((pos (point-max))
4217 (case-fold-search t))
4218 (save-excursion
4219 (goto-char (point-max))
4220 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
4221 'move)
4222 (when (search-forward "Local Variables:" nil t)
4223 (setq pos (line-beginning-position))))
4224 (goto-char pos)))))
4225
4226 (defun custom-save-variables ()
4227 "Save all customized variables in `custom-file'."
4228 (save-excursion
4229 (custom-save-delete 'custom-set-variables)
4230 (let ((standard-output (current-buffer))
4231 (saved-list (make-list 1 0))
4232 sort-fold-case)
4233 ;; First create a sorted list of saved variables.
4234 (mapatoms
4235 (lambda (symbol)
4236 (if (and (get symbol 'saved-value)
4237 ;; ignore theme values
4238 (or (null (get symbol 'theme-value))
4239 (eq 'user (caar (get symbol 'theme-value)))))
4240 (nconc saved-list (list symbol)))))
4241 (setq saved-list (sort (cdr saved-list) 'string<))
4242 (unless (bolp)
4243 (princ "\n"))
4244 (princ "(custom-set-variables
4245 ;; custom-set-variables was added by Custom.
4246 ;; If you edit it by hand, you could mess it up, so be careful.
4247 ;; Your init file should contain only one such instance.
4248 ;; If there is more than one, they won't work right.\n")
4249 (dolist (symbol saved-list)
4250 (let ((spec (car-safe (get symbol 'theme-value)))
4251 (value (get symbol 'saved-value))
4252 (requests (get symbol 'custom-requests))
4253 (now (and (not (custom-variable-p symbol))
4254 (or (boundp symbol)
4255 (eq (get symbol 'force-value)
4256 'rogue))))
4257 (comment (get symbol 'saved-variable-comment)))
4258 ;; Check REQUESTS for validity.
4259 (dolist (request requests)
4260 (when (and (symbolp request) (not (featurep request)))
4261 (message "Unknown requested feature: %s" request)
4262 (setq requests (delq request requests))))
4263 ;; Is there anything customized about this variable?
4264 (when (or (and spec (eq (car spec) 'user))
4265 comment
4266 (and (null spec) (get symbol 'saved-value)))
4267 ;; Output an element for this variable.
4268 ;; It has the form (SYMBOL VALUE-FORM NOW REQUESTS COMMENT).
4269 ;; SYMBOL is the variable name.
4270 ;; VALUE-FORM is an expression to return the customized value.
4271 ;; NOW if non-nil means always set the variable immediately
4272 ;; when the customizations are reloaded. This is used
4273 ;; for rogue variables
4274 ;; REQUESTS is a list of packages to load before setting the
4275 ;; variable. Each element of it will be passed to `require'.
4276 ;; COMMENT is whatever comment the user has specified
4277 ;; with the customize facility.
4278 (unless (bolp)
4279 (princ "\n"))
4280 (princ " '(")
4281 (prin1 symbol)
4282 (princ " ")
4283 (prin1 (car value))
4284 (when (or now requests comment)
4285 (princ " ")
4286 (prin1 now)
4287 (when (or requests comment)
4288 (princ " ")
4289 (prin1 requests)
4290 (when comment
4291 (princ " ")
4292 (prin1 comment))))
4293 (princ ")"))))
4294 (if (bolp)
4295 (princ " "))
4296 (princ ")")
4297 (unless (looking-at "\n")
4298 (princ "\n")))))
4299
4300 (defun custom-save-faces ()
4301 "Save all customized faces in `custom-file'."
4302 (save-excursion
4303 (custom-save-delete 'custom-reset-faces)
4304 (custom-save-delete 'custom-set-faces)
4305 (let ((standard-output (current-buffer))
4306 (saved-list (make-list 1 0))
4307 sort-fold-case)
4308 ;; First create a sorted list of saved faces.
4309 (mapatoms
4310 (lambda (symbol)
4311 (if (and (get symbol 'saved-face)
4312 (eq 'user (car (car-safe (get symbol 'theme-face)))))
4313 (nconc saved-list (list symbol)))))
4314 (setq saved-list (sort (cdr saved-list) 'string<))
4315 ;; The default face must be first, since it affects the others.
4316 (if (memq 'default saved-list)
4317 (setq saved-list (cons 'default (delq 'default saved-list))))
4318 (unless (bolp)
4319 (princ "\n"))
4320 (princ "(custom-set-faces
4321 ;; custom-set-faces was added by Custom.
4322 ;; If you edit it by hand, you could mess it up, so be careful.
4323 ;; Your init file should contain only one such instance.
4324 ;; If there is more than one, they won't work right.\n")
4325 (dolist (symbol saved-list)
4326 (let ((spec (car-safe (get symbol 'theme-face)))
4327 (value (get symbol 'saved-face))
4328 (now (not (or (get symbol 'face-defface-spec)
4329 (and (not (custom-facep symbol))
4330 (not (get symbol 'force-face))))))
4331 (comment (get symbol 'saved-face-comment)))
4332 (when (or (and spec (eq (nth 0 spec) 'user))
4333 comment
4334 (and (null spec) (get symbol 'saved-face)))
4335 ;; Don't print default face here.
4336 (unless (bolp)
4337 (princ "\n"))
4338 (princ " '(")
4339 (prin1 symbol)
4340 (princ " ")
4341 (prin1 value)
4342 (when (or now comment)
4343 (princ " ")
4344 (prin1 now)
4345 (when comment
4346 (princ " ")
4347 (prin1 comment)))
4348 (princ ")"))))
4349 (if (bolp)
4350 (princ " "))
4351 (princ ")")
4352 (unless (looking-at "\n")
4353 (princ "\n")))))
4354 \f
4355 ;;; The Customize Menu.
4356
4357 ;;; Menu support
4358
4359 (defcustom custom-menu-nesting 2
4360 "Maximum nesting in custom menus."
4361 :type 'integer
4362 :group 'custom-menu)
4363
4364 (defun custom-face-menu-create (widget symbol)
4365 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
4366 (vector (custom-unlispify-menu-entry symbol)
4367 `(customize-face ',symbol)
4368 t))
4369
4370 (defun custom-variable-menu-create (widget symbol)
4371 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
4372 (let ((type (get symbol 'custom-type)))
4373 (unless (listp type)
4374 (setq type (list type)))
4375 (if (and type (widget-get type :custom-menu))
4376 (widget-apply type :custom-menu symbol)
4377 (vector (custom-unlispify-menu-entry symbol)
4378 `(customize-variable ',symbol)
4379 t))))
4380
4381 ;; Add checkboxes to boolean variable entries.
4382 (widget-put (get 'boolean 'widget-type)
4383 :custom-menu (lambda (widget symbol)
4384 (vector (custom-unlispify-menu-entry symbol)
4385 `(customize-variable ',symbol)
4386 ':style 'toggle
4387 ':selected symbol)))
4388
4389 (defun custom-group-menu-create (widget symbol)
4390 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
4391 `( ,(custom-unlispify-menu-entry symbol t)
4392 :filter (lambda (&rest junk)
4393 (let* ((menu (custom-menu-create ',symbol)))
4394 (if (consp menu) (cdr menu) menu)))))
4395
4396 ;;;###autoload
4397 (defun custom-menu-create (symbol)
4398 "Create menu for customization group SYMBOL.
4399 The menu is in a format applicable to `easy-menu-define'."
4400 (let* ((deactivate-mark nil)
4401 (item (vector (custom-unlispify-menu-entry symbol)
4402 `(customize-group ',symbol)
4403 t)))
4404 (if (and (or (not (boundp 'custom-menu-nesting))
4405 (>= custom-menu-nesting 0))
4406 (progn
4407 (custom-load-symbol symbol)
4408 (< (length (get symbol 'custom-group)) widget-menu-max-size)))
4409 (let ((custom-prefix-list (custom-prefix-add symbol
4410 custom-prefix-list))
4411 (members (custom-sort-items (get symbol 'custom-group)
4412 custom-menu-sort-alphabetically
4413 custom-menu-order-groups)))
4414 `(,(custom-unlispify-menu-entry symbol t)
4415 ,item
4416 "--"
4417 ,@(mapcar (lambda (entry)
4418 (widget-apply (if (listp (nth 1 entry))
4419 (nth 1 entry)
4420 (list (nth 1 entry)))
4421 :custom-menu (nth 0 entry)))
4422 members)))
4423 item)))
4424
4425 ;;;###autoload
4426 (defun customize-menu-create (symbol &optional name)
4427 "Return a customize menu for customization group SYMBOL.
4428 If optional NAME is given, use that as the name of the menu.
4429 Otherwise the menu will be named `Customize'.
4430 The format is suitable for use with `easy-menu-define'."
4431 (unless name
4432 (setq name "Customize"))
4433 `(,name
4434 :filter (lambda (&rest junk)
4435 (let ((menu (custom-menu-create ',symbol)))
4436 (if (consp menu) (cdr menu) menu)))))
4437
4438 ;;; Toolbar and menubar support
4439
4440 (easy-menu-define
4441 Custom-mode-menu custom-mode-map
4442 "Menu used in customization buffers."
4443 (nconc (list "Custom"
4444 (customize-menu-create 'customize))
4445 (mapcar (lambda (arg)
4446 (let ((tag (nth 0 arg))
4447 (command (nth 1 arg))
4448 (active (nth 2 arg))
4449 (help (nth 3 arg)))
4450 (vector tag command :active (eval active) :help help)))
4451 custom-commands)))
4452
4453 (defvar tool-bar-map)
4454 (defvar custom-tool-bar-map
4455 (if (display-graphic-p)
4456 (let ((map (make-sparse-keymap)))
4457 (mapc
4458 (lambda (arg)
4459 (tool-bar-local-item-from-menu
4460 (nth 1 arg) (nth 4 arg) map custom-mode-map))
4461 custom-commands)
4462 map)))
4463
4464 ;;; The Custom Mode.
4465
4466 (defun Custom-no-edit (pos &optional event)
4467 "Invoke button at POS, or refuse to allow editing of Custom buffer."
4468 (interactive "@d")
4469 (error "You can't edit this part of the Custom buffer"))
4470
4471 (defun Custom-newline (pos &optional event)
4472 "Invoke button at POS, or refuse to allow editing of Custom buffer."
4473 (interactive "@d")
4474 (let ((button (get-char-property pos 'button)))
4475 (if button
4476 (widget-apply-action button event)
4477 (error "You can't edit this part of the Custom buffer"))))
4478
4479 (defvar custom-field-keymap
4480 (let ((map (copy-keymap widget-field-keymap)))
4481 (define-key map "\C-c\C-c" 'Custom-set)
4482 (define-key map "\C-x\C-s" 'Custom-save)
4483 map)
4484 "Keymap used inside editable fields in customization buffers.")
4485
4486 (widget-put (get 'editable-field 'widget-type) :keymap custom-field-keymap)
4487
4488 (defun Custom-goto-parent ()
4489 "Go to the parent group listed at the top of this buffer.
4490 If several parents are listed, go to the first of them."
4491 (interactive)
4492 (save-excursion
4493 (goto-char (point-min))
4494 (if (search-forward "\nGo to parent group: " nil t)
4495 (let* ((button (get-char-property (point) 'button))
4496 (parent (downcase (widget-get button :tag))))
4497 (customize-group parent)))))
4498
4499 (defcustom custom-mode-hook nil
4500 "Hook called when entering Custom mode."
4501 :type 'hook
4502 :group 'custom-buffer )
4503
4504 (defun custom-state-buffer-message (widget)
4505 (if (eq (widget-get (widget-get widget :parent) :custom-state) 'modified)
4506 (message "To install your edits, invoke [State] and choose the Set operation")))
4507
4508 (defun custom-mode ()
4509 "Major mode for editing customization buffers.
4510
4511 The following commands are available:
4512
4513 \\<widget-keymap>\
4514 Move to next button, link or editable field. \\[widget-forward]
4515 Move to previous button, link or editable field. \\[advertised-widget-backward]
4516 \\<custom-field-keymap>\
4517 Complete content of editable text field. \\[widget-complete]
4518 \\<custom-mode-map>\
4519 Invoke button under the mouse pointer. \\[widget-button-click]
4520 Invoke button under point. \\[widget-button-press]
4521 Set all options from current text. \\[Custom-set]
4522 Make values in current text permanent. \\[Custom-save]
4523 Make text match actual option values. \\[Custom-reset-current]
4524 Reset options to permanent settings. \\[Custom-reset-saved]
4525 Erase customizations; set options
4526 and buffer text to the standard values. \\[Custom-reset-standard]
4527
4528 Entry to this mode calls the value of `custom-mode-hook'
4529 if that value is non-nil."
4530 (kill-all-local-variables)
4531 (setq major-mode 'custom-mode
4532 mode-name "Custom")
4533 (use-local-map custom-mode-map)
4534 (easy-menu-add Custom-mode-menu)
4535 (set (make-local-variable 'tool-bar-map) custom-tool-bar-map)
4536 (make-local-variable 'custom-options)
4537 (make-local-variable 'custom-local-buffer)
4538 (make-local-variable 'widget-documentation-face)
4539 (setq widget-documentation-face 'custom-documentation)
4540 (make-local-variable 'widget-button-face)
4541 (setq widget-button-face custom-button)
4542
4543 ;; We need this because of the "More" button on docstrings.
4544 ;; Otherwise clicking on "More" can push point offscreen, which
4545 ;; causes the window to recenter on point, which pushes the
4546 ;; newly-revealed docstring offscreen; which is annoying. -- cyd.
4547 (set (make-local-variable 'widget-button-click-moves-point) t)
4548
4549 (set (make-local-variable 'widget-button-pressed-face) custom-button-pressed)
4550 (set (make-local-variable 'widget-mouse-face) custom-button-mouse)
4551
4552 ;; When possible, use relief for buttons, not bracketing. This test
4553 ;; may not be optimal.
4554 (when custom-raised-buttons
4555 (set (make-local-variable 'widget-push-button-prefix) "")
4556 (set (make-local-variable 'widget-push-button-suffix) "")
4557 (set (make-local-variable 'widget-link-prefix) "")
4558 (set (make-local-variable 'widget-link-suffix) ""))
4559 (add-hook 'widget-edit-functions 'custom-state-buffer-message nil t)
4560 (run-mode-hooks 'custom-mode-hook))
4561
4562 (put 'custom-mode 'mode-class 'special)
4563
4564 (dolist (regexp
4565 '("^No user option defaults have been changed since Emacs "
4566 "^Invalid face:? "
4567 "^No \\(?:customized\\|rogue\\|saved\\) user options"
4568 "^No customizable items matching "
4569 "^There are unset changes"
4570 "^Cannot set hidden variable"
4571 "^No \\(?:saved\\|backup\\) value for "
4572 "^No standard setting known for "
4573 "^No standard setting for this face"
4574 "^Saving settings from \"emacs -q\" would overwrite existing customizations"))
4575 (add-to-list 'debug-ignored-errors regexp))
4576
4577 ;;; The End.
4578
4579 (provide 'cus-edit)
4580
4581 ;; arch-tag: 64533aa4-1b1a-48c3-8812-f9dc718e8a6f
4582 ;;; cus-edit.el ends here